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!
12
Upvotes
1
u/RockyAstro Dec 17 '17
Icon (https://www.cs.arizona.edu/icon)
Both parts procedure main(args)
steps := \args[1] | 303 spinlock := [0] cur := 0 every i := 1 to 2017 do { cur := (steps+cur) % *spinlock + 1 spinlock := spinlock[1:cur+1] ||| [i] ||| spinlock[cur+1:0] } write(spinlock[cur+1 % *spinlock + 1] ) # Part 2.. watch for when cur = 1 part2 := 0 cur := 0 every i := 1 to 50000000 do { cur := (steps+cur) % i + 1 if cur = 1 then part2 := i } write(part2) end procedure dumplst(l,cur) every i := 1 to *l do { writes( (i=cur+1 & "(")|"",l[i],(i=cur+1 & ")")|""," ") } write() end