5 enum cellstatus
{inactive
, active
};
19 #define xorig (sizeof(inp[0]))
20 #define yorig (sizeof(inp)/sizeof(char *))
21 #define xmax (xorig+steps*2)
22 #define ymax (yorig+steps*2)
23 #define zmax (1+steps*2)
24 #define wmax (1+steps*2)
25 uint16_t map
[xmax
*ymax
*zmax
*wmax
] = {inactive
};
27 #define mapel(x, y, z, w) map[(w)*zmax*ymax*xmax+(z)*ymax*xmax+(y)*xmax+(x)]
29 enum cellstatus
oldstatus(int x
, int y
, int z
, int w
)
31 if(x
<0 || y
<0 || z
<0 || w
<0 || x
>= xmax
|| y
>= ymax
|| z
>= zmax
|| w
>= wmax
)
33 return (enum cellstatus
)((mapel(x
, y
, z
, w
) >> 8) & 0xff);
36 enum cellstatus
newstatus(int x
, int y
, int z
, int w
)
38 if(x
<0 || y
<0 || z
<0 || w
<0 || x
>= xmax
|| y
>= ymax
|| z
>= zmax
|| w
>= wmax
)
40 return (enum cellstatus
)(mapel(x
, y
, z
, w
) & 0xff);
45 //Move the old to the leftmost byte
46 for (int w
= 0; w
<wmax
; w
++)
47 for (int z
= 0; z
<zmax
; z
++)
48 for (int y
= 0; y
<ymax
; y
++)
49 for (int x
= 0; x
<xmax
; x
++)
50 mapel(x
, y
, z
, w
) <<= 8;
52 for (int w
= 0; w
<wmax
; w
++) {
53 for (int z
= 0; z
<zmax
; z
++) {
54 for (int y
= 0; y
<ymax
; y
++) {
55 for (int x
= 0; x
<xmax
; x
++) {
57 for (int dw
= -1; dw
<=1; dw
++) {
58 for (int dz
= -1; dz
<=1; dz
++) {
59 for (int dy
= -1; dy
<=1; dy
++) {
60 for (int dx
= -1; dx
<=1; dx
++) {
61 if (dx
== 0 && dy
== 0 && dz
== 0 && dw
== 0)
63 if (oldstatus(x
+dx
, y
+dy
, z
+dz
, w
+dw
) == active
)
69 switch (oldstatus(x
, y
, z
, w
)) {
72 |= count
== 2 || count
== 3
89 fprintf(stderr
, "Total size: %ux%ux%ux%u, %u elements, %u steps\n",
90 xmax
, ymax
, zmax
, wmax
, xmax
*ymax
*zmax
*wmax
, steps
);
92 for(int y
= 0; y
<yorig
; y
++)
93 for(int x
= 0; x
<xorig
; x
++)
94 mapel(x
+steps
, y
+steps
, steps
, steps
) =
95 inp
[y
][x
] == '#' ? active
: inactive
;
97 for(int i
= 0; i
<steps
; i
++) {
98 fprintf(stderr
, "step: %d\n", i
);
103 for(int w
= 0; w
<wmax
; w
++)
104 for(int z
= 0; z
<zmax
; z
++)
105 for(int y
= 0; y
<ymax
; y
++)
106 for(int x
= 0; x
<xmax
; x
++)
107 if (newstatus(x
, y
, z
, w
) == active
)
110 printf("%d\n", count
);