Skip to content

Instantly share code, notes, and snippets.

@uncompiled
Created March 3, 2018 22:43
Show Gist options
  • Save uncompiled/1c76924960f9f26184846273d871a2aa to your computer and use it in GitHub Desktop.
Save uncompiled/1c76924960f9f26184846273d871a2aa to your computer and use it in GitHub Desktop.
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