summaryrefslogtreecommitdiff
path: root/2025/ocaml/lib/application
diff options
context:
space:
mode:
authorDJ O'Leary <dijitol@proton.me>2025-12-07 03:26:14 +0100
committerDJ O'Leary <dijitol@proton.me>2025-12-07 03:27:06 +0100
commitfe97bbe055116c559d7e6537d2605a21a74dbcbd (patch)
treecdaf943f637095c8a31ae3b59a983fbc8112afcd /2025/ocaml/lib/application
parent97a9126507b5381b7f7b87b006bd6414e3ecc9d2 (diff)
fix(2025d4p1): make points accessible as (x,y)
breaks: pp_matrix
Diffstat (limited to '2025/ocaml/lib/application')
-rw-r--r--2025/ocaml/lib/application/d04p01.ml39
1 files changed, 37 insertions, 2 deletions
diff --git a/2025/ocaml/lib/application/d04p01.ml b/2025/ocaml/lib/application/d04p01.ml
index 85b0bbf..0253340 100644
--- a/2025/ocaml/lib/application/d04p01.ml
+++ b/2025/ocaml/lib/application/d04p01.ml
@@ -18,8 +18,8 @@ let input_to_matrix input =
in
let matrix = Array.make_matrix column_count row_count "" in
List.iteri
- (fun x line ->
- String.iteri (fun y char -> matrix.(x).(y) <- Char.escaped char) line )
+ (fun y line ->
+ String.iteri (fun x char -> matrix.(x).(y) <- Char.escaped char) line )
lines ;
matrix
@@ -37,3 +37,38 @@ let solve input () =
let matrix = input |> input_to_matrix in
Logs.debug (fun m -> m "%s" @@ pp_matrix matrix) ;
0
+
+let%expect_test "direct access of the matrix is in form matrix.(x).(y)" =
+ let example =
+ {|..@@.@@@@.
+@@@.@.@.@@
+@@@@@.@.@@
+@.@@@@..@.
+@@.@@@@.@@
+.@@@@@@@.@
+.@.@.@.@@@
+@.@@@.@@@@
+.@@@@@@@@.
+@.@.@@@.@.|}
+ in
+ let matrix = input_to_matrix example in
+ print_string matrix.(0).(0) ;
+ [%expect "."] ;
+ print_string matrix.(1).(0) ;
+ [%expect "."] ;
+ print_string matrix.(2).(0) ;
+ [%expect "@"] ;
+ print_string matrix.(3).(0) ;
+ [%expect "@"] ;
+ print_string matrix.(4).(0) ;
+ [%expect "."] ;
+ print_string matrix.(5).(0) ;
+ [%expect "@"] ;
+ print_string matrix.(6).(0) ;
+ [%expect "@"] ;
+ print_string matrix.(7).(0) ;
+ [%expect "@"] ;
+ print_string matrix.(8).(0) ;
+ [%expect "@"] ;
+ print_string matrix.(9).(0) ;
+ [%expect "."]