ocaml: phase 5.1 hanoi.ml baseline (Tower of Hanoi move count, n=10 -> 1023)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 26s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 26s
Classic doubly-recursive solution returning the move count:
hanoi n from to via =
if n = 0 then 0
else hanoi (n-1) from via to + 1 + hanoi (n-1) via to from
For n = 10, returns 2^10 - 1 = 1023.
Exercises 4-arg recursion, conditional base case, and tail-position
addition. Uses 'to_' instead of 'to' for the destination param to
avoid collision with the 'to' keyword in for-loops — the OCaml
conventional workaround.
37 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 — hanoi.ml baseline (Tower of Hanoi move
|
||||
count, n=10 → 1023). Classic doubly-recursive solution returning
|
||||
the number of moves: `hanoi n from to via = hanoi (n-1) from via
|
||||
to + 1 + hanoi (n-1) via to from`. Counts to 2^10 - 1 = 1023 for
|
||||
n=10, exercising tail-position addition + 4-arg recursion +
|
||||
conditional base case. (Uses `to_` instead of `to` to avoid
|
||||
collision with the `to` keyword in for-loops — OCaml conventional
|
||||
workaround.) 37 baseline programs total.
|
||||
- 2026-05-09 Phase 5.1 — validate.ml baseline (Either-based input
|
||||
validation, 3 errors × 100 + 117 sum = 417). validate_int returns
|
||||
`Left msg` on empty / non-digit, `Right (int_of_string s)` on a
|
||||
|
||||
Reference in New Issue
Block a user