day-02.jl (925B)
1 function computer(input, noun, verb) 2 input = copy(input) 3 input[2] = noun 4 input[3] = verb 5 pc = 1 6 while true 7 if input[pc] == 1 8 input[input[pc + 3] + 1] = input[input[pc + 1] + 1] + input[input[pc + 2] + 1] 9 pc += 4 10 elseif input[pc] == 2 11 input[input[pc + 3] + 1] = input[input[pc + 1] + 1] * input[input[pc + 2] + 1] 12 pc += 4 13 elseif input[pc] == 99 14 break 15 end 16 end 17 input[1] 18 end 19 20 function part_1(input) 21 computer(input, 12, 2) 22 end 23 24 function part_2(input) 25 for noun = 0:99 26 for verb = 0:99 27 if computer(input, noun, verb) == 19690720 28 return noun * 100 + verb 29 end 30 end 31 end 32 0 33 end 34 35 input = map(x -> parse(Int32, x), split(readlines(open("input.txt"))[1], ',')) 36 37 println("Julia:") 38 println("Part 1: ", part_1(input)) 39 println("Part 2: ", part_2(input))