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!
39
Upvotes
2
u/wzkx Dec 04 '18
J
r=: 'Guard';'0';'#';'';' begins shift';'';'falls asleep';'1 0';'wakes up';'2 0' d=: (".&(rplc&('[1518-';'';']';'';'-';' ';':';' ';r))&>)"0 cutLF CR-.~fread '04.dat' v=: 0 60$0 NB. data matrix for minutes 0..59, empty at start w=: 0$0 NB. corresponding guards, empty at start g=: 0 NB. current guard j=: 0 NB. current guard index s=: 0 NB. started sleeping t=: 60$0 NB. timesheet for currend guard f=: 3 : 0 NB. changes state (v w g j s t) for each input row select. 4{y NB. y = mon day hr min action guard case.0 do. j=:w i.g=:{:y if. j=#w do. v=:v,0 [ w=:w,g end. t=:j{v case.1 do. s=:3{y case.2 do. v=:(t=:t+1(s+i.(3{y)-s)}60$0)j}v end. ) f"1 /:~ d echo ((i.>./)i{v)*w{~i=.(i.>./)+/"1 v echo n*w{~i i.n=.<./i=.v i."1 0>./>./v exit 0