ocaml: phase 5.1 task_scheduler.ml baseline ("AAABBC" cooldown 2 -> 7)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s
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.
This commit is contained in:
@@ -173,6 +173,7 @@
|
|||||||
"stock_two.ml": 6,
|
"stock_two.ml": 6,
|
||||||
"subseq_check.ml": 3,
|
"subseq_check.ml": 3,
|
||||||
"tail_factorial.ml": 479001600,
|
"tail_factorial.ml": 479001600,
|
||||||
|
"task_scheduler.ml": 7,
|
||||||
"tarjan_scc.ml": 4,
|
"tarjan_scc.ml": 4,
|
||||||
"subset_sum.ml": 8,
|
"subset_sum.ml": 8,
|
||||||
"tic_tac_toe.ml": 1,
|
"tic_tac_toe.ml": 1,
|
||||||
|
|||||||
18
lib/ocaml/baseline/task_scheduler.ml
Normal file
18
lib/ocaml/baseline/task_scheduler.ml
Normal file
@@ -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
|
||||||
@@ -407,6 +407,15 @@ _Newest first._
|
|||||||
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
|
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
|
||||||
'a tree`) with insert + in-order traversal. Tests parametric ADT,
|
'a tree`) with insert + in-order traversal. Tests parametric ADT,
|
||||||
recursive match, List.append, List.fold_left.
|
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-
|
- 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
|
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
|
= 2). Two-pointer: expand right, then shrink left while sum
|
||||||
|
|||||||
Reference in New Issue
Block a user