Consider a tower of size n. The upper disk must be moved 2 n-1 times, the second disk 2 n-2 times and so on, until the lower disk is moved only once, a total of 2 n -1 moves. Moving each drive takes exactly one revolution.
1 moved 8 times
111 moved 4 times
11111 moved 2 times
1111111 moved 1 time => 8 + 4 + 2 + 1 == 15
, x- , , , , , x . , "" "", .
1
111 1 moved 8 times
111 collapse 222 moved 4 times, taking 2 turns each
11111 -----------> 11111 moved 2 times
1111111 3333333 moved 1 time, taking 3 turns
1111111 => 8 + 4*2 + 2 + 1*3 == 21
1111111
, .
Python . , "" , disks[i] i - ,
disks = [1, 2, 1, 3]
print sum(d * 2**i for i, d in enumerate(reversed(disks)))
, , , :
disks = [1, 3, 3, 5, 7, 7, 7]
last, t, s = disks[-1], 1, 0
for d in reversed(disks):
if d < last: t, last = t*2, d
s = s + t
print s
21, .