From da54c3ea53954ee7e9ed4d03c9d62615bad3cb57 Mon Sep 17 00:00:00 2001 From: giles Date: Sun, 10 May 2026 02:26:10 +0000 Subject: [PATCH] ocaml: phase 5.1 bowling.ml baseline (10-pin bowling score, sample game = 167) Walks the pin-knockdown list applying strike/spare bonuses through a 10-frame counter: strike (10): score 10 + next 2 throws, advance i+1 spare (a + b = 10): score 10 + next 1 throw, advance i+2 open (a + b < 10): score a + b, advance i+2 Frame ten special-cases are handled implicitly: the input includes bonus throws naturally and the while-loop terminates after frame 10. bowling_score [10; 7; 3; 9; 0; 10; 0; 8; 8; 2; 0; 6; 10; 10; 10; 8; 1] = 20+19+9+18+8+10+6+30+28+19 = 167 131 baseline programs total. --- lib/ocaml/baseline/bowling.ml | 24 ++++++++++++++++++++++++ lib/ocaml/baseline/expected.json | 1 + plans/ocaml-on-sx.md | 7 +++++++ 3 files changed, 32 insertions(+) create mode 100644 lib/ocaml/baseline/bowling.ml diff --git a/lib/ocaml/baseline/bowling.ml b/lib/ocaml/baseline/bowling.ml new file mode 100644 index 00000000..32cf71d0 --- /dev/null +++ b/lib/ocaml/baseline/bowling.ml @@ -0,0 +1,24 @@ +let bowling_score frames = + let arr = Array.of_list frames in + let n = Array.length arr in + let total = ref 0 in + let i = ref 0 in + let frame = ref 1 in + while !frame <= 10 && !i < n do + if arr.(!i) = 10 then begin + total := !total + 10 + arr.(!i + 1) + arr.(!i + 2); + i := !i + 1 + end else if !i + 1 < n && arr.(!i) + arr.(!i + 1) = 10 then begin + total := !total + 10 + arr.(!i + 2); + i := !i + 2 + end else begin + total := !total + arr.(!i) + arr.(!i + 1); + i := !i + 2 + end; + frame := !frame + 1 + done; + !total + +;; + +bowling_score [10; 7; 3; 9; 0; 10; 0; 8; 8; 2; 0; 6; 10; 10; 10; 8; 1] diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index 3d81952e..afa8c67f 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -7,6 +7,7 @@ "anagrams.ml": 3, "atm.ml": 120, "bag.ml": 3, + "bowling.ml": 167, "bf_full.ml": 6, "bisect.ml": 141, "bigint_add.ml": 28, diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index 969de697..13ad9d44 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-10 Phase 5.1 — bowling.ml baseline (10-pin bowling score + for canonical "167" PBA-style game). Walks pin-knockdown list + applying strike/spare bonuses through a 10-frame counter. Strike + consumes 1 throw + 2 bonus; spare consumes 2 throws + 1 bonus; + open frame is just the two pin counts. Frame ten special-cases + ignored (input includes the bonus throws naturally). 131 baseline + programs total. - 2026-05-10 Phase 5.1 — tail_factorial.ml baseline (12! via tail recursion = 479001600). Single-helper tail-recursive loop threading an accumulator. Companion to factorial.ml (10! via