summaryrefslogtreecommitdiff
path: root/2025
diff options
context:
space:
mode:
Diffstat (limited to '2025')
-rw-r--r--2025/ocaml/lib/application/d06p01.ml50
-rw-r--r--2025/ocaml/lib/application/d06p01.mli4
-rw-r--r--2025/ocaml/lib/presentation/cli.ml4
3 files changed, 58 insertions, 0 deletions
diff --git a/2025/ocaml/lib/application/d06p01.ml b/2025/ocaml/lib/application/d06p01.ml
new file mode 100644
index 0000000..9425810
--- /dev/null
+++ b/2025/ocaml/lib/application/d06p01.ml
@@ -0,0 +1,50 @@
+let err_empty_input = "input is empty"
+
+let log_matrix matrix =
+ let open Domain.Matrix in
+ Logs.debug (fun m -> m "%s" (M.of_list matrix |> M.pp (fun elt -> elt)))
+
+let log_list lst =
+ Logs.debug (fun m ->
+ m "[%s]" (List.fold_left (fun acc i -> acc ^ i ^ "; ") " " lst) )
+
+type operation = Mult | Add
+
+let solve input () =
+ if input = "" then Error err_empty_input
+ else
+ let input' = Parser.columns_of_string input in
+ assert (input' <> []) ;
+ log_matrix input' ;
+ let nums =
+ List.map (List.filter (fun i -> i <> "*" && i <> "+")) input'
+ |> List.map
+ @@ List.map (fun n ->
+ Logs.debug (fun m -> m "peeking: %s" n) ;
+ int_of_string n )
+ and ops =
+ List.map (List.filter (fun i -> i = "*" || i = "+")) input'
+ |> List.concat
+ |> List.map (fun op ->
+ match op with
+ | "*" ->
+ Mult
+ | "+" ->
+ Add
+ | _ ->
+ failwith "case not covered" )
+ in
+ let answer =
+ List.map2
+ (fun op num_lst ->
+ match op with
+ | Add ->
+ List.fold_left (fun acc i -> acc + i) 0 num_lst
+ | Mult ->
+ List.fold_left (fun acc i -> acc * i) 1 num_lst )
+ ops nums
+ |> fun lst ->
+ log_list @@ List.map string_of_int lst ;
+ lst |> List.fold_left ( + ) 0
+ in
+ Ok answer
diff --git a/2025/ocaml/lib/application/d06p01.mli b/2025/ocaml/lib/application/d06p01.mli
new file mode 100644
index 0000000..b3abc1e
--- /dev/null
+++ b/2025/ocaml/lib/application/d06p01.mli
@@ -0,0 +1,4 @@
+val solve : string -> unit -> (int, string) result
+(** [solve input ()] is the solution for the first part of the sixth day of advent of code 2025 for [input].
+ The solution for an empty input is [Error msg].
+ Requires: [input] to be a string. *)
diff --git a/2025/ocaml/lib/presentation/cli.ml b/2025/ocaml/lib/presentation/cli.ml
index 7428381..4d979b0 100644
--- a/2025/ocaml/lib/presentation/cli.ml
+++ b/2025/ocaml/lib/presentation/cli.ml
@@ -32,6 +32,10 @@ let run_day _ = function
let filepath = "../_input/day_05.txt" in
run_solver "D05P01" Application.D05p01.solve filepath ;
0
+ | 6 ->
+ let filepath = "../_input/day_06.txt" in
+ run_solver "D06P01" Application.D06p01.solve filepath ;
+ 0
| _ ->
failwith "day not implemented"