Link to the problem
Link to ideone.com
def move(n, start, finish, temp):
global count
if n > 0:
move(n - 1, start, temp, finish)
print(n, start, finish)
count += 1
move(n - 1, temp, finish, start)
count = 0
n = int(input())
move(n, 1, 3, 2)
print(count)
In
3
Out
1 1 3
2 1 2
1 3 2
3 1 3
1 2 1
2 2 3
1 1 3
7
Link to ideone.com
def move(n, start, finish, temp):
global count
if n > 0:
move(n - 1, start, temp, finish)
print(n, start, finish)
count += 1
move(n - 1, temp, finish, start)
count = 0
n = int(input())
move(n, 1, 3, 2)
print(count)
In
3
Out
1 1 3
2 1 2
1 3 2
3 1 3
1 2 1
2 2 3
1 1 3
7
Комментариев нет:
Отправить комментарий