#include namespace views = std::views; namespace ranges = std::ranges; auto parse_input(std::istream& is) { const std::string input = { std::istreambuf_iterator(is), std::istreambuf_iterator() }; auto lines = views::split(input, '\n') | views::filter([](auto line) { return not line.empty(); }); std::vector document; for (auto const line : lines) { char direction = line[0]; std::string out; ranges::copy(line | views::drop(1), std::back_inserter(out)); int length = std::stoi(out); document.push_back(direction == 'R' ? length : -length); } return document; } int const DIAL_MAX = 100; void part1(auto const& input) { // Write first part solution here int answer = 0; int dial = 50; for (auto const offset : input) { dial += offset; dial %= DIAL_MAX; if (dial == 0) { ++answer; } } std::println("{}", answer); } void part2(auto const& input) { // Write second part solution here int answer = 0; int dial = 50; int sign = 1; for (auto const offset : input) { int old_dial = dial; dial += offset; answer += std::abs(dial / DIAL_MAX); if (old_dial * dial < 0 or dial == 0) { ++answer; } dial %= DIAL_MAX; old_dial = dial; std::cerr << answer << ' ' << dial << '\n'; } std::println("{}", answer); } int main() { auto const input = parse_input(std::cin); part1(input); part2(input); return 0; }