Conway's Game Of Life in 140 bytes of JS
This is a small implementation of Conway's Game of Life in 140 bytes of JavaScript code:
function(g,x,y,w,h){v=g[x][y];s=0;for(i=x-1;i<x+2;i++)for(k=y-1;k<y+2;k++)if(i>=0&&i<w&&k>=0&&k<h)s+=g[i][k];return s==3||v&&s==4;}
The indendent code is:
function (g, x, y, w, h)
{
v=g[x][y];
s=0;
for( i=x-1; i < x+2; i++)
for(k=y-1; k<y+2; k++)
if( i >= 0 && i < w && k >= 0 && k < h )
s += g[i][k];
return s==3 | |v && s==4;
}
If you want see it in action, download the code here
Written by 0xNaN
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Game of life
Authors
depy
6.537K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#