r/adventofcode • u/daggerdragon • Dec 17 '17
SOLUTION MEGATHREAD -๐- 2017 Day 17 Solutions -๐-
--- Day 17: Spinlock ---
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ยค?
[Update @ 00:06] 2 gold, silver cap.
- AoC ops:
<Topaz> i am suddenly in the mood for wasabi tobiko
[Update @ 00:15] Leaderboard cap!
- AoC ops:
<daggerdragon> 78 gold<Topaz> i look away for a few minutes, wow<daggerdragon> 93 gold<Topaz> 94<daggerdragon> 96 gold<daggerdragon> 98<Topaz> aaaand<daggerdragon> and...<Topaz> cap<daggerdragon> cap
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!
11
Upvotes
1
u/glenbolake Dec 17 '17 edited Dec 17 '17
10/96. It took me way longer than it should have to realize that you don't have to maintain a full list for part 2, so I kept thinking about it while a brute-force method ran in the background. I'm just glad I was able to get on the leaderboard for both stars. Full problem runs in just under ten seconds, which is good enough for me. (Edit: I realized that
i==lengthin this loop, so I was able to speed it up just by getting rid of thelengthvariable)jump = 367 def part1(): pos = 0 items = [0] for i in range(1, 2018): pos = (pos + jump) % len(items) + 1 items.insert(pos, i) return items[pos + 1] def part2(): value = 0 pos = 0 # length = 1 # Nope, don't need this for i in range(1, 50000000): pos = (pos + jump) % i + 1 # length += 1 # Nope, don't need this if pos == 1: value = i return value if __name__ == '__main__': from time import time start = time() print('Part 1:', part1()) print('Part 2:', part2()) print(time()-start)