http://www.perlmonks.org?node_id=99176


in reply to Towers of Hanoi

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