Skip to content

Instantly share code, notes, and snippets.

@DavidBuchanan314
Last active August 9, 2023 23:12
Show Gist options
  • Save DavidBuchanan314/2280bff6e579e4c4ec9cd925a9ed9fea to your computer and use it in GitHub Desktop.
Save DavidBuchanan314/2280bff6e579e4c4ec9cd925a9ed9fea to your computer and use it in GitHub Desktop.
Yet another reformatting of my tiny game of life implementation. Valid ANSI C with no (default) compiler warnings or UB
#define F\
for(i=l;i\
<l*4; i++)
main(){int
i,j,w=512,
n,l=w*w,o[
]={~w,-w,-
w+1,-1,1,w
-1,w,w+1},
b[l*5];F b
[i]=rand();for(puts("YUV4MPEG\
2 W512 H512 C444");puts("FRAM\
E");){F{for(n=j=8;j;n-=1&b[i+o
[--j]]);b[i+l]=(n^5&&!b[i]|n^6
)-1;}F putchar(b[i]=b[i+l]);}}
/* gcc life.c;./a.out|mpv - */
@ilyakurdyukov
Copy link

I'm used these 24 bytes to deal with any warnings that GCC and Clang can see. Even for Clang's -Weverything, but honestly, I think -Weverything are too excessive, I didn't bother about it in my works, only care about -Wall -Wextra -pedantic.

          #define F\
          for(i=l;i\
          <l*4; i++)
          int main()
          {int i,j,w
                    =512,n,l=w
                    *w; static
                    int b[ 5<<
                    18];F b[i]
                    =rand();f\
or(puts("YUV4MPEG2 W512 H512 \
C444");;){puts("FRAME");F{for(
n=j=9;j--;n-=1&b[i+j/3*w+j%3+~
w]){}b[i+l]=(n^6&&(!b[i]||n^5)
)-1;}F putchar(b[i]=b[i+l]);}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment