Qqwy
TypeCheck Core Team
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.
Trending in Challenges
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #ai
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sasajuric
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.
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!