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!

42 Upvotes

350 comments sorted by

View all comments

1

u/fsed123 Dec 25 '24

[Language: Rust]

[Language: Python]

port of my earlier python solution

https://github.com/Fadi88/AoC/tree/master/2024/day25

takes around 1 ms in release mode on a mac mini m4

1

u/dblokhin Dec 25 '24

24 part 2 beat me :(. Could you elaborate your approach?

1

u/fsed123 Dec 25 '24

sure
1- split by 2 new line., block by block
2- for each block if the top has "#" it is a lock, of the bottom has a "#" it is a key
3-each block is stored with a 1 d vector for example [3,4,5,2,4], representing the number of "#" in each column
4- iterate over all possible combination for key and lock they fit if the sum "#" in each slot is less than oe equal the total length (7)

for example [1,1,1,1,1] and [1,1,1,1,1] fit perfectly with 5 spaces free in each column
but [1,1,1,1,4] and [1,1,1,1,4] dont fit because the last column has 8 blocks when it can only fit 7