From 0f34d9a931791406d2cabf282742530195f71927 Mon Sep 17 00:00:00 2001 From: DJ O'Leary Date: Mon, 8 Dec 2025 01:55:28 +0100 Subject: refactor(2025,ocaml): use result type for answers to allow for returning errors --- 2025/ocaml/lib/application/d01p01.ml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to '2025/ocaml/lib/application/d01p01.ml') 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 -- cgit v1.2.3