Files
rose-ash/lib/ocaml/baseline/pretty_table.ml
giles b0cbdaf713
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
ocaml: phase 5.1 pretty_table.ml baseline (Buffer + Printf widths, len = 64)
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.
2026-05-09 09:24:41 +00:00

11 lines
268 B
OCaml

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