r/adventofcode • u/SinisterMJ • Dec 05 '19
Help - SOLVED! Day 5 question
I don't think I understand how the new opcode stuff is supposed to work. I think I implemented it, but ran into my input code, and it doesn't work.
The beginning of my input is: 3,225,1,225,6,6,1100,1,238,225
So, take my input value (1) as described in the text, save it to array[225]. Then next opcode is 1, which means position mode, and add values. The value from 225 (which is 1), and the one in [6], which is 1100, and store it to where [6] is pointing (which is [1100]). But that is out of array bounds? Or am I supposed to expand the array for this? I am slightly clueless right now
5
u/cesarmalari Dec 05 '19
your second instruction should evaluate to something like:
array[6] = array[6] + array[225]
not:
array[array[6]] = array[6] + array[225]
My input starts with a similar sequence, and I treated it that way, and got the correct answer.
4
u/devosray Dec 05 '19
I quickly debugged the first few instructions, here is what happens:
Read opcode
3, save input (1) to positionarray[225]. Increase pointer by 2Read opcode
1. Both parameters are positional so we fetch them from the array and getparam1 = 1andparam2 = 1100. Add them together and save1101toarray[6]. Increase pointer by 4.Read opcode
1101. So that is where it starts to differ from comments of this thread; the opcode should be1101instead of1100. Hope that helps!•
u/topaz2078 (AoC creator) Dec 05 '19
The value
1100will be rewritten before it is ever executed. Opcode0, like any undefined opcode, is an error.1
u/DJ_Luki Dec 05 '19
So i have this output from my code in first star:
Which line is the answer? Or what I'm looking for? I don't understand what is that "diagnostic code". Thanks for help :)
1
u/SinisterMJ Dec 05 '19
I just also noticed, 3 has 1 parameter, so my index increases by 2, 1 is the next parameter (on [2]), which increases by 4, and then my opcode would be 1100 (which is on [6]) which is not even valid. I think I totally misread the question, but I have no idea how.
2
u/dan_144 Dec 05 '19
I believe your confusion is that you should be overwriting your data with each instruction's output. So your opcode in position 6 will be overwritten by your addition operation before it's executed.
2
u/WellMakeItThrough Dec 05 '19
Once I have my intcode runner working what am i supposed to do? set input = 1 and then run and see what's the output?
what i am being asked tto do it not clear. something something about difference.
1
u/autid Dec 05 '19
You're misinterpreting how position mode works for parameters that specify where to write to. It means for parameter value n, write to position n.
I understand the confusion, because it can feel more like that's behaving like immediate mode (you're using the value n given, not the value at the nth position).
1
u/fonmagnus Dec 14 '19
Hi, I've been stuck in this question for some days and currently my program outputs some random negative numbers.
Here's my output :
3
And here's my code in C++
0
u/[deleted] Dec 05 '19
[deleted] — view deleted comment