Created
November 15, 2016 04:52
-
-
Save yunsu3042/19732ba6259a887e39bea0ee219c36ae 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 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