|
|
1.1 ! root 1: # define PRINT 0 ! 2: # define DISK 3 ! 3: # define other(i,j) (6-(i+j)) ! 4: int num[4]; ! 5: long cnt; ! 6: main(argc,argv) ! 7: char **argv; { ! 8: int disk; ! 9: disk = DISK; ! 10: if(argc > 1)disk = atoi(argv[1]); ! 11: num[1] = disk; ! 12: if(PRINT)printf("Start %d on A\n",disk); ! 13: mov(disk,1,3); ! 14: printf("For %d, %ld moves\n",disk,cnt); ! 15: } ! 16: mov(n,f,t){ ! 17: int o; ! 18: if(n == 1){ ! 19: num[f]--; ! 20: num[t]++; ! 21: if(PRINT)printf("Move from %d to %d, result: A:%d B:%d C%d\n", ! 22: f,t,num[1],num[2],num[3]); ! 23: cnt++; ! 24: return; ! 25: } ! 26: o = other(f,t); ! 27: mov(n-1,f,o); ! 28: mov(1,f,t); ! 29: mov(n-1,o,t); ! 30: return; ! 31: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.