diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index f5d9c7f7..48ce7dd1 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -45,6 +45,7 @@ "hanoi.ml": 1023, "hist.ml": 75, "int_sqrt.ml": 1027, + "fizz_classifier.ml": 540, "fizzbuzz.ml": 57, "flatten_tree.ml": 28, "list_ops.ml": 30, diff --git a/lib/ocaml/baseline/fizz_classifier.ml b/lib/ocaml/baseline/fizz_classifier.ml new file mode 100644 index 00000000..95d08f55 --- /dev/null +++ b/lib/ocaml/baseline/fizz_classifier.ml @@ -0,0 +1,21 @@ +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 diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index 42f866d5..410a534f 100644 --- a/plans/ocaml-on-sx.md +++ b/plans/ocaml-on-sx.md @@ -407,6 +407,13 @@ _Newest first._ binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree * 'a tree`) with insert + in-order traversal. Tests parametric ADT, recursive match, List.append, List.fold_left. +- 2026-05-09 Phase 5.1 — fizz_classifier.ml baseline (FizzBuzz with + polymorphic variants, 1..30 weighted score = 540). Two functions: + classify maps i → ` `FizzBuzz | `Fizz | `Buzz | `Num n``, and score + pattern-matches the variant to a weight (100/10/5/value). For + i=1..30: 200 + 80 + 20 + 240 = 540. Exercises polyvariant + match (iter 87) including a payload-bearing `` `Num n``. 105 + baseline programs total. - 2026-05-09 Phase 5.1 — max_product3.ml baseline (max product of three from a list including negatives = 300). Sort, then compare product of three largest vs product of two smallest negatives and