tintin10

Untitled

Dec 26th, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. #The second part of what I do is this:
  2. puzzleInput = 347992
  3. lijst = [A list that is the side of square 81 where my puzzleInput resides but is too long to post]
  4. def binarySearch(alist, item):
  5.     first = 0
  6.     last = len(alist)-1
  7.     found = False
  8.     while first<=last and not found:
  9.         midpoint = (first + last)//2
  10.         if alist[midpoint] == item:
  11.             found = True
  12.         else:
  13.             if item < alist[midpoint]:
  14.                 last = midpoint-1
  15.             else:
  16.                 first = midpoint+1
  17.     return midpoint
  18. #print(binarySearch(lijst,puzzleInput))
  19. plek = binarySearch(lijst,puzzleInput)
  20. midden = (len(lijst)-1)//2
  21. if plek > puzzleInput:
  22.     stap1 = midden - puzzleInput
  23. if plek < puzzleInput:
  24.     stap1 = puzzleInput - midden
  25. antwoord = stap1 + 81
  26. print(antwoord)
Advertisement
Add Comment
Please, Sign In to add comment