ocaml: phase 5.1 anagram_groups.ml baseline (group by canonical anagram, 3 groups)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
canonical builds a sorted-by-frequency string representation:
let canonical s =
let chars = Array.make 26 0 in
for i = 0 to String.length s - 1 do
let k = Char.code s.[i] - Char.code 'a' in
if k >= 0 && k < 26 then chars.(k) <- chars.(k) + 1
done;
expand into a-z order via a Buffer
For 'eat', 'tea', 'ate' -> all canonicalise to 'aet'. For 'tan',
'nat' -> 'ant'. For 'bat' -> 'abt'.
group_anagrams folds the input, accumulating per-key string lists;
final answer is Hashtbl.length (number of distinct groups):
['eat'; 'tea'; 'tan'; 'ate'; 'nat'; 'bat'] -> 3 groups
99 baseline programs total.
This commit is contained in:
@@ -407,6 +407,14 @@ _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 — anagram_groups.ml baseline (group strings
|
||||
by canonical anagram form, ["eat";"tea";"tan";"ate";"nat";"bat"]
|
||||
has 3 groups). canonical builds a sorted-by-frequency string
|
||||
representation: count letters, then expand into a-z order. Used
|
||||
as Hashtbl key. group_anagrams folds the input list, accumulating
|
||||
per-key string lists; final answer is Hashtbl.length (number of
|
||||
distinct groups). Tests count-then-expand canonical pattern +
|
||||
Hashtbl as multimap. 99 baseline programs total.
|
||||
- 2026-05-09 Phase 5.1 — monotonic.ml baseline (monotonicity check,
|
||||
4/5 inputs monotonic). Tracks two bool refs (inc, dec). Each pair
|
||||
of consecutive elements: if `h < prev` clear `inc`, if `h > prev`
|
||||
|
||||
Reference in New Issue
Block a user