ocaml: phase 5.1 balance.ml baseline (paren/bracket/brace balance via Stack)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 51s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 51s
is_balanced walks a string; on each char:
'(', '[', '{' -> Stack.push c
')', ']', '}' -> require stack non-empty AND top = expected opener,
else mark ok = false
others -> skip
At end: !ok && Stack.is_empty stack.
Five test cases:
'({[abc]d}e)' -> true
'(a]' -> false (no matching opener)
'{[}]' -> false (mismatched closer)
'(())' -> true
'' -> true
Sum of (if balanced then 1 else 0) -> 3.
Exercises:
Stack.create / push / pop / is_empty
s.[!i] string indexing
while loop + bool ref short-circuit
multi-arm if/else if/else if dispatch
31 baseline programs total.
This commit is contained in:
@@ -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-09 Phase 5.1 — balance.ml baseline (paren/bracket/brace
|
||||
balance using Stack). is_balanced walks a string; on opener push,
|
||||
on closer check stack non-empty + top matches expected opener (else
|
||||
fail). Returns ok && is_empty stack at end. 5 test cases:
|
||||
"({[abc]d}e)" ✓, "(a]" ✗, "{[}]" ✗ (mismatched closers), "(())" ✓,
|
||||
"" ✓ → 3 balanced. Exercises Stack.create / push / pop / is_empty /
|
||||
s.[!i] / while + bool ref short-circuit. 31 baseline programs total.
|
||||
- 2026-05-09 Phase 5.1 — safe_div.ml baseline + Result.equal /
|
||||
compare / iter_error (+3 tests, 592 total). safe_div divides only
|
||||
if divisor non-zero, returns `Error "..."` otherwise. sum_safe folds
|
||||
|
||||
Reference in New Issue
Block a user