From 893440696a4f14f323e80c739e78fc9ee3bda8ea Mon Sep 17 00:00:00 2001 From: DJ O'Leary Date: Tue, 2 Dec 2025 13:42:04 +0100 Subject: feat(2025d2p1): parse input into tuples --- 2025/ocaml/lib/application/d02p01.ml | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to '2025') diff --git a/2025/ocaml/lib/application/d02p01.ml b/2025/ocaml/lib/application/d02p01.ml index a40bd17..c4eebbe 100644 --- a/2025/ocaml/lib/application/d02p01.ml +++ b/2025/ocaml/lib/application/d02p01.ml @@ -1 +1,31 @@ -let solve input () = failwith "not implemented" +let pp_range range = + Logs.app (fun m -> m "range=%s" range) ; + range + +let pp_tuple tuple = + let l, r = tuple in + Logs.app (fun m -> m "(left=%s, right=%s)" l r) ; + tuple + +(** [input_to_ranges input] is a list of strings that have been split on ','. + Requires: [input] to be a string in the format "12-34,56-78,90-100" *) +let input_to_ranges input = + input |> String.split_on_char ',' + |> List.filter (fun range -> range <> "") + |> List.map pp_range + +let list_to_tuple = function + | [l; r] -> + (l, r) + | _ -> + failwith "list cannot convert to tuple" + +let ranges_to_tuples ranges = + ranges + |> List.map (fun range -> + let sides = String.split_on_char '-' range in + list_to_tuple sides |> pp_tuple ) + +let solve input () = + let _ = input |> input_to_ranges |> ranges_to_tuples in + 0 -- cgit v1.2.3