Skip to content

Instantly share code, notes, and snippets.

@milkboy
Last active December 11, 2022 20:12
Show Gist options
  • Save milkboy/bc4195d27e0517bf01c01c8dadebe648 to your computer and use it in GitHub Desktop.
Save milkboy/bc4195d27e0517bf01c01c8dadebe648 to your computer and use it in GitHub Desktop.
AoC 2022 11 614 chars
#!/usr/bin/awk -f
BEGIN{E=1}
/M/{D=$2;sub(/:/,"",D);R[D]=S[D]=0;N++}
/S/{split(substr($0,19),n,", ");r=substr($0,19);gsub(/, /," ",r);I[D]=J[D]=r}
/O/{$5=="+"?A[D]=$6:$6=="old"?0:C[D]=$6}
/T/{T[D]=$4;E*=$4}
/u/{Q[D]=$6}
/fa/{W[D]=$6}
function p(i,w){split(w==1?I[i]:J[i],n);for(z in n){
z=A[i]!=""?n[z]+A[i]:C[i]!=""?n[z]*C[i]:n[z]*n[z];z=w==1?z/3:z%E;sub(/\..*/,"",z)
y=z%T[i]==0?Q[i]:W[i]
if(w==1){I[y]=sprintf("%s %s",I[y],z);K<20?R[i]++:0}else{S[i]++;J[y]=sprintf("%s %s",J[y],z)}
}w==1?I[i]="":J[i]=""}
END{for(;K<10^4;K++){m=0;while(m<N){p(m,1);p(m++)}};asort(R);asort(S);print R[N]*R[N-1],S[N]*S[N-1]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment