diff --git a/day10/day10Part1 b/day10/day10Part1 new file mode 100755 index 0000000..402d92d Binary files /dev/null and b/day10/day10Part1 differ diff --git a/day10/day10Part1.cpp b/day10/day10Part1.cpp new file mode 100644 index 0000000..424aa7e --- /dev/null +++ b/day10/day10Part1.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include +#include + +using namespace std; + +int illegalPoints = 0; + +void filterFunction(string rawInput) +{ + vector currentLine; + currentLine.clear(); + for(int index = 0; index < rawInput.length(); index++) + { + switch (rawInput[index]) + { + case '[': + case '(': + case '{': + case '<': + currentLine.push_back(rawInput[index]); + break; + case ']': + if (currentLine.back() == '[') + { + currentLine.pop_back(); + } + else + { + illegalPoints += 57; + return; + } + break; + case ')': + if (currentLine.back() == '(') + { + currentLine.pop_back(); + } + else + { + illegalPoints += 3; + return; + } + break; + case '}': + if (currentLine.back() == '{') + { + currentLine.pop_back(); + } + else + { + illegalPoints += 1197; + return; + } + break; + case '>': + if (currentLine.back() == '<') + { + currentLine.pop_back(); + } + else + { + illegalPoints += 25137; + return; + } + break; + default: + cout << "Wrong input!" << endl; + cout << rawInput[index] << ", index " << index << endl; + return; + } + } +} + +int main(void) +{ + string rawInput; + ifstream readFile ("data/input.txt", ios::in); + while(getline(readFile, rawInput)) + { + filterFunction(rawInput); + } + cout << "Total points: " << illegalPoints; + return 0; +} diff --git a/day10/day10Part2.cpp b/day10/day10Part2.cpp new file mode 100644 index 0000000..424aa7e --- /dev/null +++ b/day10/day10Part2.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include +#include + +using namespace std; + +int illegalPoints = 0; + +void filterFunction(string rawInput) +{ + vector currentLine; + currentLine.clear(); + for(int index = 0; index < rawInput.length(); index++) + { + switch (rawInput[index]) + { + case '[': + case '(': + case '{': + case '<': + currentLine.push_back(rawInput[index]); + break; + case ']': + if (currentLine.back() == '[') + { + currentLine.pop_back(); + } + else + { + illegalPoints += 57; + return; + } + break; + case ')': + if (currentLine.back() == '(') + { + currentLine.pop_back(); + } + else + { + illegalPoints += 3; + return; + } + break; + case '}': + if (currentLine.back() == '{') + { + currentLine.pop_back(); + } + else + { + illegalPoints += 1197; + return; + } + break; + case '>': + if (currentLine.back() == '<') + { + currentLine.pop_back(); + } + else + { + illegalPoints += 25137; + return; + } + break; + default: + cout << "Wrong input!" << endl; + cout << rawInput[index] << ", index " << index << endl; + return; + } + } +} + +int main(void) +{ + string rawInput; + ifstream readFile ("data/input.txt", ios::in); + while(getline(readFile, rawInput)) + { + filterFunction(rawInput); + } + cout << "Total points: " << illegalPoints; + return 0; +} diff --git a/day10/part1Input.txt b/day10/part1Instructions.txt similarity index 100% rename from day10/part1Input.txt rename to day10/part1Instructions.txt