diff options
| author | DJ O'Leary <dijitol@proton.me> | 2025-11-29 20:23:02 +0100 |
|---|---|---|
| committer | DJ O'Leary <dijitol@proton.me> | 2025-11-29 20:23:02 +0100 |
| commit | 4c3a50166bf0f78ce89459c352cc1c6536a8b96d (patch) | |
| tree | 02e4b66a1435680ef1e92bf82576747b27f16447 /2024/OCaml/lib/day_02 | |
| parent | be2f8528b3829f8263507da301812d852297c168 (diff) | |
chore: make language folders snake_case
Diffstat (limited to '2024/OCaml/lib/day_02')
| -rw-r--r-- | 2024/OCaml/lib/day_02/part_01.ml | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/2024/OCaml/lib/day_02/part_01.ml b/2024/OCaml/lib/day_02/part_01.ml deleted file mode 100644 index 32d7ab8..0000000 --- a/2024/OCaml/lib/day_02/part_01.ml +++ /dev/null @@ -1,42 +0,0 @@ -(* Day 2: Part 1 *) - -type level = int -type reports = level list list - -let rec compare_report_levels_helper comparison prev report = - match report with - | [] -> true - | h :: t -> comparison prev h && compare_report_levels_helper comparison h t - -let compare_report_levels comparison report = - match report with - | [] -> true - | h :: t -> compare_report_levels_helper comparison h t - -let all_increasing report = compare_report_levels ( < ) report -let all_decreasing report = compare_report_levels ( > ) report - -let at_least_one report = - compare_report_levels (fun prev curr -> prev <> curr) report - -let at_most_three report = - compare_report_levels (fun prev curr -> abs (prev - curr) <= 3) report - -let check_report_safety report = - if not (all_increasing report || all_decreasing report) then false - else if not (at_least_one report && at_most_three report) then false - else true - -let rec count_safe_reports acc lst = - match lst with - | [] -> acc - | h :: t -> - if h then count_safe_reports (acc + 1) t else count_safe_reports acc t - -let solve reports = - reports |> List.map check_report_safety |> count_safe_reports 0 - -let line_to_report line = - line |> String.split_on_char ' ' |> List.map int_of_string - -let lines_to_reports lines = List.map line_to_report lines |
