ocaml: phase 5.1 fizzbuzz.ml baseline (12/12 pass)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 32s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 32s
Classic fizzbuzz using ref-cell accumulator, for-loop, mod, if/elseif chain, String.concat, Int.to_string. Output verified via String.length of the comma-joined result for n=15: 57.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
"exception_handle.ml": 4,
|
||||
"expr_eval.ml": 16,
|
||||
"factorial.ml": 3628800,
|
||||
"fizzbuzz.ml": 57,
|
||||
"list_ops.ml": 30,
|
||||
"module_use.ml": 3,
|
||||
"option_match.ml": 5,
|
||||
|
||||
17
lib/ocaml/baseline/fizzbuzz.ml
Normal file
17
lib/ocaml/baseline/fizzbuzz.ml
Normal file
@@ -0,0 +1,17 @@
|
||||
(* Baseline: fizzbuzz returning a list of strings *)
|
||||
let fizzbuzz n =
|
||||
let acc = ref [] in
|
||||
for i = 1 to n do
|
||||
let s =
|
||||
if i mod 15 = 0 then "FizzBuzz"
|
||||
else if i mod 3 = 0 then "Fizz"
|
||||
else if i mod 5 = 0 then "Buzz"
|
||||
else Int.to_string i
|
||||
in
|
||||
acc := s :: !acc
|
||||
done ;
|
||||
List.rev !acc
|
||||
;;
|
||||
|
||||
(* Concatenated for a deterministic check value via String.length *)
|
||||
String.length (String.concat "," (fizzbuzz 15))
|
||||
Reference in New Issue
Block a user