progs/fun/fact.fun
author Christian Urban <christian.urban@kcl.ac.uk>
Mon, 24 Jan 2022 00:00:33 +0000
changeset 869 81ee93b87258
parent 814 1fbaa5f05516
permissions -rw-r--r--
changed os-lib as a replacement for ammonite-ops

def fact(n) =
  (if n == 0 then 1 else n * fact(n - 1));

def facT(n, acc) =
  if n == 0 then acc else facT(n - 1, n * acc);

def facTi(n) = facT(n, 1);

//fact(10)
//facTi(10)

write(fact(6)); facTi(6)

// a simple factorial program
// (including a tail recursive version)