progs/hanoi.fun
author Christian Urban <christian.urban@kcl.ac.uk>
Sat, 04 Jul 2020 16:58:12 +0100
changeset 732 c7bdd7eac4cb
parent 706 b560f78781b9
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
b560f78781b9 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
let rec hanoi = fun n a b c ->
b560f78781b9 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
  if n != 0 then (
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
b560f78781b9 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
  ) else ();;
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;;