diff options
Diffstat (limited to 'src/2022/day25/aoc.cpp')
-rw-r--r-- | src/2022/day25/aoc.cpp | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/2022/day25/aoc.cpp b/src/2022/day25/aoc.cpp index 858f5a1..f15075e 100644 --- a/src/2022/day25/aoc.cpp +++ b/src/2022/day25/aoc.cpp @@ -8,7 +8,7 @@ static int64_t pow(size_t n) { for (size_t i = 0; i < n; i++) { x *= 5; } - return n == 0 ? 0 : x; + return x; } int64_t pow5(size_t n) { @@ -69,12 +69,12 @@ snafu_digit range(size_t n) { int64_t l = m1; for (size_t i = n; i > 0; i--) { - l -= 2 * (i > 1 ? pow5(i - 1) : 1); + l -= 2 * pow5(i - 1); } int64_t h = m2; for (size_t i = n; i > 0; i--) { - h += 2 * (i > 1 ? pow5(i - 1) : 1); + h += 2 * pow5(i - 1); } p.first->second = {l, m1, d1, d2, m2, h}; } @@ -123,22 +123,21 @@ std::string baseSNAFU(int64_t x) { return s; } -std::pair<int64_t, int64_t> day25(line_view file) { +std::pair<std::string, int64_t> day25(line_view file) { std::vector<snafu> ss; per_line(file, [&ss](line_view lv) { ss.emplace_back(lv); return true; }); - // int64_t x{0}; - // for (auto& s : ss) { - // // s.print(); - // // printf(" %ld\n", base10(s)); - // x += base10(s); - // } + int64_t x{0}; + for (auto& s : ss) { + // s.print(); + // printf(" %ld\n", base10(s)); + x += base10(s); + } // printf("%ld %s\n", x, baseSNAFU(x).c_str()); - - return {0, 0}; + return {baseSNAFU(x), 0}; } } // namespace aoc2022 |