ocaml: phase 5.1 euler1.ml baseline (Project Euler #1, multiples of 3 or 5 below 1000 = 233168)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
Project Euler #1: sum of all multiples of 3 or 5 below 1000. let euler1 limit = let sum = ref 0 in for i = 1 to limit - 1 do if i mod 3 = 0 || i mod 5 = 0 then sum := !sum + i done; !sum euler1 1000 = 233168 Trivial DSL exercise but symbolically meaningful: this is the 100th baseline program. 100 baseline programs total — milestone.
This commit is contained in:
10
lib/ocaml/baseline/euler1.ml
Normal file
10
lib/ocaml/baseline/euler1.ml
Normal file
@@ -0,0 +1,10 @@
|
||||
let euler1 limit =
|
||||
let sum = ref 0 in
|
||||
for i = 1 to limit - 1 do
|
||||
if i mod 3 = 0 || i mod 5 = 0 then sum := !sum + i
|
||||
done;
|
||||
!sum
|
||||
|
||||
;;
|
||||
|
||||
euler1 1000
|
||||
@@ -24,6 +24,7 @@
|
||||
"csv.ml": 10,
|
||||
"exception_handle.ml": 4,
|
||||
"exception_user.ml": 26,
|
||||
"euler1.ml": 233168,
|
||||
"expr_eval.ml": 16,
|
||||
"expr_simp.ml": 22,
|
||||
"factorial.ml": 3628800,
|
||||
|
||||
Reference in New Issue
Block a user