progs/fun-tests/hanoi.fun
author Christian Urban <christian.urban@kcl.ac.uk>
Thu, 15 Oct 2020 09:22:33 +0100
changeset 781 bae72c598afd
parent 742 b5b5583a3a08
child 790 31a9f89776a3
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;;