fork download
  1. TARGET = 77
  2. results = {}
  3. def gameResult( x, y ):
  4. if (x,y) in results: return results[x,y]
  5. if x + y >= TARGET: return 0
  6. nextCodes = [ gameResult( x+1, y ), gameResult( x*2, y ),
  7. gameResult( x, y+1 ), gameResult( x, y*2 ) ]
  8. negative = [c for c in nextCodes if c <= 0]
  9. if negative:
  10. res = -max(negative) + 1
  11. else:
  12. res = -max(nextCodes)
  13. results[x,y] = res
  14. return res
  15.  
  16. X = 7
  17. for S in range(TARGET-X-1,0,-1):
  18. r = gameResult( X, S )
  19. print( "{:d} {:d}".format(S, r) )
  20. # your code goes here
Success #stdin #stdout 0.02s 9412KB
stdin
Standard input is empty
stdout
69 1
68 1
67 1
66 1
65 1
64 1
63 1
62 1
61 1
60 1
59 1
58 1
57 1
56 1
55 1
54 1
53 1
52 1
51 1
50 1
49 1
48 1
47 1
46 1
45 1
44 1
43 1
42 1
41 1
40 1
39 1
38 1
37 1
36 1
35 1
34 2
33 -2
32 3
31 2
30 -2
29 3
28 4
27 -4
26 5
25 6
24 -6
23 7
22 8
21 -8
20 9
19 10
18 -10
17 11
16 4
15 3
14 -4
13 5
12 7
11 -8
10 6
9 11
8 -11
7 5
6 -7
5 8
4 12
3 8
2 9
1 14