From 661ce5a9f27b25cae3672087bc8d1f8eac24ea06 Mon Sep 17 00:00:00 2001 From: DJ O'Leary Date: Sun, 7 Dec 2025 17:16:09 +0100 Subject: fix(2025d4p1): flip x and y of matrix when pretty printing fixes: pp_matrix --- 2025/ocaml/lib/application/d04p01.ml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to '2025/ocaml/lib') diff --git a/2025/ocaml/lib/application/d04p01.ml b/2025/ocaml/lib/application/d04p01.ml index 1671d53..2cc5f5d 100644 --- a/2025/ocaml/lib/application/d04p01.ml +++ b/2025/ocaml/lib/application/d04p01.ml @@ -26,7 +26,13 @@ let input_to_matrix input = (** [pp_matrix matrix] is the [input] that was used to create the [matrix] via [input_to_matrix input]. *) let pp_matrix matrix = - matrix + let row_count = Array.length matrix in + let column_count = Array.length matrix.(0) in + let matrix' = Array.make_matrix row_count column_count "" in + Array.iteri + (fun x row -> Array.iteri (fun y c -> matrix'.(y).(x) <- c) row) + matrix ; + matrix' |> Array.map @@ Array.fold_left (fun acc c -> acc ^ c) "" |> Array.fold_left (fun acc line -> if acc = "" then line else acc ^ "\n" ^ line) -- cgit v1.2.3