day 2
This commit is contained in:
parent
9a85919a6f
commit
b98722582b
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)
|
1000
inputs/02.long
Normal file
1000
inputs/02.long
Normal file
File diff suppressed because it is too large
Load Diff
6
inputs/02.short
Normal file
6
inputs/02.short
Normal file
@ -0,0 +1,6 @@
|
||||
forward 5
|
||||
down 5
|
||||
forward 8
|
||||
up 3
|
||||
down 8
|
||||
forward 2
|
Loading…
Reference in New Issue
Block a user