I'm doing an assignment about planning for tower of Hanoi problem using linear planning and I'm not allowed to use any recursive functions. The matter is that my solution is not optimal like the one from recursive method. It produces redundant steps. For example:
I have 3 rods named A, B, C respectively and there are 2 disks named 1, 2 (disk 1 is smaller than disk 2, disk 1 is on disk 2), then there are 2 ways to move all the disks from rod A to rod C using rod B as intermediate rod as follow:
So how do I (more precise: an algorithm which can be programmable) know that disk 1 must move to rod B first instead of moving to disk C to gain optimal solution? I'll really appreciate your help. Thanks!
Initially, all the disks are placed on one rod, one over the other in ascending order of size similar to a cone-shaped tower. The objective of this problem is to move the stack of disks from the initial rod to another rod, following these rules: A disk cannot be placed on top of a smaller disk.
Given a Colored Magnetic Tower of Hanoi, the number of moves of disk k are P(k) = 3(k-1) and the total number of moves is S(N) = (3N – 1)/2.
Applications of Tower of Hanoi: It has been used to determine the extent of brain injuries and helps to build/rebuild neural pathways in the brain as attempting to solve, Tower of Hanoi uses parts of the brain that involve managing time, foresight of whether the next move will lead us closer to the solution or not.
I wanted to visualize ratchet freak answer.
Larger sizes work the same way.
{initial, spare, destination}
. Your starting move depends on reminder of 2 :
if n % 2 == 0
, start with spare rodif n % 2 == 1
, start with destination rodthe key is knowing how many disks need to be moved:
it there are a even number of disks in the stack you start to the "spare" rod
if there are an odd number of disks in the stack you start to the "destination" rod
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With