Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 31s
Two functions:
classify n maps i to a polymorphic variant
FizzBuzz | Fizz | Buzz | Num of int
score x pattern-matches the variant to a weight
FizzBuzz=100, Fizz=10, Buzz=5, Num n=n
For i in 1..30:
FizzBuzz at 15, 30: 2 * 100 = 200
Fizz at 3,6,9,12,18,21,24,27: 8 * 10 = 80
Buzz at 5,10,20,25: 4 * 5 = 20
Num: rest (16 numbers) = 240
total = 540
Exercises polymorphic-variant match (iter 87) including a
payload-bearing 'Num n' arm.
105 baseline programs total.
22 lines
359 B
OCaml
22 lines
359 B
OCaml
let classify n =
|
|
let by3 = n mod 3 = 0 in
|
|
let by5 = n mod 5 = 0 in
|
|
if by3 && by5 then `FizzBuzz
|
|
else if by3 then `Fizz
|
|
else if by5 then `Buzz
|
|
else `Num n
|
|
|
|
let score x = match x with
|
|
| `FizzBuzz -> 100
|
|
| `Fizz -> 10
|
|
| `Buzz -> 5
|
|
| `Num n -> n
|
|
|
|
;;
|
|
|
|
let total = ref 0 in
|
|
for i = 1 to 30 do
|
|
total := !total + score (classify i)
|
|
done;
|
|
!total
|