summaryrefslogtreecommitdiff
path: root/2025/ocaml
diff options
context:
space:
mode:
Diffstat (limited to '2025/ocaml')
-rw-r--r--2025/ocaml/lib/application/d02p01.ml32
1 files changed, 31 insertions, 1 deletions
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