Can someone please help me with towers of hanoi I need help doing a desk check table. Could you also explain the desk check table to me.
Help with Towers of Hanoi!
Page 1 of 16 Replies - 955 Views - Last Post: 21 August 2012 - 04:00 PM
Replies To: Help with Towers of Hanoi!
#2
Re: Help with Towers of Hanoi!
Posted 21 August 2012 - 10:38 AM
Show us what you have so far 
also, by "desk check table" do you mean "disc" check table?
also, by "desk check table" do you mean "disc" check table?
#3
Re: Help with Towers of Hanoi!
Posted 21 August 2012 - 10:39 AM
What the hell is a desk check table, and what does it have to do with Towers of Hanoi?
#4
Re: Help with Towers of Hanoi!
Posted 21 August 2012 - 10:44 AM
def main():
n = input("please enter the number of rings on the starting tower: ")
tower(n)
def tower(n, a='A', b='B', c='C'):
#move n discs from a to c using b as middle
if n == 0:
return
tower(n-1, a, c, B)/>
print a, '->', c
tower(n-1, b, a, c)
main()
that is my algorithm and an example of desk checking is http://www.scribd.co...king-Algorithms
MOD EDIT: Added code tags. When postings code...ESPECIALLY Python code...USE CODE TAGS!!!
This post has been edited by atraub: 22 August 2012 - 11:38 AM
Reason for edit:: gave code tag a tiny move
#5
Re: Help with Towers of Hanoi!
Posted 21 August 2012 - 12:10 PM
At the very top of function call, print all the variables. That seems to meet the criteria.
Note that in the algorithm you've given, no values actually change in the body of the function, so just one variable dump seems sufficient.
Note that in the algorithm you've given, no values actually change in the body of the function, so just one variable dump seems sufficient.
#6
Re: Help with Towers of Hanoi!
Posted 21 August 2012 - 12:16 PM
Ok forget the desk check i figure it out
I also changed the code what i need to do is convert it into pseudo-code if someone can help me with that.
I also changed the code what i need to do is convert it into pseudo-code if someone can help me with that.
def main():
# promt user to enter the number of rings on the starting tower
# test input to see if its a number
# if input is not a number prompt user for a number
while True:
try:
n = input("please enter the number of rings on the starting tower: ") # assigns the input to tower function
break
except KeyboardInterrupt:
break
except:
print "I said enter a number dummy!"
tower(n)
def tower(n, a='A', b='B', c='C'):
#move n discs from a to c using b as middle
if n == 0:
return
# swap values of a, b, c
tower(n-1, a, c, B)/>
print a, '->', c
tower(n-1, b, a, c)
main()
#7
Re: Help with Towers of Hanoi!
Posted 21 August 2012 - 04:00 PM
Can anyone help change that into pseudocode? or give me a heads up on what to do?
I think it goes something like this
f n is 0:
do nothing
else:
move n-1 disks from a to b using c as middle
move the last disk from a to c
move n-1 disks from b to c using a as middle
I think it goes something like this
f n is 0:
do nothing
else:
move n-1 disks from a to b using c as middle
move the last disk from a to c
move n-1 disks from b to c using a as middle
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|