adventofcode-2021/day02/part2.lua
Felix Van der Jeugt 3db67bd012
get rid of capitals
2021-12-03 08:04:04 +01:00

16 lines
382 B
Lua

local position, depth, aim = 0, 0, 0
for line in io.lines(arg[3]) do
local split = line:find(" ")
local direction = line:sub(1, split - 1)
local value = line:sub(split + 1, -1)
if direction == "forward" then
position = position + value
depth = depth + aim * value
elseif direction == "up" then
aim = aim - value
else
aim = aim + value
end
end
print(depth * position)