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 - */
@DavidBuchanan314
Copy link
Author

Thank you for the advice. I haven't entered IOCCC before, but I definitely plan to. It's something I've wanted to do for a long time, so I'm humbled to be talking to a winner :)

@ilyakurdyukov
Copy link

Forgive me for this little criticism, this is actually the attention to detail and the experience of writing IOCCC entries, after months of polishing the code (rewriting it little by little every day, making it smaller and smaller), now I can easily see where improvements can be made.

I think you can still use this interesting way of displaying graphics using a video player in your next entries, even if you have published this work. But with something different from the Conway's game of life.

@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