Add 2021 day 8 puzzles

Part two needs a tidy-up which will come in a bit.

But this is how I got the correct answer.
This commit is contained in:
2021-12-08 09:42:51 +00:00
parent 6448f4c487
commit ceb89e10b7
2 changed files with 182 additions and 0 deletions

32
2021/puzzle-08-01.cc Normal file
View File

@@ -0,0 +1,32 @@
//
// Created by Matthew Gretton-Dann on 08/12/2021.
//
#include <iostream>
#include <string>
auto main() -> int
{
std::string line;
unsigned count{0};
while (std::getline(std::cin, line)) {
line = line.substr(line.find('|') + 1);
unsigned this_digit{0};
for (auto c : line) {
if (c == ' ') {
if (this_digit == 2 || this_digit == 3 || this_digit == 4 || this_digit == 7) {
++count;
}
this_digit = 0;
}
else {
++this_digit;
}
}
if (this_digit == 2 || this_digit == 3 || this_digit == 4 || this_digit == 7) {
++count;
}
}
std::cout << "Simple digits: " << count << '\n';
return 0;
}