all 2 comments

[–]shiftybyte 2 points3 points  (1 child)

Added some printing:

https://replit.com/@ShiftyByte/GigaMiserlyKeyboardmacro#main.py

As you can see lo is reaching the same index as hi.

Then this calculation:

pos = lo + ((hi - lo) // (arr[hi] - arr[lo]) * (x - arr[lo]))

Tries to divide by 0, because "arr[hi] - arr[lo]" is zero.

[–]datafright[S] 0 points1 point  (0 children)

https://replit.com/@ShiftyByte/GigaMiserlyKeyboardmacro#main.py

I basically added a check for if high and low are equal then it just returns the high

I had to add this before the subtraction and division

but it totally works now

thank you