7
votes
Day 5: Sunny with a Chance of Asteroids
Today's problem description: https://adventofcode.com/2019/day/5
Join the Tildes private leaderboard! You can do that on this page, by entering join code 730956-de85ce0c
.
Please post your solutions in your own top-level comment. Here's a template you can copy-paste into your comment to format it nicely, with the code collapsed by default inside an expandable section with syntax highlighting (you can replace python
with any of the "short names" listed in this page of supported languages):
<details>
<summary>Part 1</summary>
```python
Your code here.
```
</details>
Haven't finished yet, but wanted to comment and say woof, this one's a doozy. If anyone else out there is struggling, you aren't alone.
Edit: Finished it last night. In retrospect, it wasn't actually that difficult to code, but the instructions were pretty difficult to grok.
Part 1
Part 2
This was a very mutation-heavy problem, which went against my functional sensibilities. I'm not happy with the result, but it got the correct answer. If it's stupid but it works, then it ain't stupid.
No shit, this one was exhausting, you're basically programming a compiler, now? Had to read the instructions like 5 times to even make sense of them and they're long (not to mention build upon day 02, so if you hadn't done that one yet, it's double the work). I spent way too long on the second star's final test sample before I remembered to check outputs for "immediate mode".
Part 2
And my adventure with Elixir continues!
My architecture from day 2 held up, and adding new opcodes was straightforward. The hardest part was parsing the opcode and mode arguments, but in the end I found a rather simple solution.
Intcode module
Part 1
Part 2
Love this and love Elixir. Great work!
Also, because I like wasting time, I later added an additional detail: if opcode 3 (input read), can't find input, it produces error code -999. With this, I created the following intcode program:
"3,17,1008,17,-999,19,1005,19,20,1,17,18,18,1105,1,0,0,0,0,0,4,18"
Given a list of numbers as input, it loops through them and sums them together!
I just spent an unreasonable amount of time tracking down an issue in my addressing mode decoder, good unit testing is important here. Something I need to work on myself :S.
Day 5 Intcode Interpreter
I'm not entirely satisfied with how I'm handling the addressing modes, writing to a parameter is always encoded as a "position"-mode parameter (an address), but the actual value of that parameter should be interpreted literally. I.e. you don't see
0003 4
and go find the value at4
then write your input to that address (indirect), you always write directly to4
.I think I want to lift out the concept of a "parameter" into its own object that tracks its value as encoded and the addressing mode, and let the VM operate on that to distinguish between the read and write behaviors.
Day 5 (with nicer parameter handling)
I went back and cleaned up the handling of read/write parameter and addressing modes. Now I'm parsing out the parameter explicitly, and the VM object knows how to read and write from a given parameter. The parameter objects know their own addressing mode, and the VM can use that to understand the difference between writing to a position-mode parameter or the (inevitable) register-mode parameter.
I've also noticed that the test binary includes a good deal of code that we haven't gotten to yet, there may be some hints in there...
This language is looking more and more like Brainfuck. I got stuck for a bit because I had the order of the modes reversed, then tried to solve it cleanly. Then I got impatient and just reversed the string; I'll try to clean it up later.
Part 1
Part 2
EDIT: Okay, cleaned up; it's amazing what a short water break can do. I'm not sure if the method to read a line of input is POSIX, but it's compatible with
gawk
,lok
,mawk
, andnawk
, so I think it's fine even if it isn't.I had a rough day today so I only got to the first part. I will probably work on adding things for the second part tomorrow before starting on the new challenges. I had a little trouble with getting the immediate vs. position mode right on the I/O instructions, but other than that I think I was able to fit it into the format I started with on day 2 fairly well.
EDIT: Part 2 complete!
Parts 1 and 2, Python
EDIT: Part 2 was not as hard as I thought it would be. My only hiccup was moving the pointer on the jump instructions when there was not a jump.
I had to do moderately heavy modifications from day 2, but mostly it was just converting stuff to functions that I had previously hard-coded. Overall my structure worked pretty well.
It would definitely be shorter if I didn't include verbose and super_verbose modes. Still plenty of fun, I'm hoping we do more with the int-puter. It's getting closer to a processor
Day 5 - Python
I got sick, but now I kinda fine, so I return.
It was really hard to read and to understand the task for me too.
PHP
functions.php
part-2.php
; For part-1 just remove cases. But here is no different exept value of$enter
(sysmtem ID), even with these cases it works same.