Author Topic: Towers of Hanoi  (Read 3541 times)

0 Members and 1 Guest are viewing this topic.

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Towers of Hanoi
« on: February 12, 2007, 04:35:41 pm »
This is the simple little game that just about everyone has seen.  It consists of three pegs.  At the start of the game, one peg holds n disks in an order of decreasing size.  The object of the game is to move all of the disks from the current peg to another peg by moving each disk one at a time and never allowing a larger disk to be on top of a smaller disk.

It's a pretty simple problem if you're able to think about it correctly, otherwise it's complicated.  See if you can code something that gives you the steps to solve the puzzle for n disks.  It should print out "Move disk k from peg i to peg j." where 1<=k<=n 1<=i,j<=3.

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: Towers of Hanoi
« Reply #1 on: February 12, 2007, 06:17:04 pm »
A classic problem they use to teach, although I never had a prof who got us to do it. I guess the solution is too easy to find online.

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: Towers of Hanoi
« Reply #2 on: February 12, 2007, 06:59:56 pm »
A classic problem they use to teach, although I never had a prof who got us to do it. I guess the solution is too easy to find online.

Our professor posted gave us the solution upfront and modified the problem.  The class is pretty laid back, but they've been pretty effective in teaching some of the fundamental aspects of programming and proofs.