Skip to content

Instantly share code, notes, and snippets.

@yunsu3042
Created November 15, 2016 04:52
Show Gist options
  • Save yunsu3042/19732ba6259a887e39bea0ee219c36ae to your computer and use it in GitHub Desktop.
Save yunsu3042/19732ba6259a887e39bea0ee219c36ae to your computer and use it in GitHub Desktop.
def reverse(move_list):
for x in move_list:
for i in range(len(x)):
if x[i]==2:
x[i]=3
elif x[i]==3:
x[i]=2
return move_list
def reverse2(move_list):
for x in move_list:
for i in range(len(x)):
if x[i]==1:
x[i]=2
elif x[i]==2:
x[i]=1
return move_list
def hanoi(n):
if n==2:
return [[1,2],[1,3],[2,3]]
return reverse(hanoi(n-1))+ [[1,3]] + reverse2(hanoi(n-1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment