Thankfully it wasn't TOO many steps to get through to the end of this particular puzzle; need to add some additional functionality to "run until next input or halt" in there...!
Bring it on. My day 2 solution wasn’t exactly maintenance friendly, but with the mode operations and more I decided to rewrite today’s solution into using a jump table, so adding new opcodes is a question of adding another entry to the table and implementing the function.
In hindsight i should’ve known that it would come back... it has in the past years.
Sounds like a neat idea. Did you figure out a better solution for dealing with the modes than an if-else type thing? I guess you could also use some kind of a table there, but you'd still need to do some padding or filling in of values in case of missing leading zeros in the mode specifier.
Not sure what language you all used, but in Python, you can link a value to a function by a dictionary. ops = { 1: operator.add, 2: operator.mul, 99:halt } ops 99 ## calls halt () For day 2, I made a class, and for 5 I will inherit from that class to make modifications.
I think I was approaching something like that. I was thinking of instruction subclasses rather than functions in a dict, though, and stopped going in that direction because subclassing for every instruction seemed overkill an maybe a bit unpythonic. A mapping in a dict actually sounds quite nice.
However, off the top of my head, I suppose every instruction implementation would still need to get a reference to the memory, the instruction pointer, the parameter modes... and either parse those or get them pre-parsed by the main loop.
I'm not entirely unhappy with the way my code looks, but it kind of does feel to me like it could perhaps be a bit more compact and elegant, so maybe I'll try and see if I can improve it with something like your dict idea.
The modifications for day 5 seem to be backwards compatible with day 2 so I just kept adding to the existing code apart from a task-specific main program.
Yeah, the fact that an opcode can be 2 digits long, and the only opcode 2 digits long for now is 99 (HALT), makes me 100% sure that they will add new opcodes :D
Okay, we're into the new year, but I got it! My code repository at https://gitlab.com/MidnightLightning/advent-of-code is updated to include my code for cracking Day 7 part 2, if you'd like to use that as reference.
I have a small doubt : I have started a few days ago (so, very late), and I've reached day 5, but some parts of my input differs with yours (the first one is at value 12, I have 1102 instead of your 1101.
Does everyone have different inputs, or has something been modified, either in your display, either in the original input ?
Everybody gets a different input, and hence a different answer/solution, to each day's puzzle. This one is mine, so yours will not be identical, but will probably be similar.
I have a doubt and would really appreciate if you can clear it. For index 2 the opcode is 1 so add 225 and 6 and save at index 6. But the value is changed from 1100 to 1101. I thought the value at index 6 should change to 231.
Glad you figured it out! For others who come behind you who have the same confusion, the way that opcode is working is:
For index 2 the opcode is 1 so add the value saved in address 225 (which is 1) and the value saved in address 6 (which is 1100) and save at index 6 (overwriting 1100 with 1101).
7
u/MidnightLightning Dec 05 '19
Thankfully it wasn't TOO many steps to get through to the end of this particular puzzle; need to add some additional functionality to "run until next input or halt" in there...!
4
u/tech6hutch Dec 05 '19
I'm still on Day 4, but I'm glad the Intcode computer comes back. I was hoping it would.
2
u/ni3t Dec 05 '19
Most fun game of cookie clicker ever
1
u/_nireus_ Dec 18 '19
hi, do you have this for the day 7 part 2? I am using your visual data to see where I'm doing wrong :)
1
u/ben15810 Dec 19 '19
Hello,
I have a small doubt : I have started a few days ago (so, very late), and I've reached day 5, but some parts of my input differs with yours (the first one is at value 12, I have 1102 instead of your 1101.
Does everyone have different inputs, or has something been modified, either in your display, either in the original input ?
Thanks a lot...
1
u/zampya Dec 06 '19
I have a doubt and would really appreciate if you can clear it. For index 2 the opcode is 1 so add 225 and 6 and save at index 6. But the value is changed from 1100 to 1101. I thought the value at index 6 should change to 231.
1
u/snowguy13 Dec 05 '19
This is sweet!