864
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1 |
// Towers of Hanoi in Fun
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
2 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
3 |
def hanoi(n: Int, a: Int, b: Int, c: Int) : Void =
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
4 |
if n != 0 then {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
5 |
hanoi(n - 1, a, c, b);
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
6 |
print_int(a);
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
7 |
print_char('-'); print_char('>'); // prints out "->"
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
8 |
print_int(b);
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
9 |
print_char('\n');
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
10 |
hanoi(n - 1, c, b, a)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
11 |
} else skip;
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
12 |
|
867
|
13 |
hanoi(4,1,2,3)
|