Skip to content

Instantly share code, notes, and snippets.

@sysint64
Last active December 1, 2016 16:21
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/1127a2fa10afb6eda8280b0a398e9902 to your computer and use it in GitHub Desktop.
Save sysint64/1127a2fa10afb6eda8280b0a398e9902 to your computer and use it in GitHub Desktop.
current_tower = 0
target_axis = 2
axises = [
[6, 5, 4, 3, 2, 1],
[],
[]
]
def _select_axis(tower_index, axis):
axises_indexes = [0, 1, 2]
axises_indexes.remove(tower_index)
axises_indexes.remove(axis)
return axises_indexes[0]
def move_tower(tower_index, axis, offset=0):
tower = axises[tower_index]
if len(tower[offset:]) == 1:
axises[axis].append(tower.pop())
print(axises)
return
free_axis = _select_axis(tower_index, axis)
free_offset = len(axises[free_axis])
move_tower(tower_index, free_axis, offset+1)
move_tower(tower_index, axis, offset)
move_tower(free_axis, axis, free_offset)
move_tower(current_tower, target_axis)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment