Papey
Avent of Code 2020 - Day 20
This topic is about Day 20 of the Advent of Code 2020 .
Thanks to @egze, we have a private leaderboard:
https://adventofcode.com/2020/leaderboard/private/view/39276
The join code is:
39276-eeb74f9a
Most Liked
Papey
Just the part 1 for now.
I did not reconstruct the map, just looked at corners. It’s ugly and verbose but it works.
Now on part 2, but I already find the sea monster, it’s my function that finds corners 
def find_corners(tiles) do
# Map all edges to corresponding tiles
Enum.reduce(tiles, %{}, fn {id, tile}, acc ->
edges = edges(tile)
Enum.reduce(edges ++ Enum.map(edges, &flip/1), acc, fn edge, acc ->
{_old, acc} =
Map.get_and_update(acc, edge, fn old ->
if old do
{old, [id | old]}
else
{old, [id]}
end
end)
acc
end)
end)
# Filters out singleton
|> Enum.filter(fn {_edge, ids} -> length(ids) == 1 end)
# A list of one is just the element inside that list
|> Enum.map(fn {edge, [id]} -> {edge, id} end)
# Reverse the reduce to find how many edges maps this tile id
|> Enum.reduce(%{}, fn {_edge, id}, acc ->
{_old, acc} =
Map.get_and_update(acc, id, fn old ->
if old do
{old, old + 1}
else
{old, 1}
end
end)
acc
end)
# filter out candidates
|> Enum.filter(fn {_id, match} -> match > 2 && match < 5 end)
|> Enum.map(fn {id, _match} -> id end)
end
lud
bjorng
I tried to leverage my corner-finding code from part 1 for part 2, but I didn’t make much progress. After sleeping on it I decided to start over with another approach for part 2. I spent most of the time getting the tile combining to work. After that, it was fairly easy to implement the search for the sea monster.
Here is my solution.
blue_quartz
Not sure if it’s too late, but here’s my day 20 solution if anyone’s interested.
advent20/day20.ex at master · h-j-k/advent20 (github.com)
I’ve also documented my walkthrough if you want to understand the logic behind the steps I’ve taken… advent20/README.md at master · h-j-k/advent20 (github.com)







