Created
July 23, 2020 18:16
-
-
Save victorcamposm/e896dc7ba4b0cb833063a124aa6dc6bc to your computer and use it in GitHub Desktop.
Boolean quick find
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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