diff options
| author | DJ O'Leary <dijitol@proton.me> | 2025-12-02 13:42:04 +0100 |
|---|---|---|
| committer | DJ O'Leary <dijitol@proton.me> | 2025-12-02 13:42:04 +0100 |
| commit | 893440696a4f14f323e80c739e78fc9ee3bda8ea (patch) | |
| tree | 263313fba865a5de9a119f9e0fcc19d1aa372832 /2025/ocaml/lib/application/d02p01.ml | |
| parent | e43cb2323c9b6705ac5b4f1a65b1c0eca42489c0 (diff) | |
feat(2025d2p1): parse input into tuples
Diffstat (limited to '2025/ocaml/lib/application/d02p01.ml')
| -rw-r--r-- | 2025/ocaml/lib/application/d02p01.ml | 32 |
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 |
