defmodule AOC.Day4 do use AOC.Day, day: 4 def parse_input(lines) do Enum.map(lines, fn line -> [assign1, assign2] = line |> String.split(",") |> Enum.map(fn assign -> [from, to] = assign |> String.split("-") |> Enum.map(&String.to_integer/1) MapSet.new(from..to) end) {assign1, assign2} end) end def part1(input) do input |> Enum.map(fn {set1, set2} -> MapSet.subset?(set1, set2) or MapSet.subset?(set2, set1) end) |> Enum.count(& &1) end def part2(input) do input |> Enum.map(fn {set1, set2} -> MapSet.intersection(set1, set2) |> Enum.any?() end) |> Enum.count(& &1) end end