How is 304099 output its input and halt
# advent-of-code
a
How is 304099 output its input and halt
m
1. Reads 3 which is input, takes the input and stores it in the given position per the first parameter which is 0. So position 0 now has the input value. 2. Moves two positions, reads 4 which is output. Checks the given position per the first parameter which is 0, where the input value is stored 3. moves two position. 99 - halt
The effect being that what your input is, will be the program's output before it halts
a
But what is the input value?
What gets stored in position 0
m
You provide this
a
....
m
For example as an argument to a function
a
I might just skip today’s one
m
Think of it as a variable
For part 1, the input will be "1" (well, the number 1)
so if you just have
val input = 1
somewhere you'll be fine
so
304099
would be
104099
when processed
and have made the output 1
And the "output"...you can print that if you wish, I just stored my outputs in a list. The interesting part today is the last output, so that's all you need. I just wanted to make sure all my other output values were 0.
Do you understand?
Like, the input value could be anything, but per part one's instructions, it must be 1. Only one input value is needed, he calls it an "input instruction" and it's just a way of telling our "intcode computer how to run", but in practice it means nothing, it's just a story. For part 1, you can read the instruction "Opcode 3 takes a single integer as input and saves it to the position given by its only parameter." as "Opcode 3 - set the value 1 at the position given by it's only parameter"
Hope that helps - time to sleep in my part of the world 🙂