r/adventofcode • • 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!

Click here for rules

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!

22 Upvotes

283 comments sorted by

View all comments

Show parent comment

1

u/Vaelatern Dec 09 '18

And I further shaved of seconds (down to .497s and 53s with:

@@ -436,15 +436,16 @@

 (defn p9-ll-insert-after-cur [ll num]
   (let [curitem (:cur ll)
  • next (if (nil? curitem) num (-> ll (get curitem) :next))
+ curitemmap (-> ll (get curitem)) + next (if (nil? curitem) num (-> curitemmap :next)) prev (if (nil? curitem) num curitem)
  • marble (p9-marble num next prev)
  • newcur {:cur num}
  • newmarble {num marble}
  • newprev (if (nil? curitem) {} {curitem (assoc (-> ll (get curitem)) :next num)})
  • tmpll (merge ll newprev)
  • newnext {next (assoc (-> tmpll (get next)) :prev num)}]
  • (merge ll newcur newprev newnext newmarble)))
+ newprev (if (nil? curitem) {} {curitem (assoc curitemmap :next num)}) + tmpll (merge ll newprev)] + (assoc-in + (assoc-in + (assoc-in tmpll [next] (assoc (-> tmpll (get next)) :prev num)) + [:cur] num) + [num] (p9-marble num next prev)))) (defn p9-ll-insert-2-later [ll num] (let [tmpll (assoc ll :cur (-> ll (get (-> ll :cur)) :next))] @@ -459,8 +460,9 @@ (let [curmap (-> ll (get (-> ll :cur))) curprev (:prev curmap) curnext (:next curmap)
  • tmpll (assoc-in ll [curprev :next] curnext)
  • tmpll (assoc-in tmpll [curnext :prev] curprev)]
+ tmpll (assoc-in + (assoc-in ll [curprev :next] curnext) + [curnext :prev] curprev)] (assoc (dissoc tmpll (:num curmap)) :cur curnext))) (defn p9-back-and-drop [ll]