Check out the Pastebin Gadgets Shop. We have thousands of fun, geeky & affordable gadgets on sale :-)Want more features on Pastebin? Sign Up, it's FREE!
tweet

# Untitled

By: a guest on Jul 16th, 2012  |  syntax: Python  |  size: 1.05 KB  |  views: 5  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. #For debugging purposes import time
2. import time
3.
4. #Starting point for the search
5. tosearch=[[0,0]]
6.
7. #The points that can be reached by the monkey are added into this list
8. confirmed=[]
9.
10. #Main loop that goes through the list of points to be searched
11. for point in tosearch:
12.
13.     if point not in confirmed:
14.
15.         #Count the sum of the digits
16.         digits=str(abs(point[0]))+str(abs(point[1]))
17.         sum=0
18.         for i in digits:
19.             sum+=int(i)
20.
21.         #Here it gets weird. See thread for details.
22.         if abs(sum)<=19:
23.             confirmed.append(point)
24.             tosearch.append([point[0],point[1]-1])
25.             tosearch.append([point[0]+1,point[1]])
26.             tosearch.append([point[0]-1,point[1]-1])
27.             tosearch.append([point[0],point[1]+1])
28.             tosearch.remove(point)
29.         else:
30.             tosearch.remove(point)
31.
32.         #For debugging
33.         #print (tosearch[-5:-1])
34.         #print (confirmed[-1])
35.         #time.sleep(0.2)
36.     else:
37.         tosearch.remove(point)
38.
39. print (len(confirmed))
clone this paste RAW Paste Data
Top