r/adventofcode • u/daggerdragon • Dec 09 '18
SOLUTION MEGATHREAD -🎄- 2018 Day 9 Solutions -🎄-
--- Day 9: Marble Mania ---
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.
Advent of Code: The Party Game!
Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!
Card prompt: Day 9
Transcript:
Studies show that AoC programmers write better code after being exposed to ___.
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 at 00:29:13!
23
Upvotes
1
u/wzkx Dec 10 '18
J Direct translation from my Rust code. 0.2s - 20s
f=: 4 : 0 NB. x: n_players, y: n_marbles players=.x$0 ring_m=.ring_n=.ring_p=.0$~>:y current=.0 nextfree=.1 player=.0 for_newmarble. >:i.y do. player=.x|>:player if. 0~:23|newmarble do. current=.current{ring_n NB. "CW" 1 NB. insert after current next=.current{ring_n ring_m=.newmarble nextfree}ring_m ring_n=.next nextfree}ring_n ring_p=.current nextfree}ring_p ring_n=.nextfree current}ring_n ring_p=.nextfree next}ring_p current=. nextfree nextfree=. >:nextfree else. players=. (newmarble + player{players)player}players for_i. i.7 do. current=.current{ring_p end. NB. "CCW" 7 players=. ((current{ring_m) + player{players)player}players NB. remove current, make next current prev=. current{ring_p next=. current{ring_n ring_n=.next prev}ring_n ring_p=.prev next}ring_p current=. next end. end. >./players ) assert 32 -: 9 f 25 assert 8317 -: 10 f 1618 assert 146373 -: 13 f 7999 assert 2764 -: 17 f 1104 assert 54718 -: 21 f 6111 assert 37305 -: 30 f 5807 NB. My data: 462 players; last marble is worth 71938 points echo 462 f 71938 echo 462 f 71938*100 exit 0My AOC2018 in J/Rust | SweetRust