// // Created by Matthew Gretton-Dann on 01/12/2022. // #include #include #include #include #include #include #include using Int = std::int64_t; using UInt = std::uint64_t; using Point = std::pair; auto main() -> int { std::string line; if (!std::getline(std::cin, line)) { std::cerr << "Unable to read line.\n"; return EXIT_FAILURE; } UInt const rounds{std::stoull(line)}; std::vector scores; scores.push_back(3); scores.push_back(7); UInt elf1_pos{0}; UInt elf2_pos{1}; while (scores.size() < rounds + 10) { uint8_t const new_score{static_cast(scores[elf1_pos] + scores[elf2_pos])}; assert(new_score < 100); if (new_score >= 10) { scores.push_back(new_score / 10); } scores.push_back(new_score % 10); elf1_pos = (elf1_pos + 1 + scores[elf1_pos]) % scores.size(); elf2_pos = (elf2_pos + 1 + scores[elf2_pos]) % scores.size(); } std::cout << "Score: "; for (UInt idx{rounds}; idx < rounds + 10; ++idx) { std::cout << static_cast(scores[idx]); } std::cout << "\n"; }