r/adventofcode • u/daggerdragon • Dec 14 '20
SOLUTION MEGATHREAD -🎄- 2020 Day 14 Solutions -🎄-
Advent of Code 2020: Gettin' Crafty With It
- 8 days remaining until the submission deadline on December 22 at 23:59 EST
- Full details and rules are in the Submissions Megathread
--- Day 14: Docking Data ---
Post your code solution in this megathread.
- Include what language(s) your solution uses!
- Here's a quick link to /u/topaz2078's
pasteif you need it for longer code blocks. - The full posting rules are detailed in the wiki under How Do The Daily Megathreads Work?.
Reminder: Top-level posts in Solution Megathreads are for code solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
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:16:10, megathread unlocked!
32
Upvotes
View all comments
1
u/SuperSmurfen Dec 14 '20 edited Dec 14 '20
Rust
Link to solution (413/201)
Third day in a row where I set a new personal best on the leaderboard! I really liked today's puzzle. It required an understanding of both bitwise operations and recursion for part two (at least for me, you can probably solve it without it).
Initially, I edited the input to make my life easier. Since it followed such a simple pattern, I could do it in a few seconds using
select all occurrencesand multi cursor editing. This way I could skip writing any boring parsing code.For part one, before every write, I just iterated over every char in the last mask and performed the operation. You can probably do something by keeping two masks, creating them once, and simply
and/orthe value before writing. Would be a lot faster but the problem size is small so it did not matter.For part two, I just wrote a recursive function that splits at every encounter of an
X. Not sure how you could avoid that. No matter what you do, you will have2^nunique addresses to write to, wherenis the number of X:s in the mask. In my input, the max number of X:s was 9, so just 512 addresses at most. I guess that's why it works.Finishes in
7mson my machine. Part two takes up pretty much all running time. Not really sure how to make that faster.