Skip to content

Instantly share code, notes, and snippets.

@a17sol
a17sol / 110.c
Created March 16, 2025 20:42
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 = 0b100;
for (int i = 0; i < 30; i++) {
for (int j = 0; j < 30; j++) {
putchar(((line & 0b100) >> 2) * ('#' - ' ') + ' ');
line >>= 1;
uint8_t cond = line & 0b111;
@a17sol
a17sol / quine_clock.c
Created July 27, 2024 01:14
Quine clock without cheating like linker source code embedding etc. Inspired by https://gist.github.com/rexim/f582098611b2be202051ba543e21da05. Compile: gcc -include stdio.h -include string.h -include time.h -include unistd.h quine_clock.c
char *s="char *s=%c%s%c; char S[1024];int d[] = {32319,31812,19129,32437,31879,991\
1,30399,4001,32447,32439,320};void main(){sprintf(S,s,34,s,34,34,92,34,34,34,34,34\
,34,92,34,10);for(;;){int lin=-3,G=-5,i=0;for(i;i<strlen(S);i++){time_t t=time(0);\
printf(%c%cx1b[%%s%c,(d[ctime(&t)[G/4+11]-48]>>(lin+(G%4)*5))&1&&!((G-15)/16)&&!((\
lin-2)/3)?%c31m%c:%c90m%c);putchar(S[i]);G+=i%2;if(G>35){putchar(lin<2?92:0);putch\
ar(10);lin++;G=-5;}}sleep(1);printf(%c%cx1b[11A%c);}}%c"; char S[1024];int d[] = {
32319,31812,19129,32437,31879,9911,30399,4001,32447,32439,320};void main(){sprintf
(S,s,34,s,34,34,92,34,34,34,34,34,34,92,34,10);for(;;){int lin=-3,G=-5,i=0;for(i;i
<strlen(S);i++){time_t t=time(0);printf("\x1b[%s",(d[ctime(&t)[G/4+11]-48]>>(lin+(
G%4)*5))&1&&!((G-15)/16)&&!((lin-2)/3)?"31m":"90m");putchar(S[i]);G+=i%2;if(G>35){