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.
11 lines
268 B
OCaml
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)])
|