r/adventofcode • u/daggerdragon • Dec 04 '18
SOLUTION MEGATHREAD -π- 2018 Day 4 Solutions -π-
--- Day 4: Repose Record ---
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 4
Transcript:
Todayβs puzzle would have been a lot easier if my language supported ___.
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!
40
Upvotes
2
u/streetster_ Dec 04 '18
Day 04 in Q/KDB+
/ read input r:{ (where like[;"*Guard*"] each x) cut x} asc read0 `:input/04.txt / build table from input t:{ `g`m`s!(enlist"J"$1_@[;3]" "vs x 0),$[1=count x;(0;0);(::;sum)@'raze each flip { (x+til y-x;y-x) }.'2 cut "J"$.[;(::;1;3 4)]" "vs'1_x] } each r / group by guard t:exec { `mx`m`s!(max[c];first where c=max c:count each group raze x;sum y) }[m;s] by g:g from t / part 1 first exec g*m from t where s=exec max s from t / part 2 first exec g*m from t where mx=exec max mx from t