diff options
-rw-r--r-- | src/2021/day4/aoc.cpp | 7 | ||||
-rw-r--r-- | src/2021/day4/aoc.h | 2 | ||||
-rw-r--r-- | test/test_2021.cpp | 4 |
3 files changed, 8 insertions, 5 deletions
diff --git a/src/2021/day4/aoc.cpp b/src/2021/day4/aoc.cpp index fc18c1e..6212dcd 100644 --- a/src/2021/day4/aoc.cpp +++ b/src/2021/day4/aoc.cpp @@ -78,7 +78,7 @@ struct board { p++; } at = bingo_at(); - //print(); + // print(); } void print() const noexcept { @@ -161,7 +161,7 @@ struct board { } }; -int day4(line_view file) { +std::pair<int, int> day4(line_view file) { const char* p1 = file.line; const char* p2 = file.line + file.length; const char* p = p1; @@ -184,7 +184,8 @@ int day4(line_view file) { // for (auto& b : bs) { // printf("%d, %d\n", b.at.i, b.sum_unmarked(b.at.i) * b.at.v); // } - return bs[0].sum_unmarked(bs[0].at.i) * bs[0].at.v; + auto score = [&bs](int x) { return bs[x].sum_unmarked(bs[x].at.i) * bs[x].at.v; }; + return {score(0), score(bs.size() - 1)}; } } // namespace aoc2021 diff --git a/src/2021/day4/aoc.h b/src/2021/day4/aoc.h index 69a44fb..2e7daf3 100644 --- a/src/2021/day4/aoc.h +++ b/src/2021/day4/aoc.h @@ -3,5 +3,5 @@ namespace aoc2021 { -int day4(line_view); + std::pair<int,int> day4(line_view); } // namespace aoc2021 diff --git a/test/test_2021.cpp b/test/test_2021.cpp index 40cc402..5ec38df 100644 --- a/test/test_2021.cpp +++ b/test/test_2021.cpp @@ -30,5 +30,7 @@ TEST_CASE("Binary Diagnostic", "[2021]") { TEST_CASE("Giant Squid", "[2021]") { line_view lv = load_file("../src/2021/day4/input"); - REQUIRE(5685 == aoc2021::day4(lv)); + auto p = aoc2021::day4(lv); + REQUIRE(5685 == p.first); + REQUIRE(21070 == p.second); } |