fork download
  1. def rec(history, maxdepth, res):
  2. if len(history)<maxdepth:
  3. #print (history)
  4. last=history[-1]
  5. if res[last[0]] == 0 or res[last[0]] > 3+len(history):
  6. res[last[0]] = 3+len(history)
  7.  
  8. if last[3][0] != 's' and last[1] > 0:
  9. next=(last[1], last[0], 0, 's1')
  10. rec(history + [next], maxdepth, res)
  11. if last[2] > 0:
  12. next=(last[2], last[0], 0, 's2')
  13. rec(history + [next], maxdepth, res)
  14. if last[0] % 2 == 0:
  15. next=(int(last[0]/2), last[1]+int(last[0]/2), last[2]+int(last[0]/2), 'f')
  16. rec(history + [next], maxdepth, res)
  17. else:
  18. print('stopped')
  19.  
  20. maxpower = 128
  21. maxdepth = 17
  22. power = 2
  23. res = [0]*(maxpower+1)
  24. while power <= maxpower:
  25. rec([(power, 0, 0, '-')], maxdepth, res)
  26. power *= 2
  27.  
  28. print('n 2n-1 => res')
  29. for n in range(2, int(maxpower/2)+1):
  30. print (n, 2*n-1, '=>', res[2*n-1])
  31.  
Success #stdin #stdout 0.05s 9508KB
stdin
Standard input is empty
stdout
n 2n-1 => res
2 3 => 7
3 5 => 9
4 7 => 8
5 9 => 10
6 11 => 11
7 13 => 10
8 15 => 9
9 17 => 11
10 19 => 12
11 21 => 11
12 23 => 12
13 25 => 11
14 27 => 12
15 29 => 11
16 31 => 10
17 33 => 12
18 35 => 13
19 37 => 14
20 39 => 13
21 41 => 14
22 43 => 15
23 45 => 12
24 47 => 13
25 49 => 12
26 51 => 13
27 53 => 14
28 55 => 13
29 57 => 12
30 59 => 13
31 61 => 12
32 63 => 11
33 65 => 13
34 67 => 14
35 69 => 15
36 71 => 14
37 73 => 15
38 75 => 14
39 77 => 15
40 79 => 14
41 81 => 15
42 83 => 16
43 85 => 17
44 87 => 14
45 89 => 15
46 91 => 14
47 93 => 13
48 95 => 14
49 97 => 13
50 99 => 14
51 101 => 15
52 103 => 14
53 105 => 13
54 107 => 16
55 109 => 15
56 111 => 14
57 113 => 13
58 115 => 14
59 117 => 15
60 119 => 14
61 121 => 13
62 123 => 14
63 125 => 13
64 127 => 12