6 Replies - 3145 Views - Last Post: 21 August 2012 - 04:00 PM Rate Topic: -----

#1 3mpyre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 21-August 12

Help with Towers of Hanoi!

Posted 21 August 2012 - 10:29 AM

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.
Is This A Good Question/Topic? 0
  • +

Replies To: Help with Towers of Hanoi!

#2 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

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?
Was This Post Helpful? 1
  • +
  • -

#3 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7644
  • View blog
  • Posts: 12,895
  • Joined: 19-March 11

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?
Was This Post Helpful? 0
  • +
  • -

#4 3mpyre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 21-August 12

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!!!

:code:

This post has been edited by atraub: 22 August 2012 - 11:38 AM
Reason for edit:: gave code tag a tiny move

Was This Post Helpful? 0
  • +
  • -

#5 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5801
  • View blog
  • Posts: 12,637
  • Joined: 16-October 07

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.
Was This Post Helpful? 0
  • +
  • -

#6 3mpyre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 21-August 12

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.


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()


Was This Post Helpful? 0
  • +
  • -

#7 3mpyre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 21-August 12

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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1