0
votes

Consider the original tower of Hanoi problem with one extra condition :

  • If you have 3 pole A , B and C you are not allowed to move a disc directly from A to B or B to A

that means from the famous recursive solution we are not allowed to move start to temp or temp to start.

void hanoi(int n, char start, char temp, char finish){
    if (n== 1)
        cout << start << " -> " << finish;
    else {
        hanoi(n - 1, start, finish, temp);
        cout << start << " -> " << finish;
        hanoi(n - 1, temp, start, finish);
    }
}

Can anyone help me to find a solution for this ?

1
What makes you think there is a solution?Scott Hunter
you mean there is not ?Mehdi
I don't know; you seem to think there is, so I wondered what the basis for that was.Scott Hunter
Of course there is a solution for this. I am sure you can find one just by Googling it.user3437460

1 Answers

0
votes

Instead of moving from A to B directly, just perform an intermediary move A->C->B. If the implementation is correct, it should be always possible to do that.