2
1
Fork 0
aoc2021/05/solution_2_tree.c

26 lines
847 B
C

#include <stdio.h>
#define O 1000
#define E(a,b,X)if(a==b){X}else
#define u int
#define C(x,y)I+=++m[x][y]==2;
#define P(a,b)a<b?1:-1
#define L(s,e)u S=P(s,e);for(u c=s;c!=e;c+=S)
u
main
(void){u
m[O][O]={0},
x,X,y,Y,
I=0;while(
fscanf( stdin,
"%i,%i -> %i,%i",&
x,&y,&X,&Y)==4){E(x,X,L
(y,Y)C(x,c)C(x,Y)
)E(y,Y,L(x,X)C(c,y)C
(X,y)){u h=x,v=y,H=P(x,X
),V=P(y,Y);for(;h!=X&&v!=Y;h+=
H,v+=V
)C(h,v
)C(h,v
)}}printf(
"Answer: %d\n",I);}