Public
Edited
Nov 3, 2023
4 forks
11 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
seed = new Set(['0,0', '0,1', '0,-1', '-1,0', '1,1']) // https://www.conwaylife.com/wiki/R-pentomino
Insert cell
function tick(cells) {
const counts = {}
for (const cell of cells)
for (const n of neighbors(cell.split(',').map(Number)))
counts[n] = (counts[n] ?? 0) + 1
const next = new Set()
for (const [cell, count] of Object.entries(counts))
if (count === 3 || (count == 2 && cells.has(cell)))
next.add(cell)

return next
}
Insert cell
function* neighbors([x, y]) {
for (const dx of [-1, 0, 1])
for (const dy of [-1, 0, 1])
if (dx !== 0 || dy !== 0)
yield [x + dx, y + dy]
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more