2020 day 3
This commit is contained in:
parent
cbdecb235e
commit
2543ec7db3
|
@ -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)
|
Loading…
Reference in New Issue