solution/cw5/hanoi.fun
author Christian Urban <christian.urban@kcl.ac.uk>
Wed, 15 Dec 2021 19:00:01 +0000
changeset 864 b5b1bc0a603b
child 867 54bcd848d716
permissions -rw-r--r--
added

// Towers of Hanoi in Fun

def hanoi(n: Int, a: Int, b: Int, c: Int) : Void =
  if n != 0 then {
    hanoi(n - 1, a, c, b);
    print_int(a);
    print_char('-'); print_char('>'); // prints out "->"
    print_int(b);
    print_char('\n');
    hanoi(n - 1, c, b, a)
  } else skip;

hanoi(4,1,2,3)