2
1
Fork 0
aoc2021/21/solution.c

30 lines
1.7 KiB
C

#include <stdio.h>
M( p,s){ return(p
+s-1)% 10+1;}S( int*p,int*d,
int* D){for(int s= 0;s<3;s++,(
*D) ++)(*p)=M(* p,* d=*d%100+1
);return*p;}x(l,r ){int L=0,R=0
,d=0,D=0;for(;; ){L+=S(
&l,&d,&D); if(L>=
1000) break;R
+=S(&r, &d,&D);
if( R >= 1000)break
;}return D* (L>R?R:L);}
size_t X(t, l,r,L,R){if(L >=21
||R >= 21 ) return t;static F[ ]={1,3,6
,7 , 6,3,1}; size_t s=0;for( int m=0;m<7;
m++ ){int o=l, O= L,g=r,G=R
;if (t)G+=g=M(r ,m +3);else
O+=o=M(l,m+3);s+=F[ m] *X(! t,o,g,O
,G);}return s;}main ( int p, char* * P)
{ int l =4,r=8 ;if( p ==3
){ l= atoi(P[ 1 ]);
r=atoi (P[2 ] );
}printf("" "" "Si"
"lver: %" "" "d"
"\nGold: " "" "%lu\n"
,x(l,r),X ( 0,l,r,
0,0));}