From aa617317241098f5aecbd548eb0447935fb4b789 Mon Sep 17 00:00:00 2001 From: DJ O'Leary Date: Sat, 13 Dec 2025 16:21:12 +0100 Subject: feat(2025d3): copy part 1 over to part 2 --- 2025/ocaml/lib/application/d03p02.ml | 23 +++++++++++++++++++++++ 2025/ocaml/lib/application/d03p02.mli | 4 ++++ 2 files changed, 27 insertions(+) create mode 100644 2025/ocaml/lib/application/d03p02.ml create mode 100644 2025/ocaml/lib/application/d03p02.mli (limited to '2025/ocaml/lib/application') diff --git a/2025/ocaml/lib/application/d03p02.ml b/2025/ocaml/lib/application/d03p02.ml new file mode 100644 index 0000000..743c658 --- /dev/null +++ b/2025/ocaml/lib/application/d03p02.ml @@ -0,0 +1,23 @@ +open Domain.D03p02 + +let err_empty_input = "input is empty" + +let to_lines s = + s |> String.split_on_char '\n' |> List.map String.trim + |> List.filter (fun l -> l <> "") + +let solve input () = + if input = "" then Error err_empty_input + else + let answer = + input |> to_lines |> List.to_seq + |> Seq.map BatteryBank.of_string + |> Seq.mapi (fun idx bb -> + let joltage = BatteryBank.highest_joltage bb in + Logs.debug (fun m -> + m "%d line=%s highest_joltage=%d" (idx + 1) (BatteryBank.pp bb) + joltage ) ; + joltage ) + |> Seq.fold_left ( + ) 0 + in + Ok answer diff --git a/2025/ocaml/lib/application/d03p02.mli b/2025/ocaml/lib/application/d03p02.mli new file mode 100644 index 0000000..93d3b98 --- /dev/null +++ b/2025/ocaml/lib/application/d03p02.mli @@ -0,0 +1,4 @@ +val solve : string -> unit -> (int, string) result +(** [solve input ()] is the solution for the second part of the third day of advent of code 2025 for [input]. + The solution for an empty input is [Error msg]. + Requires: [input] to be a string. *) -- cgit v1.2.3