aoc2022/bin/d4/main.ml

21 lines
791 B
OCaml
Raw Permalink Normal View History

2022-12-04 09:32:45 +01:00
let is_full (start1, end1) (start2, end2) =
(start1 >= start2 && end1 <= end2) ||
(start2 >= start1 && end2 <= end1)
let is_partial (start1, end1) (start2, end2) =
(start1 >= start2 && start1 <= end2) ||
(start2 >= start1 && start2 <= end1)
open Utils
let split_pair c s = String.split_on_char c s |> pair_of_list
let get_elves = split_pair ','
let get_range range = range |> split_pair '-' |> map_pair int_of_string
let parse row = row |> get_elves |> map_pair get_range
let count_overlapping f l = l |> List.filter (uncurry f) |> List.length
let input = read_file "bin/d4/input.txt" |> List.map parse
let _ = "\n1: " ^ (string_of_int (input |> count_overlapping is_full)) ^
"\n2: " ^ (string_of_int (input |> count_overlapping is_partial)) |> print_endline ;;