A Game of Life engine in 126 bytes
Demo available on http://xem.github.io/miniGameOfLife
A Game of Life engine in 126 bytes
Demo available on http://xem.github.io/miniGameOfLife
| /* The Game of Life function */ | |
| // @param s: current state of the grid | |
| // @param d: size of the grid (d*d) | |
| // @param n: placeholder | |
| // @param k: placeholder | |
| // @param m: placeholder | |
| // @param i: placeholder | |
| // @param j: placeholder | |
| function(s, d, n, k, m, i, j){ | |
| for( | |
| n = [], // Initialize next state | |
| m = [d + 1, d, d - 1, 1], // Initialize the upper half of the neighbours indexes | |
| i = d * d; // For each cell | |
| i--; | |
| n[i] = k == 3 || s[i] && k == 2, // Set next state (live if it has 3 neighbours or lives and has 2 neighbours) | |
| k = 0 // Reset the count of living neighbours | |
| ) | |
| for(j in m) // for each neighbour position | |
| k += s[i + m[j]] + s[i - m[j]] // count the living neighbours | |
| return(n) // return the next state | |
| } |
| function(f,c,d,h){for(var g=[],e=[c+1,c,c-1,1],b=c*c;b--;g[b]=3==d||f[b]&&2==d,d=0)for(h in e)d+=f[b+e[h]]+f[b-e[h]];return g} |
| DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
| Version 2, December 2004 | |
| Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE> | |
| Everyone is permitted to copy and distribute verbatim or modified | |
| copies of this license document, and changing it is allowed as long | |
| as the name is changed. | |
| DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
| TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
| 0. You just DO WHAT THE FUCK YOU WANT TO. |
| { | |
| "name": "miniGameOfLife", | |
| "description": "The smallest Game of Life engine of all time", | |
| "keywords": [ | |
| "game", | |
| "life" | |
| ] | |
| } |
| <a href="http://xem.github.io/miniGameOfLife">Demo</a> |
Sadly, no. But I don't know why exactly.