summaryrefslogtreecommitdiff
path: root/2024/OCaml/lib/day_03
diff options
context:
space:
mode:
authorDJ O'Leary <dijitol@proton.me>2025-11-29 20:23:02 +0100
committerDJ O'Leary <dijitol@proton.me>2025-11-29 20:23:02 +0100
commit4c3a50166bf0f78ce89459c352cc1c6536a8b96d (patch)
tree02e4b66a1435680ef1e92bf82576747b27f16447 /2024/OCaml/lib/day_03
parentbe2f8528b3829f8263507da301812d852297c168 (diff)
chore: make language folders snake_case
Diffstat (limited to '2024/OCaml/lib/day_03')
-rw-r--r--2024/OCaml/lib/day_03/part_01.ml33
1 files changed, 0 insertions, 33 deletions
diff --git a/2024/OCaml/lib/day_03/part_01.ml b/2024/OCaml/lib/day_03/part_01.ml
deleted file mode 100644
index c12b68a..0000000
--- a/2024/OCaml/lib/day_03/part_01.ml
+++ /dev/null
@@ -1,33 +0,0 @@
-(* Day 3: Part 1 *)
-
-let find_mul text =
- let regex_or_err = Re2.create "mul\\(([0-9]{1,3}),([0-9]{1,3})\\)" in
- match regex_or_err with
- | Ok regex -> (
- let matches = Re2.get_matches regex text in
- match matches with Ok matches -> matches | Error _ -> [])
- | Error _ -> []
-
-let extract_pairs (matches : Re2.Match.t list) : (int * int) list =
- List.map
- (fun x ->
- let left = Re2.Match.get x ~sub:(`Index 1) in
- match left with
- | None -> (0, 0)
- | Some left -> (
- let left_num = int_of_string left in
- let right = Re2.Match.get x ~sub:(`Index 2) in
- match right with
- | None -> (0, 0)
- | Some right ->
- let right_num = int_of_string right in
- (left_num, right_num)))
- matches
-
-let solve input =
- input |> find_mul |> extract_pairs
- |> List.fold_left
- (fun acc pair ->
- let left, right = pair in
- acc + (left * right))
- 0