10 Replies - 4935 Views - Last Post: 19 September 2010 - 03:21 PM Rate Topic: -----

#1 besweeet  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 17-February 10

Tower of Hanoi, Recursion

Posted 18 September 2010 - 04:23 PM

My assignment is to make a [really complicated] program regarding recursion and the whole Tower of Hanoi thing. I basically need to keep track of every configuration at each moment of time, describe how the configuration will change with every move, and visualize each configuration (by using a "special method". http://pastebin.com/i5GNNhtx

I have to keep track of pretty much everything: The disk numbers, where each disk is located, how many disks are located on each needle, etc.

I've seen basic Tower of Hanoi recursion problem like the ones in my textbooks, this, and this.

I'm utterly confused as to how I need to attack this thing. I've been staring at my assignment sheet for 3 days and can't think of anything. The only thing I've actually done so far is to make an input scanner to ask the user how many total disks there are.

I'm hoping that someone can sort of guide me in the direction that I need to go to at least get started with this thing, or maybe an in-depth explanation of what I'll need to do.

I've already searched the forum for other Tower of Hanoi related posts, but couldn't really find anything in particular of what I need.

Is This A Good Question/Topic? 0
  • +

Replies To: Tower of Hanoi, Recursion

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Tower of Hanoi, Recursion

Posted 18 September 2010 - 05:41 PM

Try something.

Post it.

We will help you fix it.

We won't give you code.
Was This Post Helpful? 1
  • +
  • -

#3 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10549
  • View blog
  • Posts: 39,041
  • Joined: 27-December 08

Re: Tower of Hanoi, Recursion

Posted 18 September 2010 - 05:49 PM

Elcric has a very nice Towers of Hanoi in C++ tutorial that may help you with the algorithm some.
Was This Post Helpful? 0
  • +
  • -

#4 besweeet  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 17-February 10

Re: Tower of Hanoi, Recursion

Posted 18 September 2010 - 06:34 PM

View Postn8wxs, on 18 September 2010 - 04:41 PM, said:

Try something.

Post it.

We will help you fix it.

We won't give you code.


I don't want code. I just need a little direction as how to approach this thing. I've tried thinking about done stuff and then I got lost.
Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10549
  • View blog
  • Posts: 39,041
  • Joined: 27-December 08

Re: Tower of Hanoi, Recursion

Posted 18 September 2010 - 06:40 PM

Take a look at the tutorial I posted. Also, if you look at the bottom of the page, there are a bunch of links to other Tower of Hanoi threads on DIC you may find helpful.
Was This Post Helpful? 0
  • +
  • -

#6 besweeet  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 17-February 10

Re: Tower of Hanoi, Recursion

Posted 19 September 2010 - 02:24 PM

View Postmacosxnerd101, on 18 September 2010 - 05:40 PM, said:

Take a look at the tutorial I posted. Also, if you look at the bottom of the page, there are a bunch of links to other Tower of Hanoi threads on DIC you may find helpful.


They were sort of helpful. I'm just really lost as to how I need to print out (visually) the actual pin/needle and disk configuration.

I'm really not cut out for programming... I want to program, I really do, but I think it's just too much for me :(.
Was This Post Helpful? 0
  • +
  • -

#7 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10549
  • View blog
  • Posts: 39,041
  • Joined: 27-December 08

Re: Tower of Hanoi, Recursion

Posted 19 September 2010 - 02:37 PM

See KYA's Programming FAQs. It covers drawing shapes with code. Basically, it comes down to nested for loops and use of print() and println() statements.
Was This Post Helpful? 0
  • +
  • -

#8 besweeet  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 17-February 10

Re: Tower of Hanoi, Recursion

Posted 19 September 2010 - 02:47 PM

View Postmacosxnerd101, on 19 September 2010 - 01:37 PM, said:

See KYA's Programming FAQs. It covers drawing shapes with code. Basically, it comes down to nested for loops and use of print() and println() statements.


I can print out shapes and stuff, that's no problem. My problem is with editing the contents of the shape with whatever needs to be changed. So, if there's one needle with 3 disks on it, I need to print out a new shape with less or more disks on it, which I have no idea on how to do that.
Was This Post Helpful? 0
  • +
  • -

#9 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10549
  • View blog
  • Posts: 39,041
  • Joined: 27-December 08

Re: Tower of Hanoi, Recursion

Posted 19 September 2010 - 02:58 PM

So your question really isn't how do I print out shapes, but how do I write this program. You've been given plenty of resources, and there is always Google and Wikipedia. We are happy to help you with your good faith efforts once you have some.

Hint- Aren't the disks really just Stacks (java.util.Stack)?

I also think this applies here:

Posted Image

Was This Post Helpful? 0
  • +
  • -

#10 besweeet  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 17-February 10

Re: Tower of Hanoi, Recursion

Posted 19 September 2010 - 03:17 PM

View Postmacosxnerd101, on 19 September 2010 - 01:58 PM, said:

So your question really isn't how do I print out shapes, but how do I write this program. You've been given plenty of resources, and there is always Google and Wikipedia. We are happy to help you with your good faith efforts once you have some.

Hint- Aren't the disks really just Stacks (java.util.Stack)?

I also think this applies here:

Posted Image


I've looked at a lot of resources and nothing helped. Of course I want help with how to do it. I wouldn't be here if I didn't need help. For one, I don't know how to start this thing. I've looked at a bunch of sample code, but don't know how to really translate it into what I need to do.

I give up.
Was This Post Helpful? 0
  • +
  • -

#11 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10549
  • View blog
  • Posts: 39,041
  • Joined: 27-December 08

Re: Tower of Hanoi, Recursion

Posted 19 September 2010 - 03:21 PM

Start by trying to write an algorithm or flowchart. You are welcome to post that for feedback and ask for clarification. But the point is to *try.*

Also, Wikipedia has a recursive and non-recursive algorithm, and I suggested using Stacks.

Before we proceed, do you understand the goal of the problem? If you understand how to play the game without code, that is a big step.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1