31 lines
476 B
C
31 lines
476 B
C
/* tower of hanoi */
|
|
|
|
int num[4];
|
|
|
|
mov( int n, int from, int to)
|
|
{
|
|
int other;
|
|
if( n == 1) {
|
|
num[from] = num[from] - 1;
|
|
num[to] = num[to] + 1;
|
|
printf("%d -> %d\n",from,to);
|
|
} else {
|
|
other = 6 - from - to;
|
|
mov(n-1, from, other);
|
|
mov(1, from, to );
|
|
mov(n-1, other, to);
|
|
}
|
|
}
|
|
|
|
main() {
|
|
int disk;
|
|
printf("%f\n", 1.375f);
|
|
|
|
disk = 3;
|
|
num[0] = 0;
|
|
num[1] = disk;
|
|
num[2] = 0;
|
|
num[3] = 0;
|
|
mov(disk,1,3);
|
|
}
|