Did you get your IntCode machine just right on Day 5? Well, too bad, it was wrong.
Day 7 - The Problem
Looks like we need more power. And we're given some more parts to fix up our module to scrape a few more Joules out here and there. Unfortunately, our supply elves forgot to send us the documentation, and we have to find the optimal solution ourselves.
Part 1 is about finding the permutation of amplifiers that gives us the best output. Oh, and your IntCode compiler needs to be able to take multiple inputs now.
Part 2 decides that we need to create a feedback loop. I'm interested to see what people come up with for this one. Maybe we can fake the async?
This one swerves right back into hard territory for me. At the time of posting this, I've only solved part 1, and I may not be able to return to part 2 until Sunday! Calamity! (Ah well, such is life!)
Ongoing Meta
Dev.to List of Leaderboards
-
120635-5c140b9a- provided by Linda Thompson
If you were part of Ryan Palo's leaderboard last year, you're still a member of that!
If you want me to add your leaderboard code to this page, reply to one of these posts and/or send me a DM containing your code and any theming or notes you’d like me to add. (You can find your private leaderboard code on your "Private Leaderboard" page.)
I'll edit in any leaderboards that people want to post, along with any description for the kinds of people you want to have on it. (My leaderboard is being used as my office's leaderboard.) And if I get something wrong, please call me out or message me and I’ll fix it ASAP.
There's no limit to the number of leaderboards you can join, so there's no problem belonging to a "Beginner" and a language specific one if you want.
Neat Statistics
I'm planning on adding some statistics, but other than "what languages did we see yesterday" does anyone have any ideas?
Languages Seen On Day 06
- JavaScript × 4
- Python × 2
- Clojure × 1
- Elixir × 1
- Java × 1
- Kotlin × 1
- PHP × 1
- Prolog × 1
- Swift × 1
Many thanks to special guest stat compiler Massimo Artizzu
Latest comments (23)
That was hard, but here is my javascript walkthrough
Playing some Sunday night catch-up. My previous architecting bit me in the butt today. Had to re-think my "stdin/stdout" concepts. Converted them to vector buffers (should probably have used queues, but too lazy). Worked out pretty well. The key for me was adding in a new opcode (98, so far unused) to signify a halt waiting for input rather than a full program halt (99). Here's my (part 2) solution in Rust:
And, my Intcode Interpreter, for reference. I completed day 7 and 9 back to back, so there's some day 9 stuff in here that won't apply to this problem:
Horray, finally got part 2 solved!! happy dance Took FOREVER but I finally got it working. This will be the part 2 solution in JavaScript (part 1 was very similar, just slightly more simplified and didn't involve the objects I created for each amp).
Here's my part 2 solution in #haskell. I ended up needing to do some substantial refactoring from my previous solution that I'd used for day 5 as well as part 1. My original version attempting to go for performance by using mutable vectors to store the program state, ostensibly allowing for more performant seeks and writes to the program state. I started to extend this approach using IORefs to program state and some other clever trickery. Although I managed to get constant memory utilization, the performance was so bad the program never actually finished running.
After profiling didn't help enough, and I verified that there was nothing unsound about my algorithm, I decided to start from the ground up with the simplest solution and went back to a pure implementation using record updates to manage all of the changes to start, and manually sending IO between the amplifiers. Once again proving that when it comes to optimization I'm never as clever as I think I am, the compiler did it's job and took my naive implementation and gave me a version that finished in a couple hundred milliseconds.
My new version needs some refactoring still, both for readability and ergonomics during future challenges, but here is the version left on my disk from when I finally finished up at 5am:
Hey Jon, I was curious so I counted the languages used on day 6 for you 🤗
JavaScript × 4
Python × 2
Clojure × 1
Elixir × 1
Java × 1
Kotlin × 1
PHP × 1
Prolog × 1
Swift × 1
Awesome! Thanks! (Runs off to paste it in before I head to bed.)
Part one was a piece of cake imo. Part two was a lot tougher.
Yoooo and I thought day 5 was annoying 😫
Anyway... JavaScript. It has this nice generator thing that I basically never used professionally and very rarely by myself, and here I am using them twice here. But you know, they're quite good for stateful machines. (Which is also why I rarely use them - like many others, I prefer stateless approaches.)
This is the solution for the second part, as the first can run the first (except for the phase settings, where I just add 5 to the permutation's elements - see at the end).
Many parts are the same of day 5 of course. Sorry for the repetition.
See text, input and first part on my repo.
I decided to go with javascript and use generators so I could easily suspend the amplifier program between inputs
Well that was fun! My decision on day 2 to do the machine simulator in C continues to be both an advantage and a disadvantage. I'm enjoying flitting between the low-level pointer hacking and the high-level Prolog and Haskell solutions on other days.
Generating the permutations of the phase signals was the hardest bit today. The principle is a simple one - lock some digits, generate the permutations of the remaining, and recurse - but the details and corner cases in recursive C were a bit tricky.
Today's code runs both parts in 14 milliseconds!
Code at github.com/neilgall/adventofcode20...
Well, today was definitely fun. Continuing in Python from previous days, part one was fairly easy as the modifications to my existing Intcode computer were minimal and the task itself was fairly straight-forward, but part two was interesting.
For part two, I chose to rewrite my whole Intcode computer in dart, as that is the language I am most familiar with, and I'm happy I did so. I then gave each amplifier a StreamController as its output and the BroadcastStream of the previous amplifier's StreamController as its input and had them listen to each other in async. Probably not the easiest way to do it, but very fun and interesting to write.
Here's the code for part 2:
And the code for my dart Intcode Computer: gist.github.com/jakcharvat/818c477...