2
1
Fork 0

Day 16: Add C solution

This commit is contained in:
Mia Herkt 2021-12-17 07:32:13 +01:00
parent a775f8fcb1
commit 9272608cc9
Signed by: mia
GPG key ID: 72E154B8622EC191

24
16/solution.c Normal file
View file

@ -0,0 +1,24 @@
#include <stdio.h>
#include <stdint.h>
typedef uint64_t u;u R=0
#define O(n,x) u n(u a, u b){return x;}
,N;u X(u n){u r=0,i=0;for(;i<n;i++){if(!(R%4))scanf(
#define l(c) for(;c; i++) {m w=d(); r.l=\
i?o[t] (r.l,w.l) :w.l;r.v+=w.v;}
"%1lx",&N);r =r<<1 | N>>3-R%4&1;R++;} return r;}
typedef struct m{u l,v ;}m;O (A,a+b)O(M,a*b)O( H,a<b
?a :b)O(J, a>b?a:b)O(G,a>b)O(L, a<b)O( E,a==b)u(* o[
])(u,u)={A,M, H,J,0,G,L,E};
m d(){m r={0,X(3)}; u t=X(3
), s,k,i=0;if(t==4)do{s=X(1) ;r
.l=r.l<<4|X(4); }while(s);else{
s=X(1);k= X(s?11:
15 );
if(s)l(i<
k)else{ k+=R;l(R<
k ) }}return r;}int
main ( ) {m r=d();
printf("Silver: %lu"
"\nGold: %lu\n",r
.v,r.l);}