2
1
Fork 0
aoc2021/14/obf.c

24 lines
1.3 KiB
C

#include <stdio.h>
#include <string.h>
enum{M
#define\
P(a,\
b) (\
((a-\
65)<<\
6)|(b-65))
=P(90,90)+1};
size_t C[M]={0},T[M];void p(char*s){size_t r= -1,
R=0,k,n,i;for(i=65;i<90+1;i++){k=P(i,98);if((n=C[k])){if (n<r)
r= n;else if(n>R)R=n;}}printf("%s: %lu\n",s,R-r);}int main( void){
size_t i,j,n,k;char t[128],R[128][3]={0};scanf("%127[A-Z]\n",t) ;for(
i=0;t[i]/*⁻⁻*/;i++){if(i)/*⁻⁻*/C[P(t[i-1],t[i])]++;C[P(t[i],98)]++;}
for(i=0/* */;scanf(/* */"%c%c -> %c\n",&R[i][0],&R[i][1],&R[i
][2])==/* */3;i++);/* */for(i=0;i<40;i++){memset(T,0,M*sizeof
(size_t))/*₋₋*/;for(j=0;R[/*₋₋*/j][0];j++){k=P(R[j][0],R[j][1]);if((n=C
[k])){C[k]=0;C[P(R[j][2],98)]+=n;T[/*⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻*/P(R[j][0],R[j][
2])]+=n;T[P(R[j][2],R[j][1])]+=n;}}/* MADE IN CHINA */for(j=0; R[j][
0];j++){k=P(R[j][0],R[j][2]);C[k]/*₋₋₋₋₋₋₋₋₋₋₋₋₋₋₋*/=T[k]; k=P(R
[j][2],R[j][1]);C[k]=T[k];}if(i==9)p("Silver");}p("G" "old"
);}