Last active
April 26, 2025 01:57
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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