Assuming that the code is just wrongly formatted and it looks like this:
    
    
    proc find_x(list: openArray[int], x: int): bool =
      var lo = list.low
      var hi = list.high
      
      while lo < hi:
        var m = int((lo + (hi - lo)) / 2)
        if x == list[m]:
          return true
        elif x < list[m]:
          hi = m - 1
        else:
          lo = m
      
      return false
    
    
    Run

You have a small error here:
    
    
    var m = int((lo + (hi - lo)) / 2)
    
    
    Run

It should be:
    
    
    var m = lo + int((hi+lo) / 2)
    
    
    Run

I would also use integer division instead of converting to int:
    
    
    var m = lo + (hi + lo) div 2
    
    
    Run

P.S. You can format code nicely on the forum if you put it in triple backticks, 
like this:
    
    
    ```Nim
    echo "Hello World!"
    ```
    
    Run

Reply via email to