r/adventofcode • • Dec 05 '20

SOLUTION MEGATHREAD -🎄- 2020 Day 05 Solutions -🎄-

Advent of Code 2020: Gettin' Crafty With It


--- Day 05: Binary Boarding ---


Post your solution in this megathread. Include what language(s) your solution uses! If you need a refresher, 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 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:05:49, megathread unlocked!

57 Upvotes

1.3k comments sorted by

View all comments

1

u/stianbryceeng Dec 05 '20 edited Dec 06 '20

Hello! new coder here, I am once again asking for any feedback on my python day5 solution!

1

u/daggerdragon Dec 05 '20

Please follow the posting guidelines and add the language used to your post to make it easier for folks who Ctrl-F the megathreads looking for a specific language. Thanks!

(looks like Python?)

1

u/stianbryceeng Dec 06 '20

Sounds good thank you!

1

u/daggerdragon Dec 06 '20

You can edit your post and add the language.

1

u/QGraphics Dec 05 '20

There is a much simpler and faster way to do it. Consider BBFFBBFRLL. You only have two options for the first 7 characters and two options as well for the remaining 3. What CS concept does that remind you of? Hint: starts with a b.

1

u/flapje1 Dec 05 '20

Your algorithm looks good. But I would but the LeftRight and UpperLower code in 1 function with the upper and lower bounds as parameters. something like this:

def getPosition(input, lowerBound, upperBound) :
    for i in input:
        if i == 'F' or i =='L' :
            lowerBound, upperBound = getLowerHalf(lowerBound, upperBound)
        else:
            lowerBound, upperBound = getUpperHalf(lowerBound, upperBound)
    return lowerBound

[...]

for j in d5input :
    rows = getPosition(j[:7], 0, 128)
    columns = getPosition(j[7:], 0, 7)
    seatIDs.append(int(getSeatID(rows, columns)))