Skip to content
Snippets Groups Projects
Verified Commit 0ddda6ea authored by raphael.bach's avatar raphael.bach
Browse files

Add sequential `rule_110.c`

parent b0d71415
No related branches found
No related tags found
No related merge requests found
#include <stdint.h> // uint8_t
#include <stdlib.h> // EXIT_SUCCESS, size_t
#include <string.h> // memcpy()
#define T uint8_t
#define STEP_CNT 16
int main(void)
{
T in[] = {
1,1,0,1,0,0,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,1
};
#define size (sizeof(in)/sizeof(T))
T out[size];
for(size_t step = 0; step < STEP_CNT; step++) {
for(size_t i = 0; i < size; i++) {
if(i == 0) {
out[i] = (in[i] == 1) || (in[(i+1)] == 1);
} else if(i == (size-1)) {
out[i] = (in[i] == 1);
} else {
out[i] = (in[i] != in[(i+1)]) || ((in[(i-1)] == 0) && (in[i] == 1));
}
}
memcpy(in, out, size);
}
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment