Day 2 is in the books! And surprisingly, we're into pseudo-interpreter territory already!
Day 2 - The Problem
We need to slingshot ours...
For further actions, you may consider blocking this person and/or reporting abuse
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
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
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.
My solution in Rust
My kotlin solution:
Also super stoked that the poem I wrote for day 1 was picked as the first winner! So my comment on the megathread has a little silver medal next to it. :) For not having written any sort of fun fiction in years, I'm really excited they liked it enough to reward it!
They sent me a fun little image when they commented on it, too -
Congratulations! I love the secondary artifacts and self-imposed additional challenges that people do for this. People seem to get more creative every year!
A bit late to the party, got my c++17 code working however
I got a couple of issues with types in JavaScript, but here is the solution:
I wrote my day 2 up here:
Day 2
Written in Clojure