Created
December 1, 2016 17:54
-
-
Save sysint64/0570e5ded9c136f806ea530fa7984461 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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