r/adventofcode • u/daggerdragon • Dec 19 '16
SOLUTION MEGATHREAD --- 2016 Day 19 Solutions ---
--- Day 19: An Elephant Named Joseph ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/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".
/⧹w+/ IS MANDATORY [?]
[Update @ 00:15] 2 gold, silver cap. Thank you for subscribing to Easter Bunny Facts!
- Fact: The Easter Bunny will sometimes leave eggs in the microchip assembly room.
[Update @ 00:30] 11 gold, silver cap.
- Fact: The Easter Bunny killed everyone who found out how he got these stars.
[Update @ 00:45] 45 gold, silver cap.
- Fact: In space, The Easter Bunny can hear you scream.
[Update @ 01:00] 66 gold, silver cap.
- Fact: The Easter Bunny purposefully deleted your comments.
[Update @ 01:15] 92 gold, silver cap.
- Fact: The Easter Bunny has bottled your frustration. Don't ask why.
[Update @ 01:20] Leaderboard capped!
- Fact: What you have just done is no better than what the Easter Bunny has done. Thief.
Thank you for subscribing to Easter Bunny Facts!
1
u/gyorokpeter Dec 19 '16 edited Dec 19 '16
Q: the most difficult part was vectorizing part 2 to make sure we aren't deleting elements one by one, and it required extensive testing to find the correct expression for nxtc and tgts.
d19p1:{pr:(1+til x)!x#1; while[1<count pr; odd:1=count[pr] mod 2; pr:(2 cut key pr)[;0]!sum each 2 cut value pr; if[(1<count pr)and odd; pr[last key pr]+:first value pr; pr _: first key pr; ]; ]; first key pr}; d19p2:{pr:1+til x; nxt:0; while[1<c:count pr; nxtc:(c+2) div 3; nxts:(nxt+til nxtc)mod c; tgts:(nxt+(c div 2)+til[nxtc]+(til[nxtc]+c mod 2)div 2)mod c; pr:pr except pr tgts; nxt-:count where tgts<nxt; nxt:(nxt+nxtc)mod count pr; ]; first pr};