progs/fun-tests/hanoi.fun
author Christian Urban <christian.urban@kcl.ac.uk>
Mon, 26 Oct 2020 10:24:59 +0000
changeset 790 31a9f89776a3
parent 742 b5b5583a3a08
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
706
b560f78781b9 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
// towers of hanoi in Fun
b560f78781b9 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
790
31a9f89776a3 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 742
diff changeset
     3
def hanoi(n, a, b, c) =
31a9f89776a3 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 742
diff changeset
     4
  if n != 0 then {
706
b560f78781b9 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
    hanoi (n - 1) a c b;
b560f78781b9 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
    print_endline ("Move disk from pole " ^ (show a) ^ " to pole " ^ (show b));
b560f78781b9 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
    hanoi (n - 1) c b a
790
31a9f89776a3 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 742
diff changeset
     8
  } else write("")
706
b560f78781b9 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
b560f78781b9 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
impure $ hanoi 4 1 2 3;;