progs/hanoi.fun
author Christian Urban <urbanc@in.tum.de>
Tue, 28 Jan 2020 12:23:53 +0000
changeset 709 c112a6cb5e52
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;;