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
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#