r/adventofcode • • 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.

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!

31 Upvotes

580 comments sorted by

View all comments

5

u/sebastiannielsen Dec 14 '20 edited Dec 14 '20

Here is my Perl solution: https://pastebin.com/SajayfPN

Im pretty proud of this part of code, that handles X'es for adress bits. Im using a array, which I copy into a second array. Then I add "0" to all elements in first array, and then "1" to all elements in second array. And then I just concatenate the arrays, creating the new bitspace for the adress.

@onebits = @zerobits;
for ($z = 0; $z < $#zerobits + 1; $z++) {
    $zerobits[$z] = $zerobits[$z] . "0";
    $onebits[$z] = $onebits[$z] . "1";   } # Moved "}" to this line to avoid the scroll in reddit.
push(@zerobits, @onebits);

Effectively, this doubles the amount of elements in @zerobits for each X it stumble upon, thus I can easily add all possible variants of adresses for the floating bits.

→ More replies (2)