-
Notifications
You must be signed in to change notification settings - Fork 0
/
hanoi.py
43 lines (32 loc) · 1.3 KB
/
hanoi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
""" Implementation of the tower-of-hanoi backup rotation pattern. """
import os
def hanoi(numDisks):
numDisks = int(numDisks)
lst = []
for day in range(1,2**numDisks):
#~ print day,
for n in range(numDisks):
# test nth bit of day number and bail if True
if day & (2**n):
lst.append(n+1)
break
return lst
def get_current_hanoi_slot(days_since_any_epoch, numDisks = 3):
hanoi_list = hanoi(numDisks)
hanoi_index = int(days_since_any_epoch) % (len(hanoi_list)-1)
#~ print "idx=",hanoi_index,
#~ print "day_id=",days_since_any_epoch,
#~ print hanoi_list,
return hanoi_list[hanoi_index]-1
def testandplay():
numDisks = 8
backups = [-1000000000000 for x in range(numDisks)]
base_backup_target_path = r'C:\temp\backup'
worst_max_age = 10000000
for day in range(60000):
slot_to_use = get_current_hanoi_slot(day, numDisks = numDisks)
backups[slot_to_use] = day
age_of_backups = [day-x for x in backups]
worst_max_age = min([worst_max_age, max(age_of_backups)])
print worst_max_age,
print "%3d %3d %17s backup age: max=%3d avg=%.1f"%(day,slot_to_use,str(age_of_backups),max(age_of_backups),sum(age_of_backups)/len(age_of_backups))