Files
mips/_old/src/hanoi.c
T
jens 26291bca3d - initial import
git-svn-id: http://moon:8086/svn/mips@1 a8ebac50-d88d-4704-bea3-6648445a41b3
2014-07-20 15:01:37 +00:00

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);
}