Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 43s
Single-helper tail-recursive loop threading an accumulator:
let factorial n =
let rec go n acc =
if n <= 1 then acc
else go (n - 1) (n * acc)
in
go n 1
factorial 12 = 479_001_600
Companion to factorial.ml (10! = 3628800 via doubly-recursive
style); same answer-shape, different evaluator stress: this version
has constant stack depth.
130 baseline programs total — milestone.
11 lines
124 B
OCaml
11 lines
124 B
OCaml
let factorial n =
|
|
let rec go n acc =
|
|
if n <= 1 then acc
|
|
else go (n - 1) (n * acc)
|
|
in
|
|
go n 1
|
|
|
|
;;
|
|
|
|
factorial 12
|