01020304050607080910111213141516171819202122232425

Advent of Code

2024/25

Code Chronicle

in C#

by encse

Out of ideas and time, The Historians agree that they should go back to check the Chief Historian's office one last time, just in case he went back there without you noticing.

When you get there, you are surprised to discover that the door to his office is locked! You can hear someone inside, but knocking yields no response. The locks on this floor are all fancy, expensive, virtual versions of five-pin tumbler locks, so you contact North Pole security to see if they can help open the door.

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

namespace AdventOfCode.Y2024.Day25;

using System;
using System.Linq;

[ProblemName("Code Chronicle")]
class Solution : Solver {

    public object PartOne(string input) {
        int[] parsePattern(string[] lines) =>
            Enumerable.Range(0, lines[0].Length).Select(x =>
                Enumerable.Range(0, lines.Length).Count(y => lines[y][x] == '#')
            ).ToArray();

        bool match(int[] k, int[] l) =>
            Enumerable.Range(0, k.Length).All(i => k[i] + l[i] <= 7);

        var patterns = input.Split("\n\n").Select(b => b.Split("\n"));
        var keys = patterns.Where(p => p[0][0] == '.').Select(parsePattern).ToList();
        var locks = patterns.Where(p => p[0][0] == '#').Select(parsePattern).ToList();

        return keys.Sum(k => locks.Count(l => match(l, k)));
    }
}

Please ☆ my repo if you like it!

© 2025 Advent of Code is a registered trademark in the US Images provided by Bing image creator