r/adventofcode • u/daggerdragon • Dec 13 '17
SOLUTION MEGATHREAD -๐- 2017 Day 13 Solutions -๐-
--- Day 13: Packet Scanners ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).
Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Need a hint from the Hugely* Handyโ Haversackโก of Helpfulยง Hints^ยค?
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked!
16
Upvotes
View all comments
Show parent comment
2
u/streetster_ Dec 13 '17 edited Dec 13 '17
Here's my effort for today:
This one was fairly straightforward. Explanation with the example input.
Split input into two separate lists, layers and depths:
Create the 'firewall' with nulls in the layers without scanners. This is done by creating a list of nulls, and applying the depths at the correct indices (layers):
Calculate correct depths based on the fact that the scanner comes back up again:
Generate the offsets that you would reach each layer
modthis with the correct depths, 0 means we got caughtMultiply original depths by these layers and sum up the result
Part 2 is a simple brute-force. Add the delay to the offsets, and then, starting from 0, iterate up until we get a result where none of the results of the modulo operation are equal to 0.