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.
Me too! I spent a good couple minutes trying to figure out why the sum of their test opcode didn't match the answer... 😭
Thank you! It really helps me to understand the second part.
My solution in JS.
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!
Some Kotlin code :)
On github: github.com/sup95/AdventOfCode-19/b...
I can't believe no one has posted a solution in Janet yet! Oh wait, no, I totally believe it. It was also my first attempt in this language. I've been looking at it for some time already but only today I decided to give it a shot. It basically feels like a imperativ-ish LISP.
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:
In the browser!
Here's my Rust code. I was lucky that I caught that bit at the very end of the instructions about setting the initial values. Otherwise I probably would have spiraled trying to figure out why my answer to Part 1 was wrong.
Now I just need to refactor this out to make it easy to extend for future days!
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