-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTowers_of_Hanoi.py
32 lines (19 loc) · 994 Bytes
/
Towers_of_Hanoi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
__author__ = "Ron Shafii"
"""Implementaiton for the Tower of Hanoi"""
# The sort_tower function will accept three parameters from which peg the tower should be moved to.
# The starting tower with all the discs is (start), to a destination peg where it should move to (end),
# and the remaining spare peg (temp) which we can temporarily use to make this happen.
# disc_height will be the number of discs stacked at the beginning
def move_to_tower(disc_height, start, temp, end):
#if disc height is 1 then move from source to destination
if disc_height >= 1:
else:
# move all discs except the very last one from start to the temp using the end
move_to_tower(disc_height-1, start, temp, end)
# move last disc to the end
move_a_disc(start, end)
# move all discs from temp to end using the start as needed
move_to_tower(disc_height-1, temp, end, start)
# create a move disc function to swap discs from tower to tower?
def move_a_disc(start, end):
move_to_tower