This commit is contained in:
Felix Van der Jeugt 2021-12-02 08:21:18 +01:00
parent 9a85919a6f
commit b98722582b
No known key found for this signature in database
GPG Key ID: 58B209295023754D
4 changed files with 1035 additions and 0 deletions

14
Day02/Part1.lua Normal file
View 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
View 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

File diff suppressed because it is too large Load Diff

6
inputs/02.short Normal file
View File

@ -0,0 +1,6 @@
forward 5
down 5
forward 8
up 3
down 8
forward 2