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

sasajuric
Note by the Moderators: This topic is to talk about Day 5 of the Advent of Code. For general discussion about the Advent of Code 2018 an...
New
Aetherus
This topic is about Day 4 of the Advent of Code 2020 . Thanks to @egze, we have a private leaderboard: https://adventofcode.com/2020/le...
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 5 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
Aetherus
I spent 3 hours struggling in part 2, until I noticed a very basic mistake :joy: Here’s my code: https://github.com/Aetherus/advent-of-...
New
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement