diff --git a/2024/day8.exs b/2024/day8.exs index 3fbc042..694fc13 100755 --- a/2024/day8.exs +++ b/2024/day8.exs @@ -1,14 +1,14 @@ #!/usr/bin/env elixir defmodule Day8 do - def part1({x, y, antennas}) do - Enum.reduce(antennas, MapSet.new(), fn coords, antinodes -> - MapSet.union(antinodes, find_antinodes(coords, x, y)) + def part1({x, y, frequencies}) do + Enum.reduce(frequencies, MapSet.new(), fn antennas, antinodes -> + MapSet.union(antinodes, find_antinodes(antennas, x, y)) end) |> MapSet.size() end - def find_antinodes(coords, x, y) do - coords + def find_antinodes(antennas, x, y) do + antennas |> find_pairs() |> Enum.flat_map(fn pair -> calc_antinodes(pair, x, y) end) |> MapSet.new() @@ -28,15 +28,15 @@ defmodule Day8 do end) end - def part2({x, y, antennas}) do - Enum.reduce(antennas, MapSet.new(), fn coords, antinodes -> - MapSet.union(antinodes, find_resonant_harmonics(coords, x, y)) + def part2({x, y, frequencies}) do + Enum.reduce(frequencies, MapSet.new(), fn antennas, antinodes -> + MapSet.union(antinodes, find_resonant_harmonics(antennas, x, y)) end) |> MapSet.size() end - def find_resonant_harmonics(coords, x, y) do - coords + def find_resonant_harmonics(antennas, x, y) do + antennas |> find_pairs |> Enum.flat_map(fn pair -> calc_resonant_harmonics(pair, x, y) end) |> MapSet.new()