1
0
Fork 0

2020 day 1

This commit is contained in:
Lucidiot 2020-12-06 23:50:56 +01:00
parent edfb942e89
commit 8584d36762
Signed by: lucidiot
GPG Key ID: 3358C1CA6906FB8D
2 changed files with 34 additions and 2 deletions

32
2020/1/day1.lua Executable file
View File

@ -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())

View File

@ -5,8 +5,8 @@ My solutions to the Advent of Code puzzles.
## Progress
```
15 16 17 18 19
1 ██ ██ ██ ██
15 16 17 18 19 20
1 ██ ██ ██ ██ ██
2 ██ ██ ██ ██
3 ██ ██ ██ ██
4 ██ ██ ██