ocaml: phase 5.1 reverse_int.ml baseline (digit-reverse sum = 54329)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
Walks digits via mod 10 / div 10, accumulating the reversed value:
let reverse_int n =
let m = ref n in
let r = ref 0 in
while !m > 0 do
r := !r * 10 + !m mod 10;
m := !m / 10
done;
!r
reverse 12345 + reverse 100 + reverse 7
= 54321 + 1 + 7
= 54329
Trailing zeros collapse (reverse 100 = 1, not 001).
132 baseline programs total.
This commit is contained in:
@@ -107,6 +107,7 @@
|
||||
"queens.ml": 2,
|
||||
"quicksort.ml": 44,
|
||||
"roman.ml": 44,
|
||||
"reverse_int.ml": 54329,
|
||||
"rpn.ml": 9,
|
||||
"run_decode.ml": 21,
|
||||
"run_length.ml": 11,
|
||||
|
||||
12
lib/ocaml/baseline/reverse_int.ml
Normal file
12
lib/ocaml/baseline/reverse_int.ml
Normal file
@@ -0,0 +1,12 @@
|
||||
let reverse_int n =
|
||||
let m = ref n in
|
||||
let r = ref 0 in
|
||||
while !m > 0 do
|
||||
r := !r * 10 + !m mod 10;
|
||||
m := !m / 10
|
||||
done;
|
||||
!r
|
||||
|
||||
;;
|
||||
|
||||
reverse_int 12345 + reverse_int 100 + reverse_int 7
|
||||
@@ -407,6 +407,11 @@ _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-10 Phase 5.1 — reverse_int.ml baseline (digit-reverse,
|
||||
reverse(12345) + reverse(100) + reverse(7) = 54321 + 1 + 7 =
|
||||
54329). Walks digits via mod 10 / div 10, accumulating the
|
||||
reversed value. Trailing zeros collapse (reverse 100 = 1).
|
||||
132 baseline programs total.
|
||||
- 2026-05-10 Phase 5.1 — bowling.ml baseline (10-pin bowling score
|
||||
for canonical "167" PBA-style game). Walks pin-knockdown list
|
||||
applying strike/spare bonuses through a 10-frame counter. Strike
|
||||
|
||||
Reference in New Issue
Block a user