From b98722582b4618f1e896ef95eaef137c397ab3b3 Mon Sep 17 00:00:00 2001 From: Felix Van der Jeugt Date: Thu, 2 Dec 2021 08:21:18 +0100 Subject: [PATCH] day 2 --- Day02/Part1.lua | 14 + Day02/Part2.lua | 15 + inputs/02.long | 1000 +++++++++++++++++++++++++++++++++++++++++++++++ inputs/02.short | 6 + 4 files changed, 1035 insertions(+) create mode 100644 Day02/Part1.lua create mode 100644 Day02/Part2.lua create mode 100644 inputs/02.long create mode 100644 inputs/02.short diff --git a/Day02/Part1.lua b/Day02/Part1.lua new file mode 100644 index 0000000..2ab294b --- /dev/null +++ b/Day02/Part1.lua @@ -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) diff --git a/Day02/Part2.lua b/Day02/Part2.lua new file mode 100644 index 0000000..312bcba --- /dev/null +++ b/Day02/Part2.lua @@ -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) diff --git a/inputs/02.long b/inputs/02.long new file mode 100644 index 0000000..cde6bfc --- /dev/null +++ b/inputs/02.long @@ -0,0 +1,1000 @@ +forward 5 +down 9 +forward 2 +up 2 +forward 4 +forward 4 +up 5 +down 3 +forward 2 +forward 9 +down 7 +forward 2 +down 2 +forward 1 +up 9 +forward 1 +forward 4 +up 5 +down 9 +forward 8 +forward 3 +up 1 +down 2 +down 3 +forward 7 +forward 2 +up 3 +forward 9 +forward 9 +down 3 +up 8 +forward 5 +forward 7 +forward 2 +down 7 +forward 5 +down 4 +up 7 +forward 8 +forward 1 +down 3 +down 1 +forward 6 +up 7 +forward 6 +down 3 +forward 9 +forward 6 +up 3 +down 1 +forward 8 +up 7 +down 9 +down 2 +down 1 +down 5 +forward 4 +down 8 +forward 2 +down 5 +down 6 +down 5 +forward 5 +down 8 +up 8 +forward 3 +forward 4 +forward 8 +forward 9 +down 2 +forward 7 +forward 3 +forward 9 +down 3 +up 1 +down 5 +forward 2 +down 9 +down 2 +down 5 +down 2 +down 9 +up 3 +forward 6 +up 9 +down 1 +forward 8 +up 6 +down 1 +forward 1 +up 1 +forward 3 +down 8 +down 1 +down 9 +forward 4 +forward 1 +down 3 +forward 8 +down 9 +forward 7 +up 6 +down 8 +down 6 +down 8 +down 7 +down 1 +down 8 +down 1 +forward 5 +down 9 +forward 4 +down 2 +forward 8 +up 1 +forward 7 +down 7 +down 6 +forward 4 +forward 6 +down 2 +down 2 +up 7 +down 2 +up 9 +forward 6 +forward 3 +down 8 +forward 9 +down 9 +down 9 +down 8 +forward 2 +forward 5 +forward 8 +forward 1 +down 3 +forward 1 +forward 2 +forward 9 +up 5 +forward 4 +forward 2 +down 6 +forward 3 +forward 7 +forward 1 +forward 8 +down 7 +forward 4 +up 3 +down 9 +up 2 +forward 2 +forward 7 +down 9 +up 9 +forward 9 +up 8 +up 7 +down 8 +down 9 +forward 1 +forward 5 +up 7 +down 3 +up 9 +forward 9 +down 4 +down 7 +down 7 +down 1 +down 4 +down 5 +up 2 +forward 2 +forward 2 +forward 6 +down 7 +forward 7 +down 5 +forward 8 +down 7 +forward 6 +down 2 +up 2 +down 5 +down 1 +up 4 +down 8 +up 9 +forward 1 +down 9 +down 6 +down 8 +up 7 +up 1 +forward 7 +down 8 +forward 1 +down 4 +down 2 +forward 3 +forward 6 +forward 8 +down 2 +forward 7 +forward 8 +up 3 +down 1 +down 8 +up 3 +down 4 +down 5 +forward 6 +forward 9 +down 3 +up 2 +down 9 +up 2 +down 3 +down 9 +forward 4 +forward 6 +down 7 +down 8 +down 4 +forward 7 +up 2 +down 5 +up 3 +down 5 +up 1 +up 1 +forward 5 +forward 9 +down 9 +up 4 +up 4 +up 8 +up 5 +forward 7 +forward 6 +up 6 +down 5 +forward 4 +forward 3 +up 6 +down 6 +forward 5 +up 6 +up 7 +forward 1 +forward 2 +forward 5 +down 3 +forward 6 +down 6 +down 3 +up 9 +down 4 +down 5 +down 4 +forward 1 +down 1 +forward 3 +up 4 +forward 1 +forward 5 +up 3 +forward 6 +forward 5 +forward 9 +forward 6 +down 2 +forward 2 +down 1 +down 4 +forward 6 +forward 8 +down 8 +up 5 +forward 8 +forward 3 +forward 1 +forward 3 +forward 6 +down 1 +down 9 +up 7 +down 2 +forward 6 +down 4 +down 7 +down 5 +forward 2 +down 1 +forward 2 +forward 8 +forward 4 +up 3 +down 1 +forward 6 +forward 3 +down 3 +down 9 +forward 1 +up 5 +forward 3 +forward 3 +up 5 +down 7 +forward 8 +up 5 +forward 2 +forward 2 +down 6 +up 8 +up 5 +forward 2 +forward 1 +down 9 +forward 7 +down 5 +forward 3 +down 3 +down 5 +down 5 +up 7 +down 8 +forward 2 +forward 4 +forward 5 +forward 1 +down 6 +forward 3 +down 1 +down 7 +forward 3 +forward 7 +down 5 +down 3 +forward 6 +down 3 +down 2 +down 4 +down 9 +forward 7 +down 2 +up 2 +up 6 +up 9 +up 8 +forward 9 +down 1 +forward 4 +forward 2 +forward 7 +forward 2 +down 8 +down 3 +forward 4 +forward 6 +down 8 +forward 7 +forward 6 +up 3 +down 6 +down 1 +down 3 +down 8 +down 2 +down 7 +down 9 +forward 4 +forward 7 +forward 8 +forward 5 +forward 9 +up 5 +down 2 +forward 9 +forward 6 +up 6 +forward 7 +down 2 +down 3 +forward 4 +down 6 +down 1 +down 2 +down 8 +forward 3 +down 3 +forward 3 +down 5 +up 8 +down 5 +forward 8 +down 1 +forward 1 +forward 4 +forward 7 +down 2 +down 5 +forward 5 +down 8 +forward 2 +down 2 +forward 5 +forward 6 +forward 4 +down 7 +up 7 +down 1 +forward 7 +forward 8 +down 6 +up 7 +forward 6 +up 6 +down 8 +forward 5 +forward 8 +up 4 +up 2 +up 1 +down 8 +down 6 +up 2 +down 5 +down 1 +forward 5 +forward 7 +down 2 +up 3 +up 3 +forward 9 +down 1 +forward 6 +down 2 +forward 2 +down 1 +down 9 +forward 7 +down 5 +down 8 +up 1 +forward 1 +down 7 +forward 3 +down 4 +up 4 +down 6 +forward 1 +forward 3 +down 2 +forward 3 +forward 5 +forward 6 +up 2 +up 9 +forward 4 +down 4 +up 1 +up 3 +forward 8 +forward 1 +down 9 +down 9 +forward 2 +down 1 +up 9 +up 3 +up 1 +up 5 +forward 6 +down 9 +forward 6 +forward 9 +forward 6 +forward 4 +up 2 +down 6 +up 3 +forward 3 +forward 1 +up 4 +forward 7 +down 9 +down 3 +forward 9 +down 4 +down 8 +down 3 +up 8 +down 8 +down 8 +forward 2 +forward 8 +up 9 +forward 2 +up 6 +forward 7 +down 1 +forward 5 +forward 4 +forward 1 +forward 7 +up 9 +down 8 +forward 1 +up 5 +forward 9 +forward 2 +forward 8 +down 1 +forward 7 +down 2 +up 8 +down 6 +up 9 +up 3 +down 6 +forward 5 +down 1 +forward 1 +forward 6 +forward 6 +up 1 +forward 5 +forward 1 +up 2 +forward 9 +forward 6 +down 3 +up 1 +forward 7 +forward 2 +down 1 +forward 6 +down 3 +up 2 +down 3 +down 8 +forward 4 +down 2 +up 7 +down 6 +up 5 +down 7 +forward 4 +down 9 +down 3 +forward 2 +up 5 +up 4 +forward 9 +down 1 +up 2 +forward 4 +down 9 +down 8 +forward 5 +forward 2 +down 5 +forward 6 +down 4 +forward 7 +forward 1 +forward 6 +down 3 +down 9 +forward 9 +forward 2 +forward 6 +down 7 +down 5 +down 3 +forward 7 +down 3 +down 3 +down 4 +down 4 +down 7 +down 7 +down 7 +up 7 +up 9 +up 7 +up 3 +up 4 +down 9 +down 4 +up 3 +forward 2 +up 1 +down 9 +down 6 +up 1 +up 2 +down 7 +down 9 +up 2 +forward 7 +down 4 +forward 3 +down 1 +down 7 +forward 7 +up 7 +forward 3 +forward 1 +forward 6 +forward 2 +down 9 +forward 8 +up 8 +down 8 +down 9 +up 1 +down 4 +down 6 +down 8 +up 4 +down 1 +forward 1 +forward 1 +forward 4 +forward 7 +forward 1 +down 4 +forward 5 +up 3 +forward 4 +down 5 +down 1 +up 2 +down 7 +forward 7 +down 7 +up 9 +down 9 +down 3 +up 2 +up 8 +up 8 +up 7 +forward 7 +forward 5 +forward 3 +forward 2 +down 5 +forward 4 +forward 1 +down 6 +down 1 +forward 8 +down 6 +down 3 +down 5 +down 9 +down 3 +forward 7 +forward 6 +down 6 +forward 9 +up 7 +forward 3 +up 5 +down 5 +down 5 +forward 4 +up 6 +down 6 +forward 3 +up 2 +forward 4 +up 1 +down 5 +forward 6 +forward 9 +down 2 +up 2 +down 2 +up 7 +forward 3 +up 2 +forward 9 +forward 5 +down 5 +down 7 +down 8 +down 6 +up 9 +up 5 +forward 7 +down 8 +down 1 +forward 7 +up 2 +forward 4 +forward 2 +up 9 +down 8 +forward 1 +forward 7 +down 2 +down 3 +down 6 +down 3 +forward 1 +up 6 +forward 8 +down 9 +down 9 +forward 8 +up 8 +down 6 +forward 4 +up 1 +forward 5 +down 3 +down 7 +down 7 +down 3 +up 2 +forward 4 +down 9 +forward 2 +down 9 +forward 9 +forward 4 +forward 5 +down 4 +forward 1 +up 1 +forward 4 +up 3 +up 4 +forward 7 +down 9 +forward 6 +down 1 +down 1 +down 2 +down 4 +forward 7 +forward 8 +forward 6 +down 8 +forward 2 +down 3 +up 5 +forward 2 +up 5 +forward 8 +down 8 +down 8 +up 8 +forward 6 +up 1 +down 3 +forward 6 +down 1 +forward 9 +up 1 +forward 7 +forward 7 +down 1 +forward 5 +forward 2 +up 7 +down 1 +forward 2 +down 4 +forward 3 +down 9 +forward 6 +up 5 +forward 1 +forward 5 +down 7 +forward 6 +down 8 +forward 9 +down 1 +forward 9 +down 1 +forward 5 +up 9 +forward 1 +forward 6 +forward 5 +down 7 +down 6 +down 5 +down 9 +forward 9 +down 2 +down 8 +down 8 +forward 2 +forward 3 +forward 3 +down 3 +forward 8 +forward 8 +down 8 +forward 1 +up 1 +forward 4 +down 7 +forward 1 +up 2 +forward 9 +forward 1 +down 6 +up 9 +down 3 +down 1 +up 1 +up 6 +up 7 +forward 9 +up 2 +forward 4 +up 8 +down 6 +forward 3 +forward 7 +down 6 +down 5 +down 3 +forward 5 +down 1 +forward 2 +forward 9 +down 8 +up 6 +forward 3 +forward 2 +up 7 +down 3 +forward 5 +forward 9 +down 5 +down 1 +up 4 +down 8 +forward 1 +forward 3 +forward 3 +down 2 +forward 5 +down 1 +forward 2 +up 3 +forward 8 +down 2 +up 8 +down 6 +down 8 +forward 4 +down 4 +up 7 +up 6 +down 7 +forward 2 +up 3 +forward 3 +down 8 +forward 8 +down 5 +forward 5 +down 3 +up 7 +down 1 +down 2 +up 8 +down 6 +up 6 +down 7 +forward 5 +up 3 +forward 7 +forward 2 +down 9 +down 1 +down 4 +down 7 +forward 9 +up 7 +forward 5 +up 8 +forward 8 +up 1 +forward 2 +down 7 +down 5 +down 6 +down 4 +up 4 +forward 5 +forward 6 +up 4 +forward 8 +forward 4 +forward 3 +up 5 +down 6 +up 4 +forward 8 +down 7 +forward 3 +down 2 +down 7 +down 5 +down 4 +forward 5 +up 4 +forward 4 +down 7 +down 3 +down 9 +down 7 +forward 2 +forward 1 +down 7 +down 8 +forward 1 +forward 2 +down 5 +up 1 +down 1 +forward 5 +down 2 +forward 9 +forward 7 +down 2 +forward 6 +forward 9 +up 5 +forward 3 +up 5 +forward 7 +down 6 +down 3 +up 3 +down 4 +forward 2 +up 4 +forward 5 +up 9 +down 3 +up 1 +down 1 +up 3 +forward 4 +forward 5 +down 3 +forward 5 +down 6 +down 2 +forward 5 +forward 3 +down 7 +down 8 +forward 4 +down 5 +forward 7 +forward 2 +forward 7 +down 7 +up 1 +forward 6 +down 1 +forward 1 +down 4 +forward 1 +up 6 +forward 8 +forward 6 +forward 7 +up 6 +up 7 +up 2 +down 9 +forward 4 +up 3 +down 1 +down 1 +forward 3 +down 4 +down 6 +down 8 +forward 9 +forward 6 +down 1 +forward 5 \ No newline at end of file diff --git a/inputs/02.short b/inputs/02.short new file mode 100644 index 0000000..b7172ac --- /dev/null +++ b/inputs/02.short @@ -0,0 +1,6 @@ +forward 5 +down 5 +forward 8 +up 3 +down 8 +forward 2