- #1
pqrs008jeff
- 3
- 0
the well known hanoi tower algorithm is as follow:
my problem is : can we handle this algorithm in this method?
we can regard three places as one place which means that three places' case is the basic case, then we can solve the problem of nine places where three places are regarded as one place, and so on, we can solve the case of 27 places then to the case of places. if we realized that when we move three places, it means that we move 7 times which time we move one place, in this way we can solve the problem with remainder.
Code:
public static void hanoi(int n,int a,int b,int c)
(
if(n>0)
(
hanoi(n-1,a,c,b);
move(a,b);
hanoi(n-1,c,b,a);
)
)
we can regard three places as one place which means that three places' case is the basic case, then we can solve the problem of nine places where three places are regarded as one place, and so on, we can solve the case of 27 places then to the case of places. if we realized that when we move three places, it means that we move 7 times which time we move one place, in this way we can solve the problem with remainder.
Last edited by a moderator: