This commit is contained in:
2024-12-28 14:24:10 -06:00
parent 969215f3fa
commit 1b949772c2
2 changed files with 13 additions and 8 deletions

View File

@@ -14,8 +14,9 @@ namespace {
auto suffixed(std::uint64_t x, std::uint64_t y) -> std::optional<std::uint64_t>
{
while (x > 0 && x % 10 != y % 10) {
while (x > 0) {
if (y == 0) { return x; }
if (x % 10 != y % 10) return std::nullopt;
x /= 10;
y /= 10;
}
@@ -53,14 +54,16 @@ auto check(bool const part2, std::uint64_t const target, std::vector<std::uint64
} // namespace
auto Main(std::istream & in, std::ostream & out) -> void
{
std::vector<boost::tuple<std::uint64_t, std::vector<std::uint64_t>>> input;
aocpp::ParseSimple(in, *(qi::ulong_long >> ':' >> *(' ' >> qi::ulong_long) >> '\n'), input);
{
auto const input =
aocpp::ParseSimple
<std::vector<boost::tuple<std::uint64_t, std::vector<std::uint64_t>>>>
(in, *(qi::ulong_long >> ':' >> *(' ' >> qi::ulong_long) >> '\n'));
std::uint64_t p1{}, p2{};
for (auto && [x, xs] : input) {
if (check(false, x, xs)) p1 += x;
if (check(true, x, xs)) p2 += x;
if (check(true, x, xs)) p2 += x;
}
out << "Part 1: " << p1 << "\n"