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
https://github.com/papey/aoc/commit/28227b000a7dbe2ddfc122c6e36a6d9f7d3f4167
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.
Popular in Challenges
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









