From 67ece98ba1caadc4d5694ec56c71cf76e937cf82 Mon Sep 17 00:00:00 2001 From: giles Date: Mon, 11 May 2026 04:34:40 +0000 Subject: [PATCH] ocaml: phase 5.1 task_scheduler.ml baseline ("AAABBC" cooldown 2 -> 7) Task-scheduler closed-form min total intervals: m = max letter frequency k = number of letters tied at frequency m answer = max((m - 1) * (n + 1) + k, total_tasks) For "AAABBC" with cooldown n = 2: freq A = 3, freq B = 2, freq C = 1 -> m = 3, k = 1 formula = (3 - 1) * (2 + 1) + 1 = 7 total tasks = 6 answer = 7 Witness schedule: A, B, C, A, B, idle, A. Tests String.iter with side-effecting count update via Char.code arithmetic, fixed-size 26-bucket histogram. 195 baseline programs total. --- lib/ocaml/baseline/expected.json | 1 + lib/ocaml/baseline/task_scheduler.ml | 18 ++++++++++++++++++ plans/ocaml-on-sx.md | 9 +++++++++ 3 files changed, 28 insertions(+) create mode 100644 lib/ocaml/baseline/task_scheduler.ml 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