ocaml: phase 5.1 twosum.ml baseline (LeetCode #1 one-pass hashmap, index sum = 5)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s

Walks list with List.iteri, checking if target - x is already in
the hashtable; if yes, the earlier index plus current is the
answer; otherwise record the current pair.

  twosum [2;7;11;15] 9   = (0, 1)   2+7
  twosum [3;2;4]     6   = (1, 2)   2+4
  twosum [3;3]       6   = (0, 1)   3+3

Sum of i+j over each pair: 1 + 3 + 1 = 5.

Tests Hashtbl.find_opt + add (the iter-99 cleanup), List.iteri, and
tuple destructuring on let-binding (iter 98 'let (i, j) = twosum
... in').

63 baseline programs total.
This commit is contained in:
2026-05-09 13:15:05 +00:00
parent 50981a2a9b
commit 0eef5bc8e6
3 changed files with 29 additions and 0 deletions

View File

@@ -407,6 +407,17 @@ _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 — twosum.ml baseline (LeetCode #1, hashtable
one-pass, index-sum 1+3+1 = 5). Walks list with List.iteri,
checking if `target - x` is already in the hashtable; if yes, the
earlier index plus current is the answer; otherwise record the
current pair. Three test cases:
[2;7;11;15] target 9 → (0, 1)
[3;2;4] target 6 → (1, 2)
[3;3] target 6 → (0, 1)
Sum of i+j over each pair: 1+3+1 = 5. Tests Hashtbl.find_opt /
add + List.iteri + tuple destructuring on let-binding (iter 98).
63 baseline programs total.
- 2026-05-09 Phase 5.1 — bisect.ml baseline (root-finding via
bisection, sqrt(2) * 100 = 141). 50 iterations of bisection
searching for x^2 - 2 = 0 in [1, 2]. Tests higher-order function