Skip to content

Instantly share code, notes, and snippets.

@sysint64
Created December 1, 2016 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sysint64/0570e5ded9c136f806ea530fa7984461 to your computer and use it in GitHub Desktop.
Save sysint64/0570e5ded9c136f806ea530fa7984461 to your computer and use it in GitHub Desktop.
def restore_disks(size, action_index, action_count, from_axis, to_axis):
pivot = action_count // 2
free_axis = _select_axis(from_axis, to_axis)
part_count = action_count - pivot - 1
if action_index == pivot:
axises[from_axis].append(size)
for i in range(size-1, 0, -1):
axises[free_axis].append(i)
elif action_index < pivot:
axises[from_axis].append(size)
restore_disks(size-1, action_index, part_count, from_axis, free_axis)
else:
action_index -= pivot + 1
axises[to_axis].append(size)
restore_disks(size-1, action_index, part_count, free_axis, to_axis)
def restore_towers(index):
global axises
rings_count = 6
axises = [[], [], []]
restore_disks(rings_count, index, 2 ** 6 - 1, 0, 2)
print(axises)
for i in range(0, 2 ** 6 - 1):
restore_towers(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment