ocaml: phase 5.1 fib_mod.ml baseline (Fibonacci mod prime, fib(100) mod 1000003 = 391360)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s

Iterative two-ref Fibonacci with modular reduction every step:

  let fib_mod n m =
    let a = ref 0 in
    let b = ref 1 in
    for _ = 1 to n do
      let c = (!a + !b) mod m in
      a := !b;
      b := c
    done;
    !a

The 100th Fibonacci is 354_224_848_179_261_915_075, well past JS
safe-int (2^53). Modular reduction every step keeps intermediate
values within int53 precision so the answer is exact in our
runtime. fib(100) mod 1000003 = 391360.

76 baseline programs total.
This commit is contained in:
2026-05-09 15:53:47 +00:00
parent 07de86365e
commit ce013fa138
3 changed files with 20 additions and 0 deletions

View File

@@ -407,6 +407,12 @@ _Newest first._
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
'a tree`) with insert + in-order traversal. Tests parametric ADT,
recursive match, List.append, List.fold_left.
- 2026-05-09 Phase 5.1 — fib_mod.ml baseline (Fibonacci mod prime,
fib(100) mod 1000003 = 391360). Iterative two-ref Fibonacci with
modular reduction at every step to keep intermediate values
bounded. The 100th Fibonacci is 354224848179261915075, which
exceeds JS safe-int range; modular arithmetic on each step keeps
computations within int53 precision. 76 baseline programs total.
- 2026-05-09 Phase 5.1 — luhn.ml baseline (Luhn check digit, 2/4
inputs valid). Walks digits right-to-left, doubles every other
starting from the second-from-right; if doubled value > 9