ocaml: phase 5.1 tail_factorial.ml baseline (12! via tail-recursion = 479001600)
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.
This commit is contained in:
2026-05-10 02:05:09 +00:00
parent e77a2d3a81
commit 63901931c4
3 changed files with 17 additions and 0 deletions

View File

@@ -114,6 +114,7 @@
"simpson_int.ml": 10000,
"stable_unique.ml": 46,
"subseq_check.ml": 3,
"tail_factorial.ml": 479001600,
"subset_sum.ml": 8,
"tic_tac_toe.ml": 1,
"word_freq.ml": 8,

View File

@@ -0,0 +1,10 @@
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