2021-12-05 12:17:39 +01:00
|
|
|
#!/usr/bin/env luajit
|
|
|
|
|
2021-12-02 08:21:18 +01:00
|
|
|
local position, depth = 0, 0
|
|
|
|
for line in io.lines(arg[3]) do
|
|
|
|
local split = line:find(" ")
|
|
|
|
local direction = line:sub(1, split - 1)
|
|
|
|
local distance = line:sub(split + 1, -1)
|
|
|
|
if direction == "forward" then
|
|
|
|
position = position + distance
|
|
|
|
elseif direction == "up" then
|
|
|
|
depth = depth - distance
|
|
|
|
else
|
|
|
|
depth = depth + distance
|
|
|
|
end
|
|
|
|
end
|
|
|
|
print(depth * position)
|