0102030405

Advent of Code

2025/3

Lobby

in C#

by encse

You descend a short staircase, enter the surprisingly vast lobby, and are quickly cleared by the security checkpoint. When you get to the main elevators, however, you discover that each one has a red light above it: they're all offline.

"Sorry about that," an Elf apologizes as she tinkers with a nearby control panel. "Some kind of electrical surge seems to have fried them. I'll try to get them online soon."

Visit the website for the full story and full puzzle description.

namespace AdventOfCode.Y2025.Day03;

using System.Linq;

[ProblemName("Lobby")]
class Solution : Solver {

    public object PartOne(string input) => MaxJoltSum(input, 2);
    public object PartTwo(string input) => MaxJoltSum(input, 12);

    public long MaxJoltSum(string input, int batteryCount) =>
        input.Split("\n").Select(bank => MaxJolt(bank, batteryCount)).Sum();

    long MaxJolt(string bank, int batteryCount) {
        long res = 0L;
        for (; batteryCount > 0; batteryCount--) {
            // jump forward to the highest available digit in the bank, but keep 
            // batteryCount digits in the suffix, so that we can select something 
            // for those remaining batteries as well.
            char jolt = bank[..^(batteryCount - 1)].Max();
            bank = bank[(bank.IndexOf(jolt) + 1)..];
            res = 10 * res + (jolt - '0');
        }
        return res;
    }
}

Please ☆ my repo if you like it!

© 2025 | Advent of Code is a registered trademark in the US | Images provided by Bing and Nano Banana