5ftl0g
Last Updated: February 25, 2016
·
779
· 0xnan

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