2
1
Fork 0
aoc2021/05/solution_2_tree.c

26 lines
847 B
C
Raw Normal View History

2021-12-05 18:26:38 +01:00
#include <stdio.h>
#define O 1000
#define E(a,b,X)if(a==b){X}else
#define u int
2021-12-06 00:31:09 +01:00
#define C(x,y)I+=++m[x][y]==2;
2021-12-05 18:26:38 +01:00
#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)
2021-12-06 00:31:09 +01:00
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);}