r/adventofcode • • Dec 14 '18

SOLUTION MEGATHREAD -🎄- 2018 Day 14 Solutions -🎄-

--- Day 14: Chocolate Charts ---


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 14

Transcript:

The Christmas/Advent Research & Development (C.A.R.D.) department at AoC, Inc. just published a new white paper on ___.


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:19:39!

16 Upvotes

179 comments sorted by

View all comments

Show parent comment

1

u/jayfoad Dec 14 '18

Translated into APL with roughly similar timings -- I get about 80 seconds overall.

⎕IO←0
input←⍎⊃⊃⎕NGET'p14.txt'1
scores←3 7

nxt←{(⍵+1+cur)|⍨≢scores⊣scores,←⍎¨⍕+/cur←scores[⍵]}
pos←nxt⍣{input≤¯10+≢scores}0 1
∊⍕¨r←10↑input↓scores ⍝ part 1

match←⍎¨⍕input ⋄ chk←{∨/match⍷¯7↑scores}
{}nxt⍣chk pos
⊃⍸match⍷scores ⍝ part 2

1

u/jayfoad Dec 14 '18

I managed to get my APL solution under 30 seconds by using something faster than ⍎¨⍕ in nxt, and running multiple nxts between each chk. But it seems to be an inherently serial problem so I can't see any way to match the performance of compiled languages.

1

u/will_bui Dec 16 '18

Cool! We've been experimenting with strings and caching the lookup of the 3 9 => 1 2, the fastest came down to about 36 seconds.

1

u/jayfoad Dec 17 '18

My fastest is about 15 seconds. I simplified the nxt function as much as I could by not dealing with wraparound. Then I work out a safe approximation to how many times I can run it in a tight loop, based on how close the two elves are to the end of the scoreboard.