clearer variable names
This commit is contained in:
parent
6c003ed3c2
commit
9345419941
1 changed files with 10 additions and 10 deletions
|
@ -1,14 +1,14 @@
|
||||||
#!/usr/bin/env elixir
|
#!/usr/bin/env elixir
|
||||||
defmodule Day8 do
|
defmodule Day8 do
|
||||||
def part1({x, y, antennas}) do
|
def part1({x, y, frequencies}) do
|
||||||
Enum.reduce(antennas, MapSet.new(), fn coords, antinodes ->
|
Enum.reduce(frequencies, MapSet.new(), fn antennas, antinodes ->
|
||||||
MapSet.union(antinodes, find_antinodes(coords, x, y))
|
MapSet.union(antinodes, find_antinodes(antennas, x, y))
|
||||||
end)
|
end)
|
||||||
|> MapSet.size()
|
|> MapSet.size()
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_antinodes(coords, x, y) do
|
def find_antinodes(antennas, x, y) do
|
||||||
coords
|
antennas
|
||||||
|> find_pairs()
|
|> find_pairs()
|
||||||
|> Enum.flat_map(fn pair -> calc_antinodes(pair, x, y) end)
|
|> Enum.flat_map(fn pair -> calc_antinodes(pair, x, y) end)
|
||||||
|> MapSet.new()
|
|> MapSet.new()
|
||||||
|
@ -28,15 +28,15 @@ defmodule Day8 do
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def part2({x, y, antennas}) do
|
def part2({x, y, frequencies}) do
|
||||||
Enum.reduce(antennas, MapSet.new(), fn coords, antinodes ->
|
Enum.reduce(frequencies, MapSet.new(), fn antennas, antinodes ->
|
||||||
MapSet.union(antinodes, find_resonant_harmonics(coords, x, y))
|
MapSet.union(antinodes, find_resonant_harmonics(antennas, x, y))
|
||||||
end)
|
end)
|
||||||
|> MapSet.size()
|
|> MapSet.size()
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_resonant_harmonics(coords, x, y) do
|
def find_resonant_harmonics(antennas, x, y) do
|
||||||
coords
|
antennas
|
||||||
|> find_pairs
|
|> find_pairs
|
||||||
|> Enum.flat_map(fn pair -> calc_resonant_harmonics(pair, x, y) end)
|
|> Enum.flat_map(fn pair -> calc_resonant_harmonics(pair, x, y) end)
|
||||||
|> MapSet.new()
|
|> MapSet.new()
|
||||||
|
|
Loading…
Reference in a new issue