aboutsummaryrefslogtreecommitdiff
path: root/2021/day02
diff options
context:
space:
mode:
authorjacopograndi <jacopo.grandi@outlook.it>2022-01-06 18:42:22 +0100
committerjacopograndi <jacopo.grandi@outlook.it>2022-01-06 18:42:22 +0100
commit9f7b0cd76272068588d0a7220408f91390c5b583 (patch)
tree49a517f0303c951023554ba6b3fb8cc3d5eb1234 /2021/day02
parent72a3388c042f4812e2db33f6d6a1b757392a18a6 (diff)
moved
Diffstat (limited to '2021/day02')
-rwxr-xr-x2021/day02/day02bin0 -> 47672 bytes
-rw-r--r--2021/day02/day02.cpp50
-rw-r--r--2021/day02/day02_input.txt1000
-rw-r--r--2021/day02/makefile2
4 files changed, 1052 insertions, 0 deletions
diff --git a/2021/day02/day02 b/2021/day02/day02
new file mode 100755
index 0000000..8755c57
--- /dev/null
+++ b/2021/day02/day02
Binary files differ
diff --git a/2021/day02/day02.cpp b/2021/day02/day02.cpp
new file mode 100644
index 0000000..dccb44a
--- /dev/null
+++ b/2021/day02/day02.cpp
@@ -0,0 +1,50 @@
+#include <iostream>
+
+int main (int argc, char *argv[]) {
+ if (argc != 2) return 1;
+
+ int depth = 0;
+ int forward = 0;
+
+ int aim = 0;
+ int aim_depth = 0;
+
+ FILE *f = fopen(argv[1], "r");
+ char c = fgetc(f);
+ std::string command;
+ while (c != EOF) {
+ if (c == '\n') {
+ auto token_space = command.find(" ");
+ if (token_space != std::string::npos) {
+ std::string op = command.substr(0, token_space);
+ int amt = std::stoi(command.substr(token_space+1));
+ if (op == "forward") {
+ forward += amt;
+ aim_depth += aim * amt;
+ }
+ if (op == "down") {
+ depth += amt;
+ aim += amt;
+ }
+ if (op == "up") {
+ depth -= amt;
+ aim -= amt;
+ }
+ }
+ command = "";
+ }
+ else command += c;
+ c = fgetc(f);
+ }
+
+ std::cout << "depth " << depth << ", "
+ << "forward " << forward << ", "
+ << "product " << depth * forward << std::endl;
+
+ std::cout << "using aim: depth " << aim_depth << ", "
+ << "forward " << forward << ", "
+ << "aim " << aim << ", "
+ << "product " << aim_depth * forward << std::endl;
+
+ return 0;
+}
diff --git a/2021/day02/day02_input.txt b/2021/day02/day02_input.txt
new file mode 100644
index 0000000..7834464
--- /dev/null
+++ b/2021/day02/day02_input.txt
@@ -0,0 +1,1000 @@
+forward 8
+forward 9
+forward 9
+down 3
+forward 9
+down 1
+down 7
+down 7
+down 4
+down 2
+down 6
+down 6
+down 2
+forward 6
+forward 6
+forward 2
+forward 2
+forward 7
+forward 6
+up 6
+up 8
+forward 5
+forward 4
+down 6
+forward 7
+down 5
+forward 5
+down 8
+down 8
+down 7
+forward 4
+down 2
+forward 7
+up 8
+forward 3
+down 2
+forward 1
+up 3
+forward 3
+up 1
+down 3
+up 7
+up 2
+down 4
+down 2
+forward 9
+forward 3
+down 8
+forward 5
+up 9
+up 4
+forward 9
+down 1
+forward 6
+down 3
+forward 8
+up 2
+forward 3
+up 7
+down 4
+forward 2
+forward 7
+forward 3
+down 1
+down 3
+up 5
+forward 6
+down 5
+down 4
+down 8
+down 2
+up 5
+forward 7
+up 8
+forward 2
+down 5
+forward 3
+up 1
+up 5
+down 8
+down 3
+forward 4
+forward 4
+forward 1
+up 8
+down 9
+forward 7
+forward 9
+down 5
+up 3
+down 9
+up 6
+forward 1
+forward 3
+forward 5
+down 5
+forward 6
+down 3
+down 8
+forward 3
+forward 5
+forward 7
+forward 6
+down 9
+down 5
+down 6
+down 5
+down 1
+down 8
+forward 3
+down 9
+down 5
+down 5
+forward 9
+forward 2
+down 7
+forward 9
+forward 9
+up 1
+forward 3
+up 9
+forward 5
+forward 7
+down 7
+forward 2
+up 8
+up 6
+down 7
+down 3
+down 5
+down 2
+forward 6
+forward 6
+up 6
+up 2
+forward 4
+forward 7
+forward 1
+down 4
+up 8
+down 3
+up 1
+down 2
+forward 4
+forward 7
+up 1
+down 7
+forward 8
+up 2
+down 8
+up 4
+up 4
+up 2
+down 8
+up 4
+down 6
+up 8
+down 5
+up 5
+down 8
+forward 9
+down 1
+down 5
+forward 3
+forward 3
+up 9
+down 2
+forward 3
+down 6
+forward 1
+forward 9
+forward 3
+down 8
+up 4
+down 1
+down 8
+up 1
+forward 2
+down 7
+up 3
+up 8
+down 2
+up 6
+forward 6
+down 9
+forward 4
+forward 7
+up 9
+forward 3
+forward 2
+down 8
+down 2
+down 5
+down 5
+down 1
+up 7
+down 4
+forward 5
+down 9
+down 5
+down 1
+down 6
+forward 9
+down 6
+forward 3
+down 3
+up 6
+forward 2
+forward 6
+down 2
+down 9
+down 6
+down 1
+down 7
+down 6
+down 6
+up 1
+forward 8
+down 9
+down 6
+down 8
+down 8
+down 6
+down 3
+forward 9
+forward 6
+down 9
+forward 5
+down 6
+down 6
+down 9
+down 7
+down 3
+forward 1
+up 9
+forward 9
+down 7
+forward 4
+down 1
+forward 9
+up 9
+down 7
+forward 5
+down 3
+up 7
+forward 9
+forward 6
+forward 3
+forward 8
+down 4
+down 1
+down 7
+down 7
+up 4
+down 9
+forward 6
+forward 7
+down 8
+forward 2
+forward 2
+forward 9
+forward 6
+forward 9
+up 6
+up 8
+forward 2
+up 3
+forward 9
+forward 1
+down 4
+forward 8
+down 4
+forward 5
+forward 7
+up 2
+forward 5
+down 4
+forward 3
+down 5
+forward 9
+up 3
+forward 8
+down 7
+down 7
+down 9
+forward 2
+down 1
+down 6
+up 8
+down 2
+down 1
+up 3
+down 3
+forward 2
+forward 6
+up 6
+down 3
+up 9
+up 3
+down 8
+up 6
+down 2
+forward 4
+up 1
+down 5
+down 4
+up 9
+up 7
+forward 7
+down 9
+forward 9
+forward 5
+forward 3
+down 4
+up 6
+up 7
+down 7
+down 6
+up 9
+up 4
+down 7
+forward 7
+forward 8
+down 9
+forward 5
+forward 4
+down 5
+forward 8
+forward 5
+up 3
+down 9
+forward 1
+forward 2
+up 3
+down 2
+down 1
+forward 5
+forward 5
+forward 6
+up 2
+forward 3
+down 7
+down 6
+up 3
+down 4
+down 4
+forward 5
+down 3
+up 6
+forward 1
+up 8
+forward 7
+forward 1
+forward 9
+down 2
+up 8
+up 1
+up 4
+forward 9
+forward 3
+forward 5
+down 1
+up 9
+down 1
+forward 3
+down 6
+down 8
+up 4
+forward 6
+up 7
+down 8
+forward 9
+up 2
+down 7
+down 1
+forward 9
+up 7
+forward 3
+forward 9
+forward 1
+forward 1
+down 9
+forward 1
+up 4
+down 5
+forward 4
+down 1
+forward 4
+forward 9
+up 4
+down 3
+down 6
+up 2
+down 6
+down 5
+forward 5
+up 1
+up 9
+forward 8
+up 3
+down 1
+forward 3
+forward 7
+up 6
+up 3
+down 6
+forward 7
+up 6
+down 7
+forward 8
+up 4
+down 8
+up 9
+up 3
+down 3
+forward 8
+down 4
+down 9
+forward 2
+down 7
+up 1
+forward 9
+forward 5
+up 8
+forward 9
+forward 4
+forward 9
+forward 7
+down 4
+up 4
+down 7
+down 4
+down 4
+down 1
+forward 5
+forward 4
+down 1
+down 4
+down 8
+down 3
+forward 7
+forward 4
+down 1
+down 9
+up 3
+forward 2
+down 8
+down 9
+down 2
+down 5
+up 9
+down 9
+up 9
+forward 5
+forward 8
+forward 9
+down 5
+forward 6
+down 8
+down 9
+forward 8
+up 5
+up 9
+up 7
+up 8
+forward 9
+forward 1
+up 6
+down 8
+down 8
+forward 1
+up 1
+forward 8
+forward 6
+down 4
+forward 1
+down 7
+forward 8
+forward 3
+up 3
+down 4
+down 2
+forward 2
+forward 3
+up 4
+down 3
+forward 2
+down 8
+forward 7
+up 3
+down 2
+forward 2
+down 5
+up 6
+up 6
+forward 4
+up 4
+down 8
+forward 8
+down 9
+down 9
+down 6
+down 2
+forward 2
+up 6
+up 5
+forward 3
+forward 3
+up 9
+down 3
+forward 8
+down 5
+forward 5
+forward 7
+down 3
+down 4
+down 1
+down 8
+down 1
+down 1
+forward 9
+forward 3
+down 8
+down 6
+up 9
+forward 1
+forward 5
+up 9
+up 8
+forward 2
+up 8
+down 9
+up 2
+forward 5
+forward 1
+forward 8
+down 3
+forward 4
+down 5
+up 6
+forward 8
+forward 9
+forward 3
+down 1
+down 3
+down 3
+up 4
+forward 9
+down 3
+down 6
+forward 3
+forward 2
+down 6
+down 8
+forward 6
+up 8
+up 3
+up 4
+forward 2
+forward 4
+forward 4
+forward 7
+down 6
+up 8
+down 3
+forward 8
+forward 4
+down 7
+down 5
+forward 6
+forward 4
+forward 6
+down 3
+forward 3
+down 1
+down 7
+forward 3
+forward 2
+forward 7
+down 5
+up 4
+down 6
+down 9
+forward 3
+forward 5
+forward 3
+down 1
+forward 2
+up 5
+up 6
+forward 2
+down 4
+forward 3
+down 4
+down 1
+forward 8
+up 2
+down 3
+down 6
+up 5
+forward 3
+forward 6
+down 3
+forward 1
+down 7
+forward 2
+forward 1
+forward 6
+forward 5
+forward 3
+down 4
+down 8
+forward 1
+up 2
+up 8
+down 4
+forward 9
+up 6
+forward 5
+forward 7
+down 5
+forward 5
+down 1
+forward 4
+forward 5
+up 2
+forward 5
+up 8
+up 1
+forward 2
+down 4
+down 6
+forward 4
+down 2
+down 3
+forward 2
+up 3
+up 4
+forward 2
+down 6
+forward 1
+forward 4
+down 6
+forward 7
+up 2
+forward 7
+forward 6
+up 2
+forward 8
+forward 4
+forward 9
+down 1
+down 8
+forward 3
+forward 2
+down 8
+up 1
+forward 4
+down 8
+forward 2
+forward 8
+up 2
+down 1
+forward 4
+forward 2
+up 4
+up 2
+down 3
+up 8
+forward 3
+up 8
+forward 9
+up 1
+up 5
+down 5
+down 6
+forward 1
+up 5
+up 8
+forward 7
+down 5
+up 4
+forward 2
+up 4
+up 4
+down 2
+forward 6
+forward 2
+down 7
+down 5
+forward 1
+down 2
+down 5
+down 7
+up 8
+down 8
+up 5
+down 1
+forward 5
+down 2
+forward 5
+down 1
+up 7
+up 2
+forward 2
+forward 3
+forward 6
+forward 3
+down 8
+up 8
+forward 8
+forward 1
+forward 7
+up 2
+forward 9
+down 1
+forward 5
+up 9
+forward 3
+forward 7
+forward 8
+up 1
+down 3
+forward 5
+down 2
+forward 6
+forward 3
+down 9
+up 5
+forward 2
+down 4
+up 1
+forward 4
+up 4
+down 8
+down 8
+forward 3
+forward 8
+down 7
+up 3
+forward 1
+up 3
+forward 9
+forward 7
+forward 1
+down 6
+forward 3
+down 1
+down 8
+forward 5
+forward 3
+up 6
+forward 5
+forward 4
+forward 3
+forward 9
+forward 8
+down 6
+down 2
+forward 7
+forward 6
+up 6
+down 6
+down 4
+down 3
+forward 8
+down 9
+up 5
+forward 3
+forward 2
+down 5
+up 4
+down 6
+down 3
+forward 9
+down 2
+forward 9
+forward 8
+up 1
+down 2
+forward 7
+up 5
+up 6
+down 8
+up 9
+up 8
+forward 1
+forward 5
+down 9
+forward 8
+down 8
+up 1
+down 7
+forward 7
+up 3
+down 3
+down 1
+forward 2
+down 3
+forward 9
+forward 2
+down 8
+down 2
+forward 5
+down 9
+down 1
+down 5
+down 6
+up 4
+up 3
+down 1
+up 7
+forward 6
+down 3
+down 6
+up 5
+forward 8
+up 8
+down 1
+down 2
+up 8
+down 7
+forward 7
+forward 4
+down 8
+down 3
+forward 3
+down 4
+forward 3
+down 6
+forward 4
+forward 7
+forward 9
+up 7
+forward 1
+down 7
+down 8
+down 8
+up 6
+down 3
+forward 5
+forward 5
+forward 9
+forward 4
+down 4
+down 8
+down 7
+down 1
+forward 2
+forward 4
+down 3
+down 6
+down 7
+forward 5
+down 8
+down 1
+forward 4
+forward 3
+forward 1
+down 6
+down 7
+down 1
+forward 6
+down 4
+up 2
+forward 4
+down 2
+up 5
+down 2
+down 6
+up 7
+forward 4
+forward 7
+forward 9
+up 5
+down 9
+up 5
+forward 6
+down 2
+up 8
+up 9
+up 9
+forward 5
+down 2
+forward 2
+down 7
+forward 5
+forward 9
+up 8
+down 8
+forward 1
+down 2
+up 3
+forward 3
+down 5
+forward 4
+down 3
+forward 4
+forward 9
+forward 3
+down 5
+forward 4
+down 2
+forward 5
+forward 8
+up 6
+up 2
+down 3
+forward 6
+down 5
+down 4
+down 4
+down 4
+up 2
+up 2
+forward 6
+forward 2
+forward 9
+down 2
+down 9
+down 8
+forward 2
+down 3
+up 3
+forward 5
+down 4
+up 3
+forward 3
+down 1
+forward 7
+forward 5
+forward 6
+down 8
+down 5
+down 5
+down 9
+up 2
+forward 3
+down 4
+down 9
+forward 3
+forward 9
+forward 2
+forward 4
+up 6
+down 6
+up 9
+forward 8
+down 7
+forward 1
+forward 4
+up 1
+up 2
+down 9
+forward 6
+down 6
+down 1
+down 4
+down 7
+down 6
+forward 5
+up 1
+up 7
+down 2
+down 8
+down 2
+down 7
+down 3
+up 9
+down 7
+down 5
+down 6
+forward 9
+up 3
+forward 2
+down 8
+forward 4
+down 6
+forward 3
+up 3
+down 5
+up 4
+forward 6
+forward 7
+forward 9
+down 3
+forward 7
+forward 3
+down 4
+up 4
+down 8
+forward 6
+forward 7
+forward 9
+forward 4
+down 3
+up 5
+down 7
+down 7
+forward 9
diff --git a/2021/day02/makefile b/2021/day02/makefile
new file mode 100644
index 0000000..61ca2f4
--- /dev/null
+++ b/2021/day02/makefile
@@ -0,0 +1,2 @@
+all day02.cpp:
+ g++ -std=c++20 -o day02 day02.cpp