• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Blackboard Erasing Puzzle Brute Force Solution

Geometrian Jan 14th, 2015 365 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #http://puzzling.stackexchange.com/questions/7862/ten-numbers-on-a-blackboard
2.
3. import time
4.
5.
6. def rem_comb(i,j, l):
7.     l2 = []
8.     for index in range(len(l)):
9.         if index == i or index == j: continue
10.         l2.append(l[index])
11.     a,b = l[i],l[j]
12.     l2.append(a*b + a + b)
13.     return l2
14. def experiment(l):
15.     if len(l) == 1:
16.         return l[0]
17.     else:
18.         best = (0, None,None)
19.         for i in range(len(l)):
20.             for j in range(i+1,len(l),1):
21.                 value = experiment(rem_comb(i,j, l))
22.                 if value > best[0]:
23.                     best = (value, i,j)
24.         return best[0]
25. for length in range(1,10+1,1):
26.     t0 = time.time()
27.     value = experiment(list(range(1,length+1,1)))
28.     t1 = time.time()
29.     print("Length % 2d best %d (time %f)"%(length,value,t1-t0))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top