Finish day10part1
This commit is contained in:
parent
9169b831a7
commit
ccbbcf413e
4 changed files with 176 additions and 0 deletions
BIN
day10/day10Part1
Executable file
BIN
day10/day10Part1
Executable file
Binary file not shown.
88
day10/day10Part1.cpp
Normal file
88
day10/day10Part1.cpp
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int illegalPoints = 0;
|
||||||
|
|
||||||
|
void filterFunction(string rawInput)
|
||||||
|
{
|
||||||
|
vector<char> 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;
|
||||||
|
}
|
88
day10/day10Part2.cpp
Normal file
88
day10/day10Part2.cpp
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int illegalPoints = 0;
|
||||||
|
|
||||||
|
void filterFunction(string rawInput)
|
||||||
|
{
|
||||||
|
vector<char> 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;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue