1
0
Fork 0

2020 day 3

This commit is contained in:
Lucidiot 2020-12-07 01:39:26 +01:00
parent cbdecb235e
commit 2543ec7db3
Signed by: lucidiot
GPG Key ID: 3358C1CA6906FB8D
2 changed files with 25 additions and 1 deletions

24
2020/3/day3.lua Normal file
View File

@ -0,0 +1,24 @@
local lines = {}
for line in io.lines() do
table.insert(lines, line)
end
local function count_trees(right, down)
right = right or 1
down = down or 1
local count, iteration = 0, 1
for index = 1,#lines,down do
local pos = ((iteration - 1) * right) % lines[index]:len() + 1
if lines[index]:sub(pos, pos) == "#" then
count = count + 1
end
iteration = iteration + 1
end
return count
end
local part1 = count_trees(3)
local part2 = count_trees() * part1 * count_trees(5) * count_trees(7) * count_trees(1, 2)
print(part1)
print(part2)

View File

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