Skip to content

Instantly share code, notes, and snippets.

@a17sol
Last active April 26, 2025 01:57
Show Gist options
  • Save a17sol/207e686a67c4047a62ee24838aa550ec to your computer and use it in GitHub Desktop.
Save a17sol/207e686a67c4047a62ee24838aa550ec to your computer and use it in GitHub Desktop.
Rule 110 simulation in a single variable/register. This approach can be used for hardware implementations, using a long shift register and a minimal number of logic gates.
#include <stdint.h>
#include <stdio.h>
void main(void) {
register uint32_t line = 0b10;
for (int i = 0; i < 31; i++) {
for (int j = 0; j < 31; j++) {
putchar(((line & 0b100) >> 2) * ('#' - ' ') + ' ');
uint8_t cond = line & 0b111;
line >>= 1;
if (cond != 0b111 && cond != 0b001 && cond != 0b000) {
line = line | ((uint32_t)1 << 31);
}
}
putchar('\n');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment