auto solve = [](grid2d const& grid) -> std::pair<int, u64> { std::flat_map<int, u64> beam_counts, next_beam_counts; beam_counts[flux::find(grid.data, 'S')] = 1; int split_count = 0; for (int row : flux::iota(1, grid.height)) { for (auto [col, count] : beam_counts) { if (grid[col, row] == '^') { next_beam_counts[col - 1] += count; next_beam_counts[col + 1] += count; ++split_count; } else { next_beam_counts[col] += count; } } std::swap(beam_counts, next_beam_counts); next_beam_counts.clear(); } return {split_count, flux::sum(beam_counts.values())}; };
Nothing particularly fancy for today's #AdventOfCode, but it did give me an excuse to use C++23's std::flat_map for the first time
Github: github.com/tcbrindle/ad...