Day 2 is in the books! And surprisingly, we're into pseudo-interpreter territory already!
Day 2 - The Problem
We need to slingshot ourselves around the moon, but the computer that calculates our trajectory has sadly exploded. Given our current data and the specs for that machine, we need to build ourselves a new IntCode interpreter.
It's surprising to me to see a psuedo-assembly converter so early in the Advent of Code, but this one turned out to be vaguely straightforward. Most of my personal problems stemmed from input validation. (If you're a newbie, let me assure you that input validation is almost always something that will slow you down. This goes triply for anyone learning a new language!)
Part 2 luckily doesn't require a whole lot of extra logic, but it has a bit of "optimization" and "compartmentalization" to keep tabs on.
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?
Top comments (24)
I struggled with reading comprehension tonight 🤦🏼♀️
Yeah, the second part's wording was really confusing to me.
Thank you! It really helps me to understand the second part.
Me too! I spent a good couple minutes trying to figure out why the sum of their test opcode didn't match the answer... 😭
Some Kotlin code :)
On github: github.com/sup95/AdventOfCode-19/b...
In past Advent of Codes I've belligerently tried to write these machine simulators in Haskell or pure functional Kotlin or something else completely inappropriate. Maybe it's a sign of maturity that this year I've done it in C.
It's been a while since I've written C. The purity and simplicity is refreshing.
Funny, I think they're harder to write initially in a functional language, but easier to modify and extend in later questions.
Extending to part 2 was easy enough. But the description today made it clear more is coming so I can't wait to find out!
My solution in JS.
It took more time than I expected but finally done with it. I actually started Day 1 today as well.
Here is my solution in swift. Incase anyone would like followup code can be found here in Github
My solution in Rust
Pretty rough assignment on day two already, but got it working in the end! I've solved it in Elixir. Here's my solution for part two:
Check out part one here
Back again with more Clojure.
My favorite part of this is how the actions get selected. the
get-action
function actually returns the function used for handling the inputs (where 99 returns a function that, regardless of input, returns "stop"). Then, that function is used with theapply
function insidecalculate
to actually pass the arguments to that function.I'm sure there should be a better way of handling the brute force handling of part 2, but for now, it's just a poor man's nested for loop implemented using atoms.
JavaScript checking in! I think it'll be interesting, seeing how we re-use this in future challenges. It did take me reading the end of part 2 a number of times before I understood what I was looking for! :)
I also feel like there should be a better way to process the second part...I saw folks on the subreddit talking about just changing the noun value until it's as high as can be while still below the desired output, then changing the verb, but it seems maybe there's unforeseen issues with that? I don't know, everyone I've seen so far is just nesting for loops so I'm not that worried about it. :)
Here's my Python solution - nothing special or well optimised, but it works: