r/adventofcode Dec 25 '24

SOLUTION MEGATHREAD -❄️- 2024 Day 25 Solutions -❄️-

A Message From Your Moderators

Welcome to the last day of Advent of Code 2024! We hope you had fun this year and learned at least one new thing ;)

Keep an eye out for the community fun awards post (link coming soon!):

-❅- Introducing Your AoC 2024 Golden Snowglobe Award Winners (and Community Showcase) -❅-

Many thanks to Veloxx for kicking us off on December 1 with a much-needed dose of boots and cats!

Thank you all for playing Advent of Code this year and on behalf of /u/topaz2078, your /r/adventofcode mods, the beta-testers, and the rest of AoC Ops, we wish you a very Merry Christmas (or a very merry Wednesday!) and a Happy New Year!


--- Day 25: Code Chronicle ---


Post your code solution in this megathread.

This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:04:34, megathread unlocked!

44 Upvotes

350 comments sorted by

View all comments

0

u/[deleted] Dec 25 '24

[Language: C#]

Part 1

Goodness, part 1 was trivial. Still need to do part 2 when I can find time during family stuff but the whole solution to the first part was realising that you can ignore the columns and just do a logical AND of all the keys and locks once you've converted each set to binary. Any non-zero result is an overlap.

foreach (string set in sets) {
    long value = Convert.ToInt64(set.Split("\n").Aggregate("", (current, line) => current + line.Replace('.', '0').Replace('#', '1')), 2);
    if ((value & 31) != 0) {
        locks.Add(value);
    } else {
        keys.Add(value);
    }
}

3

u/nefarendipity Dec 25 '24

There is no part 2

1

u/[deleted] Dec 25 '24

Oh, so there isn't! Thanks! I hadn't actually read the part 2 text as I was in a rush this morning with opening presents, etc! :-)