![]() ![]() Print ''.format(N,Hanoi3,Hanoi4,a)Īs you can see, N/2 does not calculate the best a. Here's a simple program to figure out and print the best costs in python: Hanoi3= If nil, move rings as fast as possible while displaying all: intermediate positions. For each N, then, the resulting formula would be 2*Hanoi4(a) + Hanoi3(N-a), where a is the number of small pegs we move off first. (defgroup hanoi nil 'The Towers of Hanoi.':group games) (defcustom hanoi-horizontal-flag nil 'Non-nil means that hanoi poles are oriented horizontally.':type boolean) (defcustom hanoi-move-period 1 'Time, in seconds, for each pole-to-pole move of a ring. I think you are correct that for every N, the best strategy will be to move some small disks onto a spare peg with Hanoi4, move the remaining large ones onto the target with Hanoi3, and then move the small ones ones to the target with Hanoi4. Let Hanoi4(N) be the number of movesit takes to move N disks with 4 pegs, and let Hanoi3(N) be the number of moves it takes to move N disks with 3 pegs. Is there any way way I could split the n to get a better run time? This gets the most efficient run time if the disc is 1 to 8, but after 9 theres apparently a better way. Now simply putting the original n//2 to the destination - The algorithm of a tower of Hanoi is actually quite simple and consists only of 3 steps which are repeated until the puzzle is solved. Now using the 3 stools that are left, I want to use the n - 1 approach (normal tower of hanoi) to get the remainder to the destination (I realized I put the n//2 in spare1 instead of spare2 but same thing overall). ![]() I want to move n // 2 disc to one of the two spare stools. If we have 5 disc it would look like this. Should obviously be faster than normal tower of hanoi three solutions to this, and the last one is the most efficient. Lets say I have to find the most efficient way for a recursive tower of hanoi function except with 4 pegs. Towers of Hanoi, a math game, is often used as a common recursion and optimization. It turns out that the most efficient solution to the Towers of Hanoi problem with ndisks takes 2n 1 moves. ![]()
0 Comments
Leave a Reply. |