Skip to content

Instantly share code, notes, and snippets.

@SaschaMann
Created December 2, 2019 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SaschaMann/ba7ddfde3224a42d004c18a153d2c554 to your computer and use it in GitHub Desktop.
Save SaschaMann/ba7ddfde3224a42d004c18a153d2c554 to your computer and use it in GitHub Desktop.
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
@cmcaine
Copy link

cmcaine commented Dec 2, 2019

I like that you called it reverse :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment