summaryrefslogtreecommitdiff
path: root/ocaml/lib/year2025/day03/part02/solver.ml
diff options
context:
space:
mode:
Diffstat (limited to 'ocaml/lib/year2025/day03/part02/solver.ml')
-rw-r--r--ocaml/lib/year2025/day03/part02/solver.ml23
1 files changed, 23 insertions, 0 deletions
diff --git a/ocaml/lib/year2025/day03/part02/solver.ml b/ocaml/lib/year2025/day03/part02/solver.ml
new file mode 100644
index 0000000..4a06e83
--- /dev/null
+++ b/ocaml/lib/year2025/day03/part02/solver.ml
@@ -0,0 +1,23 @@
+open Battery_bank
+
+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