5 struct point
{int x
; int y
; int z
; };
9 struct point points
[100];
12 bool parse_scanner(struct scanner
*s
)
16 if (-1 == getline(&b
, &len
, stdin
))
18 sscanf(b
, "--- scanner %d ---\n", &s
->num
);
19 while (getline(&b
, &len
, stdin
) != -1 && strcmp(b
, "\n") != 0) {
20 sscanf(b
, "%d,%d,%d\n"
21 , &s
->points
[s
->npoints
].x
22 , &s
->points
[s
->npoints
].y
23 , &s
->points
[s
->npoints
].z
);
29 struct point
orient(struct point p
, struct point r
, int orientation
)
32 return (struct point
){.x
=r
.x
*p
.x
, .y
=r
.y
*p
.y
, .z
=r
.z
*p
.z
};
33 else if (orientation
== 1)
34 return (struct point
){.x
=r
.x
*p
.x
, .y
=r
.y
*p
.z
, .z
=r
.z
*p
.y
};
35 else if (orientation
== 2)
36 return (struct point
){.x
=r
.x
*p
.y
, .y
=r
.y
*p
.x
, .z
=r
.z
*p
.z
};
37 else if (orientation
== 3)
38 return (struct point
){.x
=r
.x
*p
.y
, .y
=r
.y
*p
.z
, .z
=r
.z
*p
.x
};
39 else if (orientation
== 4)
40 return (struct point
){.x
=r
.x
*p
.z
, .y
=r
.y
*p
.x
, .z
=r
.z
*p
.y
};
41 else if (orientation
== 5)
42 return (struct point
){.x
=r
.x
*p
.z
, .y
=r
.y
*p
.y
, .z
=r
.z
*p
.x
};
44 fprintf(stderr
, "unknown orientation\n");
46 struct point rotations
[] =
57 void match_scanners(struct scanner
*l
, struct scanner
*r
, int rot
, int or)
59 for (int dx
= -1000; dx
<1000; dx
++) {
60 for (int dy
= -1000; dy
<1000; dy
++) {
61 for (int dz
= -1000; dz
<1000; dz
++) {
72 struct scanner scanners
[25];
73 while(parse_scanner(&scanners
[nscanner
]))
76 for (int i
= 0; i
<nscanner
; i
++) {
77 for (int j
= 0; j
<nscanner
; j
++) {
80 for (int rot
= 0; rot
<8; rot
++) {
81 for (int or = 0; or<6; or++) {
82 match_scanners(&scanners
[i
], &scanners
[j
], rot
, or);