diff options
| author | DJ O'Leary <dijitol@proton.me> | 2025-12-08 01:55:28 +0100 |
|---|---|---|
| committer | DJ O'Leary <dijitol@proton.me> | 2025-12-08 01:57:20 +0100 |
| commit | 0f34d9a931791406d2cabf282742530195f71927 (patch) | |
| tree | 076e546f64f8f541e91bf135d5d5c78cde173ccf /2025/ocaml/lib/application/d01p01.ml | |
| parent | 63c4dea442acb32db82318b4399ac05fb955e6d0 (diff) | |
refactor(2025,ocaml): use result type for answers to allow for returning errors
Diffstat (limited to '2025/ocaml/lib/application/d01p01.ml')
| -rw-r--r-- | 2025/ocaml/lib/application/d01p01.ml | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/2025/ocaml/lib/application/d01p01.ml b/2025/ocaml/lib/application/d01p01.ml index 75e1b17..206e757 100644 --- a/2025/ocaml/lib/application/d01p01.ml +++ b/2025/ocaml/lib/application/d01p01.ml @@ -1,5 +1,7 @@ open Domain.D01p01 +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 <> "") @@ -42,8 +44,10 @@ let rec turn_aux count current = 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 |
