Day 16: Add C solution
This commit is contained in:
parent
a775f8fcb1
commit
9272608cc9
1 changed files with 24 additions and 0 deletions
24
16/solution.c
Normal file
24
16/solution.c
Normal 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);}
|
Loading…
Reference in a new issue