5 struct point
{ int x
; int y
; };
6 struct dot
{ struct point p
; UT_hash_handle hh
; };
8 #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
;
46 while (getline(&buf
, &len
, stdin
) != -1 && strcmp(buf
, "\n") != 0) {
47 char *to
= strchr(buf
, ',');
49 add_dot(&grid
, pnt(atoi(buf
), atoi(to
)));
52 int maxx
= 0, maxy
= 0;
53 while (getline(&buf
, &len
, stdin
) != -1) {
54 char *to
= strchr(buf
, '=')-1;
55 int foldline
= atoi(to
+2);
56 fold (&grid
, *to
, foldline
--);
57 if (*to
== 'x') maxx
= foldline
;
62 for (int y
= 0; y
<=maxy
; y
++) {
63 for (int x
= 0; x
<=maxx
; x
++) {
64 HASH_FIND(hh
, grid
, &pnt(x
, y
), sizeof(struct point
), d
);
65 printf("%c", d
? '#' : '.');