day 2
This commit is contained in:
parent
9a85919a6f
commit
b98722582b
4 changed files with 1035 additions and 0 deletions
14
Day02/Part1.lua
Normal file
14
Day02/Part1.lua
Normal file
|
@ -0,0 +1,14 @@
|
|||
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)
|
15
Day02/Part2.lua
Normal file
15
Day02/Part2.lua
Normal file
|
@ -0,0 +1,15 @@
|
|||
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)
|
Loading…
Add table
Add a link
Reference in a new issue