ocaml: phase 5.1 pretty_table.ml baseline (Buffer + Printf widths, len = 64)
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
Builds a 4-row scoreboard via Buffer + Printf.sprintf: Buffer.add_string buf (Printf.sprintf '%-10s %4d\n' name score) Each row is exactly 16 chars regardless of actual name/score length: 10 name padding + 1 space + 4 score padding + 1 newline. 4 rows -> 64 chars total. Combines: - Buffer.add_string + Printf.sprintf - %-Ns left-justified string and %Nd right-justified int width - List.iter on tuple-pattern args (iter 101 fun (a, b)) 42 baseline programs total.
This commit is contained in:
@@ -29,6 +29,7 @@
|
|||||||
"mutable_record.ml": 10,
|
"mutable_record.ml": 10,
|
||||||
"option_match.ml": 5,
|
"option_match.ml": 5,
|
||||||
"pi_leibniz.ml": 314,
|
"pi_leibniz.ml": 314,
|
||||||
|
"pretty_table.ml": 64,
|
||||||
"poly_stack.ml": 5,
|
"poly_stack.ml": 5,
|
||||||
"queens.ml": 2,
|
"queens.ml": 2,
|
||||||
"quicksort.ml": 44,
|
"quicksort.ml": 44,
|
||||||
|
|||||||
10
lib/ocaml/baseline/pretty_table.ml
Normal file
10
lib/ocaml/baseline/pretty_table.ml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
let table rows =
|
||||||
|
let buf = Buffer.create 64 in
|
||||||
|
List.iter (fun (name, score) ->
|
||||||
|
Buffer.add_string buf (Printf.sprintf "%-10s %4d\n" name score)
|
||||||
|
) rows;
|
||||||
|
Buffer.contents buf
|
||||||
|
|
||||||
|
;;
|
||||||
|
|
||||||
|
String.length (table [("alice", 95); ("bob", 67); ("carol", 100); ("dave", 8)])
|
||||||
@@ -407,6 +407,14 @@ _Newest first._
|
|||||||
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
|
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
|
||||||
'a tree`) with insert + in-order traversal. Tests parametric ADT,
|
'a tree`) with insert + in-order traversal. Tests parametric ADT,
|
||||||
recursive match, List.append, List.fold_left.
|
recursive match, List.append, List.fold_left.
|
||||||
|
- 2026-05-09 Phase 5.1 — pretty_table.ml baseline (Buffer + Printf
|
||||||
|
width specifiers, total length 64). Builds a 4-row scoreboard via
|
||||||
|
Buffer + `Printf.sprintf "%-10s %4d\n"`. Each row is exactly 16
|
||||||
|
chars (10 name + 1 space + 4 score + 1 newline) regardless of
|
||||||
|
actual content length thanks to width padding. 4 rows = 64 chars.
|
||||||
|
Combines Buffer.add_string + Printf.sprintf with `%-Ns` /
|
||||||
|
`%Nd` width specifiers + List.iter on tuple-pattern args. 42
|
||||||
|
baseline programs total.
|
||||||
- 2026-05-09 Phase 4 — bitwise ops `land`/`lor`/`lxor`/`lsl`/`lsr`/
|
- 2026-05-09 Phase 4 — bitwise ops `land`/`lor`/`lxor`/`lsl`/`lsr`/
|
||||||
`asr` + bits.ml baseline (popcount-sum = 21) (+5 tests, 607 total).
|
`asr` + bits.ml baseline (popcount-sum = 21) (+5 tests, 607 total).
|
||||||
The binop precedence table already had these but eval-op fell
|
The binop precedence table already had these but eval-op fell
|
||||||
|
|||||||
Reference in New Issue
Block a user