Skip to content

Instantly share code, notes, and snippets.

@victorcamposm
Created July 23, 2020 18:16
Show Gist options
  • Select an option

  • Save victorcamposm/e896dc7ba4b0cb833063a124aa6dc6bc to your computer and use it in GitHub Desktop.

Select an option

Save victorcamposm/e896dc7ba4b0cb833063a124aa6dc6bc to your computer and use it in GitHub Desktop.
Boolean quick find
import random
start = 1
end = 100
r = random.randint(start,end+1)
print("Random number: " + str(r))
g = end/2
for i in range(1,100):
print("g = " + str(g))
if r > g: start = g
elif r < g: end = g
elif r==g: break
g = (start+end)/2
print("found! It took " + str(i) + " iterations")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment