3 * File name: test/Hanoi.c
4 * Purpose: Towers of hanoi
5 * Author: Arne Frick (in Sather-k)
6 * Modified by: Michael Beck (for C)
9 * Copyright: (c) 2001 Universitaet Karlsruhe
23 static boolean verbose = false;
26 //-- initializes an array of pegs
33 void hanoi(int n, int from, int to) {
34 int spare = 3 - from - to;
36 //-- moves the stack of pegs from stick[from] via stick[temp]
39 hanoi (n-1, from, spare);
41 stick[from] = stick[from] - 1;
42 stick[to] = stick[to] + 1;
44 printf("move %d to %d\n", from, to);
46 hanoi (n-1, spare, to);
50 //--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
52 int main(int argc, char *argv[]) {
54 boolean n_specified = false;
59 if args.asize > i and args[i].equals ("-v") {
68 if i /= args.asize - 1 {
69 << " wrong # of arguments\n\n"
70 "Usage: hanoi [-v] n\n"
71 " where n is the number of pegs\n"
72 " -v enables verbose printing of moves\n";
74 printf("Usage: hanoi n\nWhere n is the number of pegs.\nContinuing with default: n = 21 (-> 2097151)\n");
83 //<< "Total #moves: " << p.moves << "\n";
84 // hanoi(28) = 268435455
85 printf(" number of moves : %d\n", moves);