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

Click here for rules

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!

38 Upvotes

340 comments sorted by

View all comments

2

u/dpeckett Dec 04 '18

Continuing with my quest to solve all this years challenges using nothing other than AWK:

Solution To Both Challenges:

{
  gsub(/[\[\]#]/,"",$0);t[NR]=$0
} END {
  n=asort(t);
  for(i=1;i<=n;i++)
    if(split(t[i],v,/[ \-\:]/)>7)g=v[7];
    else if(index(v[6],"f"))p=v[5];
    else for(j=p;j<v[5];j++){z[g","j]++;if(++zt[g]>zt[x])x=g}
  for(i=0;i<60;i++)if(z[x","i]>z[x","y])y=i;
  print x*y;
  for(i in z)if(z[i]>z[w])w=i;
  split(w,v,",");print v[1]*v[2];
}

Runtime

real 0m0.027s
user 0m0.014s
sys  0m0.005s