diff options
| author | DJ O'Leary <dijitol@proton.me> | 2026-06-27 04:28:48 +0200 |
|---|---|---|
| committer | DJ O'Leary <dijitol@proton.me> | 2026-06-27 04:28:48 +0200 |
| commit | bc8b9edc0860f4804dfd0ea868ee7beaa564e62a (patch) | |
| tree | e1123d11627b4829586da3b097015b1dbb3d0285 /2024/ocaml/lib/day_01/part_02.ml | |
| parent | 976048a85403fbb0751c34fa42703a3c47f6e918 (diff) | |
Diffstat (limited to '2024/ocaml/lib/day_01/part_02.ml')
| -rw-r--r-- | 2024/ocaml/lib/day_01/part_02.ml | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/2024/ocaml/lib/day_01/part_02.ml b/2024/ocaml/lib/day_01/part_02.ml deleted file mode 100644 index 25c8b7d..0000000 --- a/2024/ocaml/lib/day_01/part_02.ml +++ /dev/null @@ -1,44 +0,0 @@ -(* Day 1: Part 2 *) - -let rec count_occurrances_help element acc lst = - match lst with - | [] -> acc - | h :: t -> - if h = element then count_occurrances_help element (acc + 1) t - else count_occurrances_help element acc t - -let count_occurrances element lst = count_occurrances_help element 0 lst - -let solve left right = - List.map (fun x -> x * count_occurrances x right) left - |> List.fold_left ( + ) 0 - -let left line = - let pos = 0 in - let len = String.index line ' ' in - String.sub line pos len - -let right line = - let pos = String.rindex line ' ' + 1 in - let len = String.length line - pos in - String.sub line pos len - -let line_to_tuple line = (left line, right line) - -let lines_to_lists lines = - let tuples = List.map line_to_tuple lines in - let left = - List.map - (fun t -> - let l, _ = t in - int_of_string l) - tuples - in - let right = - List.map - (fun t -> - let _, r = t in - int_of_string r) - tuples - in - (left, right) |
