diff --git a/cpp/.gitignore b/cpp/.gitignore new file mode 100644 index 0000000..44d4a10 --- /dev/null +++ b/cpp/.gitignore @@ -0,0 +1 @@ +problem \ No newline at end of file diff --git a/cpp/2015/1/problem.cpp b/cpp/2015/1/problem.cpp new file mode 100644 index 0000000..c33b548 --- /dev/null +++ b/cpp/2015/1/problem.cpp @@ -0,0 +1,31 @@ +#include +#include +#include + +int main() { + std::ifstream input_file ("../data/2015/1/input.txt"); + + int floor = 0; + while(input_file) { + char c = input_file.get(); + if (c == '(') floor++; + else if (c == ')') floor--; + } + + std::cout << "Part 1: " << floor << "\n"; + + input_file.clear(); + input_file.seekg(0); + + floor = 0; + int steps = 0; + while(input_file) { + char c = input_file.get(); + if (c == '(') floor++; + else if (c == ')') floor--; + steps++; + if (floor < 0) break; + } + + std::cout << "Part 2: " << steps << "\n"; +} diff --git a/cpp/bin/run b/cpp/bin/run new file mode 100755 index 0000000..2b9ad80 --- /dev/null +++ b/cpp/bin/run @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +year=$1 +day=$2 + +g++ -o $year/$day/problem $year/$day/problem.cpp && time ./$year/$day/problem