Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I am curious as to if someone can help guide me in how to solve this or show me how to solve this. I am looking to be able to solve it with any number of variables. For example

perl hanoi.pl 4

If no variable was passed I would like for it to default to just 3. I am looking to just impress my friends. I am taking psy200. I am not sure how to begin to look at solving this. If the above was typed in at the command line I would like to see the following result.

A-B
A-C
B-C
A-B
C-A
C-B
A-B
A-C
B-C
B-A
C-A
B-C
A-B
A-C
B-C
DONE!!!!! Finished in 15 moves!!!!

This is more so illustrated at this site and also solved for 3-7. I am looking to solve for any number (or as many as possible). Any help in this would be awesome, as I am sure this will be a fun project.

Thanks,

LeGo

UPDATE: I found the solution above did work for me. It just needed the arguement passed in on command line. The answer was posted in more detail here. It would still be nice to be able to see how many moves it took...


In reply to Re: Towers of Hanoi by LeGo
in thread Towers of Hanoi by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-03-28 10:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found