From: Mart Lubbers Date: Thu, 17 Dec 2020 08:47:07 +0000 (+0100) Subject: 17 X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=2c628ade9d15908a311f0763c6ae94a74d1ca1b0;p=aoc20.git 17 --- diff --git a/17/one.c b/17/one.c new file mode 100644 index 0000000..9733cb3 --- /dev/null +++ b/17/one.c @@ -0,0 +1,120 @@ +#include +#include +#include +#include +#include + +enum cellstatus {active, inactive}; + +//char *inp[] = {".#.","..#","###"}; +char *inp[] = + {"...#.#.#" + ,"..#..#.." + ,"#.#.##.#" + ,"###.##.." + ,"#####.##" + ,"#......." + ,"#..#..##" + ,"...##.##" + }; + +int steps = 6; +uint16_t *map = NULL; +int xmax, ymax, zmax; + +#define mapel(x, y, z) map[(z)*ymax*xmax+(y)*xmax+(x)] + +enum cellstatus oldstatus(int x, int y, int z) +{ + if(x<0 || y<0 || z<0 || x >= xmax || y >= ymax || z >= zmax) + return inactive; + return (enum cellstatus)((mapel(x, y, z) >> 8) & 0xff); +} + +enum cellstatus newstatus(int x, int y, int z) +{ + if(x<0 || y<0 || z<0 || x >= xmax || y >= ymax || z >= zmax) + return inactive; + return (enum cellstatus)(mapel(x, y, z) & 0xff); +} + +void step() +{ + //Move the old to the leftmost byte + for (int z = 0; z +#include +#include + +enum cellstatus {inactive, active}; + +char *inp[] = + {"...#.#.#" + ,"..#..#.." + ,"#.#.##.#" + ,"###.##.." + ,"#####.##" + ,"#......." + ,"#..#..##" + ,"...##.##" + }; + +#define steps 6 +#define xorig (sizeof(inp[0])) +#define yorig (sizeof(inp)/sizeof(char *)) +#define xmax (xorig+steps*2) +#define ymax (yorig+steps*2) +#define zmax (1+steps*2) +#define wmax (1+steps*2) +uint16_t map[xmax*ymax*zmax*wmax] = {inactive}; + +#define mapel(x, y, z, w) map[(w)*zmax*ymax*xmax+(z)*ymax*xmax+(y)*xmax+(x)] + +enum cellstatus oldstatus(int x, int y, int z, int w) +{ + if(x<0 || y<0 || z<0 || w<0 || x >= xmax || y >= ymax || z >= zmax || w >= wmax) + return inactive; + return (enum cellstatus)((mapel(x, y, z, w) >> 8) & 0xff); +} + +enum cellstatus newstatus(int x, int y, int z, int w) +{ + if(x<0 || y<0 || z<0 || w<0 || x >= xmax || y >= ymax || z >= zmax || w >= wmax) + return inactive; + return (enum cellstatus)(mapel(x, y, z, w) & 0xff); +} + +void step() +{ + //Move the old to the leftmost byte + for (int w = 0; w