Created
December 2, 2019 08:48
-
-
Save SaschaMann/ba7ddfde3224a42d004c18a153d2c554 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using OffsetArrays | |
using Test | |
const input = parse.(Int, split(read("2_input", String), ',')) | |
const instructions = Dict( | |
1 => +, | |
2 => *, | |
) | |
function init!(intcode, noun, verb) | |
intcode[1] = noun | |
intcode[2] = verb | |
return intcode | |
end | |
function main(input, noun, verb) | |
intcode = OffsetVector(copy(input), 0:length(input) - 1) | |
# 1202 program alarm | |
# init!(intcode, 12, 2) | |
init!(intcode, noun, verb) | |
i = 0 | |
while intcode[i] != 99 | |
intcode[intcode[i + 3]] = instructions[intcode[i]](intcode[intcode[i + 1]], intcode[intcode[i + 2]]) | |
i += 4 | |
end | |
return intcode[0] | |
end | |
function reverse(input, output) | |
for i in 0:99, j in 0:99 | |
main(input, i, j) == output && return 100 * i + j | |
end | |
end | |
function tests() | |
@test main(input, 12, 2) == 5866714 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I like that you called it
reverse
:)