summary refs log tree commit diff
path: root/22.10/main.cpp
diff options
context:
space:
mode:
authordzwdz2022-12-10 10:53:53 +0100
committerdzwdz2022-12-10 10:53:53 +0100
commitf9469968b20e597e8698fca3970dcd224fd6a38a (patch)
treea4b35882410083081ec4259c4b4418414fb08106 /22.10/main.cpp
parentc952634ddd6f24b4fd30f52d7b972764ae20d1b3 (diff)
day 10 part 1
Diffstat (limited to '22.10/main.cpp')
-rw-r--r--22.10/main.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/22.10/main.cpp b/22.10/main.cpp
new file mode 100644
index 0000000..4124fc7
--- /dev/null
+++ b/22.10/main.cpp
@@ -0,0 +1,46 @@
+#include <iostream>
+#include <string>
+#include <sstream>
+using namespace std;
+
+class VM
+{
+	int x = 1;
+	int cycles = 0;
+
+	void delay(int amt) {
+		for (int i = 0; i < amt; i++) {
+			cycles++;
+			if (cycles % 40 == 20) {
+				part1 += cycles * x;
+			}
+		}
+	}
+
+public:
+	int part1 = 0;
+
+	void parse(string line) {
+		istringstream stream(line);
+		string cmd;
+		stream >> cmd;
+		if (cmd == "noop") {
+			delay(1);
+		} else if (cmd == "addx") {
+			int d;
+			stream >> d;
+			delay(2);
+			x += d;
+		}
+	}
+};
+
+int
+main()
+{
+	VM vm;
+	for (string line; getline(cin, line); ) {
+		vm.parse(line);
+	}
+	cout << vm.part1 << endl;
+}