cleanup
This commit is contained in:
15
2024/07.cpp
15
2024/07.cpp
@@ -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"
|
||||
|
Reference in New Issue
Block a user