Skip to content

Instantly share code, notes, and snippets.

@activexray
Created December 2, 2019 05:23
Show Gist options
  • Select an option

  • Save activexray/3ec189d0f0059eb38f7d9fc4fbe11fae to your computer and use it in GitHub Desktop.

Select an option

Save activexray/3ec189d0f0059eb38f7d9fc4fbe11fae to your computer and use it in GitHub Desktop.
AoC 2019 - Day 2
program = [parse(Int64,i) for i in split(readline("2.txt"),',')]
program[2] = 12
program[3] = 2
function runIntcode!(program,offset=1)
# Step 1 - Get opcode
opcode = program[offset]
if opcode == 1
# Add routine
program[program[offset+3]+1] = program[program[offset+1]+1] + program[program[offset+2]+1]
elseif opcode == 2
# Multiply routine
program[program[offset+3]+1] = program[program[offset+1]+1] * program[program[offset+2]+1]
elseif opcode == 99
return
end
runIntcode!(program,offset+4)
end
runIntcode!(program)
@show program[1]
# Part 2
target = 19690720
function matchTarget(target)
for i in 0:99, j in 0:99
program = [parse(Int64,i) for i in split(readline("2.txt"),',')]
program[2] = i
program[3] = j
runIntcode!(program)
if program[1] == target
print("Got $(100 * i + j)")
end
end
end
matchTarget(target)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment