summaryrefslogtreecommitdiff
path: root/2025/ocaml/lib/application/d01p02.ml
diff options
context:
space:
mode:
Diffstat (limited to '2025/ocaml/lib/application/d01p02.ml')
-rw-r--r--2025/ocaml/lib/application/d01p02.ml14
1 files changed, 9 insertions, 5 deletions
diff --git a/2025/ocaml/lib/application/d01p02.ml b/2025/ocaml/lib/application/d01p02.ml
index 6f935a4..7910486 100644
--- a/2025/ocaml/lib/application/d01p02.ml
+++ b/2025/ocaml/lib/application/d01p02.ml
@@ -1,5 +1,7 @@
open Domain.D01p02
+let err_empty_input = "input is empty"
+
let rec input_to_lines input =
let lines =
String.split_on_char '\n' input |> List.filter (fun l -> l <> "")
@@ -44,8 +46,10 @@ let rec turn_aux count dial = function
let turn current = turn_aux 0 current
let solve input () =
- let lines = input_to_lines input in
- let turns = lines_to_turns lines in
- let start = Dial.start in
- let answer = turn start turns in
- answer
+ if input = "" then Error err_empty_input
+ else
+ let lines = input_to_lines input in
+ let turns = lines_to_turns lines in
+ let start = Dial.start in
+ let answer = turn start turns in
+ Ok answer