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)})
11 void add_dot(struct dot
**grid
, struct point p
)
14 HASH_FIND(hh
, *grid
, &p
, sizeof(struct point
), d
);
16 d
= malloc(sizeof(struct dot
));
18 HASH_ADD(hh
, *grid
, p
, sizeof(struct point
), d
);
22 #define foldp(p, f) ( (f) - ( (p) - (f) ) )
24 void fold(struct dot
**grid
, char axis
, int num
)
27 HASH_ITER(hh
, *grid
, d
, tmp
) {
28 struct point p
= d
->p
;
29 if (axis
== 'x' && p
.x
>= num
) {
32 add_dot(grid
, pnt(foldp(p
.x
, num
), p
.y
));
33 } else if (axis
== 'y' && p
.y
>= num
) {
36 add_dot(grid
, pnt(p
.x
, foldp(p
.y
, num
)));
45 struct dot
*grid
= NULL
;
47 while (getline(&buf
, &len
, stdin
) != -1 && strcmp(buf
, "\n") != 0) {
48 char *to
= strchr(buf
, ',');
50 add_dot(&grid
, pnt(atoi(buf
), atoi(to
)));
52 while (getline(&buf
, &len
, stdin
) != -1) {
53 char *to
= strchr(buf
, '=');
54 fold (&grid
, *(to
-1), atoi(to
+1));
57 int maxx
= 0, maxy
= 0;
58 for (struct dot
*d
= grid
; d
!=NULL
; d
= d
->hh
.next
) {
59 maxx
= maxx
< d
->p
.x
? d
->p
.x
: maxx
;
60 maxy
= maxy
< d
->p
.y
? d
->p
.y
: maxy
;
64 for (int y
= 0; y
<=maxy
; y
++) {
65 for (int x
= 0; x
<=maxx
; x
++) {
66 HASH_FIND(hh
, grid
, &pnt(x
, y
), sizeof(struct point
), d
);
67 printf("%c", d
? '#' : '.');