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!

32 Upvotes

580 comments sorted by

View all comments

Show parent comment

1

u/i_have_no_biscuits Dec 14 '20

Interesting to see lots of people using yield in different ways -- my logic was very similar to yours except I'd already converted my addresses to numbers so some bit-twiddling was involved!

def allfloats(base, fl):
    if fl:
        yield from allfloats(base & ~(1<<fl[0]), fl[1:])
        yield from allfloats(base |  (1<<fl[0]), fl[1:])
    else:
        yield base

I'm getting to be a big fan of 'yield' and 'yield from'.

1

u/mebeim Dec 14 '20

These yield from solutions are truly beautiful, but in the end I used itertools.product() just because it's faster.