Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 40s
Iterative Collatz / hailstone sequence:
let collatz_length n =
let m = ref n in
let count = ref 0 in
while !m > 1 do
if !m mod 2 = 0 then m := !m / 2
else m := 3 * !m + 1;
count := !count + 1
done;
!count
27 is the famous 'long-running' Collatz starter. Reaches a peak of
9232 mid-sequence and takes 111 steps to bottom out at 1.
64 baseline programs total.
14 lines
210 B
OCaml
14 lines
210 B
OCaml
let collatz_length n =
|
|
let m = ref n in
|
|
let count = ref 0 in
|
|
while !m > 1 do
|
|
if !m mod 2 = 0 then m := !m / 2
|
|
else m := 3 * !m + 1;
|
|
count := !count + 1
|
|
done;
|
|
!count
|
|
|
|
;;
|
|
|
|
collatz_length 27
|