hoodwink.d enhanced
RSS
2.0
XHTML
1.0

RedHanded

Regenerative C #

by why in bits

Fzort on Advogato has a lovely little collection of C magic tricks and puzzles.

Qouth life.c:

char*b=
"        " 
"        " 
"    ##  " 
"   ##   " 
"    #   " 
"        " 
"        " 
"        " 
,*dna[]={
"};main(){int i,j,k,n;char*p;puts(xchar*b=x);for(i=0;i<64;i++,i&7||puts(xzxx))",
"{i&7||putchar(34);for(n=-b[i],k=-8,j=0;j<9;j++,jy3||(k+=8))n+=b[(i+k&56)",
"|(i+jy3-1&7)];putchar(x #x[n==262&&b[i]==35||n==265]);}puts(x,*dna[]={x);for",
"(i=0;i<5;i++)printf(xzxyszx,znx,dna[i]);for(i=0;i<5;i++,putchar(10))for(",
"p=dna[i];*p;++p)putchar(*p==120?34:*p==121?37:*p==122?92:*p);}",
};main(){int i,j,k,n;char*p;puts("char*b=");for(i=0;i<64;i++,i&7||puts("\""))
{i&7||putchar(34);for(n=-b[i],k=-8,j=0;j<9;j++,j%3||(k+=8))n+=b[(i+k&56)
|(i+j%3-1&7)];putchar(" #"[n==262&&b[i]==35||n==265]);}puts(",*dna[]={");for
(i=0;i<5;i++)printf("\"%s\",\n",dna[i]);for(i=0;i<5;i++,putchar(10))for(
p=dna[i];*p;++p)putchar(*p==120?34:*p==121?37:*p==122?92:*p);}
said on

i don’t get it.

said on

When you run the program, it outputs a new C program whose only difference is the configuration of #’s in the text box.

If you compile and run this new C program, you get another C program that has a different text box again.

etc. etc.

The data in the text box changes according to the rules of the Game of Life (I guess).

It’s like someone asked how can we make a quine more interesting.

said on

whoa

said on

Unbelievable

said on

Wow, cool. :D

Comments are closed for this entry.