Created
March 3, 2018 22:43
-
-
Save uncompiled/1c76924960f9f26184846273d871a2aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function gameOfLifeIterator(b) { | |
const a = (x, y) => b[x] && b[x][y] | |
return b.map((r, x) => | |
r.map((_, y) => { | |
let n = 0 | |
if (a(x - 1, y - 1)) n++ | |
if (a(x - 1, y)) n++ | |
if (a(x - 1, y + 1)) n++ | |
if (a(x, y - 1)) n++ | |
if (a(x, y + 1)) n++ | |
if (a(x + 1, y - 1)) n++ | |
if (a(x + 1, y)) n++ | |
if (a(x + 1, y + 1)) n++ | |
return (a(x, y) ? n > 1 && n < 4 : n === 3) ? 1 : 0 | |
})) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment