Qqwy

Qqwy

TypeCheck Core Team

Advent of Code - Day 7

Note by the Moderators: This topic is to talk about Day 7 of the Advent of Code.

For general discussion about the Advent of Code 2018 and links to topics of the other days, see this topic.

Most Liked

sasajuric

sasajuric

Author of Elixir In Action

Here’s my take on day7. I implemented the first part as a special case of part two (using just one worker). This makes part 1 less optimal, but the running time is still good enough.

The curiosity of my approach is that I made a stream which emits all intermediate states. Part 1 then boils down to taking the last state and fetching the processed items. Part 2 amounts to counting all the states and decrementing it by one.

Last Post!

simon

simon

I’ve finally gotten around to solving this (code is here) and, like @sasajuric, my part two solution replaced me original part one code.

My solution revolves around having two maps; one for the steps, their dependencies and their durations and the other for workers, which step they are processing and when they will be done processing (in seconds).

I’m using recursion to step through time and at each second I check to see if any steps have been completed (and log their identifier if they have) and then assign any pending steps to any available workers.

When a step is assigned to a worker it is removed from the map of sets and any references to it are removed from the dependencies list in other steps. The actual progress of a step (really just monitoring when it is complete) is done via the workers.

I’m not entirely happy with my code and will be going back to do some tidying (and documenting) but that’s tending to be my overall trend with these challenges. They’re proving to be a fantastic way to find my way around the Elixir standard libraries but they’re also taking me far longer to complete then they probably should.

Ah well… I’ll improve with practice!

Where Next?

Popular in Challenges Top

QuinnWilton
Note: This topic is to talk about Day 7 of the Advent of Code 2019 . There is a private leaderboard for elixirforum members. You can joi...
New
Aetherus
This topic is about Day 15 of the Advent of Code 2020 . Thanks to @egze, we have a private leaderboard: https://adventofcode.com/2020/l...
New
bjorng
This topic is about Day 17 of the Advent of Code 2020 . Thanks to @egze, we have a private leaderboard: https://adventofcode.com/2020/l...
New
code-shoily
Just did part 1. Part 2 seems to be demanding too much of my reading time so will get to that after I am done with some chores. Oh here ...
New
bjorng
This topic is about Day 6 of the Advent of Code 2021. We have a private leaderboard (shared with users of Erlang Forums ): https://adve...
New
jkwchui
Monkeys fitted squarely as GenServers in my head. My initial problem was using cast instead of call; I imagine impolite monkeys slinging...
New
lud
Gosh this one took me sooo much time. At first I was trying to iterate each digit independently on the input A number to make digits cha...
New

Other popular topics Top

grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54006 488
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44139 214
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New

We're in Beta

About us Mission Statement