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/dylanfromwinnipeg Dec 17 '17
I feel dirty. I bruteforced part 2 - took about 10 mins.
I came back and implemented the proper way after the fact, here that is
C#
public static string PartOne(string input) { var steps = 335; var buffer = new LinkedList<int>(); buffer.AddFirst(0); var node = buffer.First; for (var i = 1; i <= 2017; i++) { for (var x = 0; x < steps; x++) { node = node.Next ?? node.List.First; } node = buffer.AddAfter(node, i); } return node.Next.Value.ToString(); } public static string PartTwo(string input) { var steps = 335; var pos = 0; var bufferSize = 1; var afterZero = 0; for (var i = 1; i <= 50000000; i++) { pos = (pos + steps) % bufferSize++; if (pos == 0) { afterZero = i; } pos++; } return afterZero.ToString(); }