Files
rose-ash/lib/ocaml/baseline/euler3.ml
giles 320d78a993
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 27s
ocaml: phase 5.1 euler3.ml baseline (largest prime factor of 13195 = 29)
PE3's worked example. Trial-division streaming: when the current
factor divides m, divide and update largest; otherwise bump factor:

  let largest_prime_factor n =
    let m = ref n in
    let factor = ref 2 in
    let largest = ref 0 in
    while !m > 1 do
      if !m mod !factor = 0 then begin
        largest := !factor;
        m := !m / !factor
      end else factor := !factor + 1
    done;
    !largest

  largest_prime_factor 13195 = 29  (= 5 * 7 * 13 * 29)

The full PE3 number 600851475143 exceeds JS safe-int (2^53 ≈ 9e15
in float terms; 6e11 is fine but the intermediate 'i mod !factor'
on the way to 6857 can overflow precision). 13195 keeps the program
portable across hosts.

113 baseline programs total.
2026-05-09 22:21:16 +00:00

288 B