I was creating a simple program to change locations on a grid:
#define R 11
#define C 11
#define N 3
typedef struct {
uint8_t live :1;
uint8_t next :1;
uint8_t padding :6;
} point;
int main() {
uint8_t r, c;
point graph[R][C] = {
{{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
{{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
{{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
{{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
{{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
{{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{1,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
{{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
{{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
{{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
{{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
{{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
};
for(size_t i = 0; i < N; i++) {
for(r = 0; r < R; r++) {
for(c = 0; c < C; c++){
putchar(0x30 + graph[r][c].live);
graph[r][c].next ^= (graph[(r-1) % R][c].live | graph[(r+1) % R][c].live | graph[r][(c+1) % C].live | graph[r][(c-1) % C].live);
}
putchar(0x0a);
}
putchar(0x0a);
for(r = 0; r < R; r++) {
for(c = 0; c < C; c++) {
graph[r][c].live = graph[r][c].next;
}
}
}
return 0;
}
Instead of outputting the predicted pattern, (I can't seem to display it without making my question have to much code to be submit it), after the second iteration, graph[0][3] is flipped to a 1 when it should remain a 0.