6 struct point
{ int x
; int y
; };
7 struct dot
{ struct point p
; UT_hash_handle hh
; };
9 #define pnt(px, py) ((struct point){.x=(px), .y=(py)})
10 void add_dot(struct dot
**grid
, struct point p
)
13 HASH_FIND(hh
, *grid
, &p
, sizeof(struct point
), d
);
15 d
= malloc(sizeof(struct dot
));
17 HASH_ADD(hh
, *grid
, p
, sizeof(struct point
), d
);
21 #define foldp(p, f) ( (f) - ( (p) - (f) ) )
23 void fold(struct dot
**grid
, char axis
, int num
)
26 HASH_ITER(hh
, *grid
, d
, tmp
) {
27 struct point p
= d
->p
;
28 if (axis
== 'x' && p
.x
>= num
) {
31 add_dot(grid
, pnt(foldp(p
.x
, num
), p
.y
));
32 } else if (axis
== 'y' && p
.y
>= num
) {
35 add_dot(grid
, pnt(p
.x
, foldp(p
.y
, num
)));
44 struct dot
*grid
= NULL
;
47 while (getline(&buf
, &len
, stdin
) != -1) {
48 if (strcmp(buf
, "\n") == 0) {
51 char *to
= strchr(buf
, ',');
53 add_dot(&grid
, pnt(atoi(buf
), atoi(to
)));
55 char *to
= strchr(buf
, '=');
56 fold (&grid
, *(to
-1), atoi(to
+1));
60 printf("%d\n", HASH_COUNT(grid
));