Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 21s
Sum of even-valued Fibonacci numbers up to 4,000,000:
let euler2 limit =
let a = ref 1 in
let b = ref 2 in
let sum = ref 0 in
while !a <= limit do
if !a mod 2 = 0 then sum := !sum + !a;
let c = !a + !b in
a := !b;
b := c
done;
!sum
Sequence: 1, 2, 3, 5, 8, 13, 21, 34, ... Only every third term
(2, 8, 34, 144, ...) is even. Sum below 4M: 4613732.
101 baseline programs total.
16 lines
226 B
OCaml
16 lines
226 B
OCaml
let euler2 limit =
|
|
let a = ref 1 in
|
|
let b = ref 2 in
|
|
let sum = ref 0 in
|
|
while !a <= limit do
|
|
if !a mod 2 = 0 then sum := !sum + !a;
|
|
let c = !a + !b in
|
|
a := !b;
|
|
b := c
|
|
done;
|
|
!sum
|
|
|
|
;;
|
|
|
|
euler2 4000000
|