Hello everyone, I have doubts on how to solve the variant 2 of tower of hanoi, I modified the code for the variant that roughly works(don’t know exactly). Can anyone show how it’s actually done?
void towerOfHanoicounter(int n, char from_rod, char to_rod, char aux_rod)
{
if (n == 1)
{
t++;
if(from_rod != 'c' and to_rod != 'c'){
printf("\n Move disk 1 from rod %c to rod %c", from_rod, aux_rod);
t++;
printf("\n Move disk 1 from rod %c to rod %c", aux_rod, to_rod);
}else{
printf("\n Move disk 1 from rod %c to rod %c", from_rod, to_rod);
}
return;
}
if(from_rod != 'c' and to_rod != 'c') {
towerOfHanoicounter(n - 1, from_rod, aux_rod, to_rod);
towerOfHanoicounter(n - 1, aux_rod, to_rod, from_rod);
printf("\n Move disk %d from rod %c to rod %c", n, from_rod, aux_rod);
towerOfHanoicounter(n - 1, to_rod, aux_rod, from_rod);
towerOfHanoicounter(n - 1, aux_rod, from_rod, to_rod);
printf("\n Move disk %d from rod %c to rod %c", n, aux_rod, to_rod);
t+=2;
towerOfHanoicounter(n - 1, from_rod, to_rod, aux_rod);
}else{
towerOfHanoicounter(n-1, from_rod, aux_rod, to_rod);
printf("\n Move disk %d from rod %c to rod %c", n, from_rod, to_rod);
t++;
towerOfHanoicounter(n-1, aux_rod, to_rod, from_rod);
}
}
Thanks in advance.