diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index 7c10507e..85242cde 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -173,6 +173,7 @@ "stock_two.ml": 6, "subseq_check.ml": 3, "tail_factorial.ml": 479001600, + "task_scheduler.ml": 7, "tarjan_scc.ml": 4, "subset_sum.ml": 8, "tic_tac_toe.ml": 1, diff --git a/lib/ocaml/baseline/task_scheduler.ml b/lib/ocaml/baseline/task_scheduler.ml new file mode 100644 index 00000000..62063c91 --- /dev/null +++ b/lib/ocaml/baseline/task_scheduler.ml @@ -0,0 +1,18 @@ +let task_intervals tasks n = + let counts = Array.make 26 0 in + String.iter (fun c -> counts.(Char.code c - Char.code 'A') <- counts.(Char.code c - Char.code 'A') + 1) tasks; + let max_c = ref 0 in + for i = 0 to 25 do + if counts.(i) > !max_c then max_c := counts.(i) + done; + let max_n = ref 0 in + for i = 0 to 25 do + if counts.(i) = !max_c then max_n := !max_n + 1 + done; + let intervals = (!max_c - 1) * (n + 1) + !max_n in + let total = String.length tasks in + if intervals > total then intervals else total + +;; + +task_intervals "AAABBC" 2 diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index d1603223..5135c066 100644 --- a/plans/ocaml-on-sx.md +++ b/plans/ocaml-on-sx.md @@ -407,6 +407,15 @@ _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-11 Phase 5.1 — task_scheduler.ml baseline (task cooldown + formula, "AAABBC" with n=2 → 7 intervals). Counts each letter, + finds max frequency `m` and the number of letters that hit that + max `k`. Formula: `(m-1)·(n+1) + k`, taking the larger of that + and the total task count when interleaving fills the schedule. + Witness: A,B,C,A,B,idle,A satisfies cooldown 2 between A→A and + B→B. Tests String.iter with side-effecting closure (count + histogram update via Char.code arithmetic). 195 baseline + programs total. - 2026-05-11 Phase 5.1 — min_subarr_target.ml baseline (sliding- window min subarray with sum ≥ target on [2;3;1;2;4;3] target=7 = 2). Two-pointer: expand right, then shrink left while sum