summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMia Herkt <mia@0x0.st>2021-12-17 07:32:13 +0100
committerMia Herkt <mia@0x0.st>2021-12-17 07:32:13 +0100
commit9272608cc997c5efb4b869259992fb04536d7698 (patch)
treee29047c3f5c64e5a2f427ea1d4b467093fe7c339
parenta775f8fcb1a2fe254b51b04b9e5250e1f144472a (diff)
downloadaoc2021-9272608cc997c5efb4b869259992fb04536d7698.tar.bz2
aoc2021-9272608cc997c5efb4b869259992fb04536d7698.tar.xz
Day 16: Add C solution
-rw-r--r--16/solution.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/16/solution.c b/16/solution.c
new file mode 100644
index 0000000..8f73f73
--- /dev/null
+++ b/16/solution.c
@@ -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);}