-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday2.2.lua
40 lines (35 loc) · 869 Bytes
/
day2.2.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require("intcode")
input = io.input(arg[1])
output = io.output()
-- Read the input into a data table
output:write("Reading the input into data")
data = {}
dIndex = 0
while true do
local opcode = input:read("n")
input:seek("cur", 2) -- Skip the separators
if opcode == nil then -- If we didn't get an opcode, we're at the end of the input
break
else
data[dIndex] = opcode
dIndex = dIndex + 1
output:write(".")
end
end
output:write("\n")
-- Process
output:write("Processing")
targetValue = 19690720
for noun = 0, 99 do
for verb = 0, 99 do
local dataCopy = {}
table.move(data, 0, #data, 0, dataCopy)
dataCopy[1] = noun
dataCopy[2] = verb
local result = intcode(dataCopy)
output:write("\n" .. noun .. "," .. verb .. " (" .. (100 * noun + verb) .. ")'s result was " .. result[0])
if result[0] == targetValue then
return
end
end
end