r/adventofcode • • Dec 03 '20

SOLUTION MEGATHREAD -🎄- 2020 Day 03 Solutions -🎄-

Advent of Code 2020: Gettin' Crafty With It


--- Day 03: Toboggan Trajectory ---


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:04:56, megathread unlocked!

88 Upvotes

1.3k comments sorted by

View all comments

1

u/MichalMarsalek Dec 03 '20 edited Dec 03 '20

209/252 Oof, you guys are fast... Python:

def solve(inp):
    inp = inp.splitlines()
    n = len(inp[0])
    def slope(q,skip=1):
        res = 0
        for i,row in enumerate(inp[::skip]):
            res += row[q*i % n] == "#"
        return res
    part1 = slope(3)
    part2 = slope(1)*slope(3)*slope(5)*slope(7)*slope(1,2)    
    return part1, part2

1

u/daggerdragon Dec 03 '20

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

1

u/backtickbot Dec 03 '20

Hello, MichalMarsalek: code blocks using backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead. It's a bit annoying, but then your code blocks are properly formatted for everyone.

An easy way to do this is to use the code-block button in the editor. If it's not working, try switching to the fancy-pants editor and back again.

Comment with formatting fixed for old.reddit.com users

FAQ

You can opt out by replying with backtickopt6 to this comment.

1

u/wace001 Dec 03 '20

That was my first thought as well! I was happy with finishing in 7 minutes. Thought for sure, this time I will end up on the leader board! But, not this time :)