cblavier
Advent of Code 2020 - Day 11
Hey there ![]()

No magic or algorithmic finesse today, I just finished the challenge and I my code is quite slow (1sec for part1, 3sec for part2).
But at least I managed to made my code readable and to reuse most of part1 for part2.
Most Liked
LostKobrakai
Recursion if it’s truely while do or do while:
https://github.com/LostKobrakai/aoc2020/blob/master/lib/aoc2020/day11.ex#L182-L191
My other goto for evaluation (does not always fit) is Stream.unfold:
https://github.com/LostKobrakai/aoc2020/blob/d9e79ebd6cd6d346df1705fd7ef109bb4fa5f596/lib/aoc2020/day3.ex#L30-L39
cblavier
Papey
I ended up with something nice for finding neighbours on part 2, but wow, this is veeeerryyyy slooooow (~4 seconds)
def neighbours(current, {x, y}) do
Enum.reduce(@dirs, 0, fn {dx, dy}, acc ->
[v] =
Stream.iterate(1, &(&1 + 1))
|> Stream.map(fn mul -> {x + dx * mul, y + dy * mul} end)
|> Stream.map(fn {xx, yy} -> Map.get(current, {xx, yy}) end)
|> Stream.drop_while(&(&1 == @floor))
|> Enum.take(1)
if v == @occupied, do: acc + 1, else: acc
end)
end
I was thinking about the fact that the current map is RO, did someone try to add some concurrency into the mix ?
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








