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

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:
2026-05-09 09:24:41 +00:00
parent aaaf054441
commit b0cbdaf713
3 changed files with 19 additions and 0 deletions

View File

@@ -29,6 +29,7 @@
"mutable_record.ml": 10,
"option_match.ml": 5,
"pi_leibniz.ml": 314,
"pretty_table.ml": 64,
"poly_stack.ml": 5,
"queens.ml": 2,
"quicksort.ml": 44,

View 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)])