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:
32
2021/puzzle-08-01.cc
Normal file
32
2021/puzzle-08-01.cc
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user