summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroy <[email protected]>2026-06-12 15:58:04 +0300
committerroy <[email protected]>2026-06-12 15:58:04 +0300
commitb4470c5718736e75377791994dc25736bac7dc13 (patch)
tree0c1ff7863e7c1b7c7781319eab814f5233ff83d7
Initial commit
-rw-r--r--.gitignore1
-rw-r--r--CMakeLists.txt8
-rw-r--r--aoc.h4
-rw-r--r--main.cpp9
-rw-r--r--years/2015.cpp81
5 files changed, 103 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..567609b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+build/
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..74be9f5
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.20)
+project(aoc)
+set(CMAKE_CXX_STANDARD 17)
+
+add_executable(aoc
+ main.cpp
+ years/2015.cpp
+)
diff --git a/aoc.h b/aoc.h
new file mode 100644
index 0000000..b97be22
--- /dev/null
+++ b/aoc.h
@@ -0,0 +1,4 @@
+int y2015_q01_p01();
+int y2015_q01_p02();
+int y2015_q02_p01();
+int y2015_q02_p02();
diff --git a/main.cpp b/main.cpp
new file mode 100644
index 0000000..e99c444
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,9 @@
+#include "aoc.h"
+#include <iostream>
+
+int main() {
+
+ std::cout << y2015_q02_p02();
+
+ return 0;
+}
diff --git a/years/2015.cpp b/years/2015.cpp
new file mode 100644
index 0000000..67fe1a6
--- /dev/null
+++ b/years/2015.cpp
@@ -0,0 +1,81 @@
+#include "../aoc.h"
+#include <iostream>
+#include <sstream>
+#include <vector>
+
+int y2015_q01_p01(std::string instructions) {
+ int floor = 0;
+
+ for (const char &c : instructions) {
+ floor += c == '(' ? 1 : -1;
+ }
+
+ return floor;
+}
+
+int y2015_q01_p02(std::string instructions) {
+ int floor = 0;
+
+ for (std::size_t i = 0; i < instructions.size(); i++) {
+ floor += instructions[i] == '(' ? 1 : -1;
+ if (floor == -1)
+ return i + 1;
+ }
+
+ return -1;
+}
+
+std::vector<std::string> splitstring(std::string input, char splitter) {
+ std::stringstream splitterstream(input);
+ std::string segment;
+ std::vector<std::string> splatstring;
+
+ while (std::getline(splitterstream, segment, splitter)) {
+ splatstring.push_back(segment);
+ }
+
+ return splatstring;
+}
+
+int y2015_q02_p01_instance(int l, int w, int h) {
+ return std::min(l * w, std::min(l * h, h * w)) + 2 * l * w + 2 * l * h +
+ 2 * w * h;
+}
+
+int y2015_q02_p01() {
+ int sum = 0;
+
+ std::string input;
+ getline(std::cin, input);
+
+ while (input != "-1") {
+ std::vector<std::string> split = splitstring(input, 'x');
+ sum += y2015_q02_p01_instance(std::stoi(split[0]), std::stoi(split[1]),
+ std::stoi(split[2]));
+
+ getline(std::cin, input);
+ }
+
+ return sum;
+}
+
+int y2015_q02_p02_instance(int l, int w, int h) {
+ return std::min(2 * (l + w), std::min(2 * (l + h), 2 * (w + h))) + l * w * h;
+}
+
+int y2015_q02_p02() {
+ int sum = 0;
+
+ std::string input;
+ getline(std::cin, input);
+
+ while (input != "-1") {
+ std::vector<std::string> split = splitstring(input, 'x');
+ sum += y2015_q02_p02_instance(std::stoi(split[0]), std::stoi(split[1]),
+ std::stoi(split[2]));
+
+ getline(std::cin, input);
+ }
+
+ return sum;
+}