Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#26 2007-07-15 10:56:44

mikau
Member
Registered: 2005-08-22
Posts: 1,504

Re: The Tower of Hanoi

Oh oh I get it. Yeah, we can distribute the disks to more posts. smile


A logarithm is just a misspelled algorithm.

Offline

#27 2007-07-15 11:01:27

Ricky
Moderator
Registered: 2005-12-04
Posts: 3,791

Re: The Tower of Hanoi

Since Luca already answered it partially, here is a faster solution for n pegs:

Move (k-1)/(n-2) to each of the n-2 pegs, leaving the first with only the bottom disk and the last peg empty.  Note there may be additional ones left over because of integer division.  This will cost f((k-1)/(n-2)), the same f as before.  Now move the big disk over, and stack all the others on top, each costing f((k-1)/(n-2)).  The total cost is:

2*(n-2)*f((k-1)/(n-2)) + 1

Is this the fastest way?


"In the real world, this would be a problem.  But in mathematics, we can just define a place where this problem doesn't exist.  So we'll go ahead and do that now..."

Offline

#28 2007-07-20 05:11:20

Mathskido
Member
Registered: 2007-07-20
Posts: 18

Re: The Tower of Hanoi

I've played it once, but I can't played it any more because it flashes a lot when I play it.


High score in SAT's at the end of Year 6, Virgo, D'oh!, www.freewebs.com/roadster96cat.gif
[img]C:\Documents and Settings\Alex\Desktop\Stuff\Pictures[/img]

Offline

#29 2007-07-21 17:39:41

mikau
Member
Registered: 2005-08-22
Posts: 1,504

Re: The Tower of Hanoi

oh that applet?

actually thats an EXTREMELY irritating occurance that annoys the heck out of me with java applets. Whenever you tell the screen to refresh it flickers. If it refreshes everytime you move the mouse, its just.. a nightmare.

I'm not sure if it does that with jframes though..


A logarithm is just a misspelled algorithm.

Offline

#30 2007-07-21 18:19:17

Ricky
Moderator
Registered: 2005-12-04
Posts: 3,791

Re: The Tower of Hanoi

actually thats an EXTREMELY irritating occurance that annoys the heck out of me with java applets. Whenever you tell the screen to refresh it flickers. If it refreshes everytime you move the mouse, its just.. a nightmare.

Double buffering will eliminate the flicker.


"In the real world, this would be a problem.  But in mathematics, we can just define a place where this problem doesn't exist.  So we'll go ahead and do that now..."

Offline

#31 2007-07-22 03:35:11

mikau
Member
Registered: 2005-08-22
Posts: 1,504

Re: The Tower of Hanoi

do we have access to that?


A logarithm is just a misspelled algorithm.

Offline

#32 2007-07-22 05:05:39

Ricky
Moderator
Registered: 2005-12-04
Posts: 3,791

Re: The Tower of Hanoi

Yep.  What you do is create an image, then set a graphics object to associate with that image:

Image backi;
Graphics backg;

backi = createImage(width, height);
backg = backi.getGraphics();

Now do all your drawing on backg, just as you would on the normal graphics object.  When you want to swap images, simply call:

g.drawImage(backi, 0, 0, this);

Note that "g" here is the normal graphics object you get from some method like update(Graphics g).


"In the real world, this would be a problem.  But in mathematics, we can just define a place where this problem doesn't exist.  So we'll go ahead and do that now..."

Offline

Board footer

Powered by FluxBB