2020 day 1
This commit is contained in:
parent
edfb942e89
commit
8584d36762
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/env lua
|
||||
-- I'm feeling lazy.
|
||||
local numbers = {}
|
||||
|
||||
for line in io.lines() do
|
||||
table.insert(numbers, tonumber(line))
|
||||
end
|
||||
|
||||
local function part1()
|
||||
for _, x in ipairs(numbers) do
|
||||
for _, y in ipairs(numbers) do
|
||||
if x + y == 2020 then
|
||||
return x * y
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function part2()
|
||||
for _, x in ipairs(numbers) do
|
||||
for _, y in ipairs(numbers) do
|
||||
for _, z in ipairs(numbers) do
|
||||
if x + y + z == 2020 then
|
||||
return x * y * z
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
print(part1())
|
||||
print(part2())
|
Loading…
Reference in New Issue