Published
Edited
Nov 13, 2019
1 star
Insert cell
Insert cell
Insert cell
state = {
let state = initial
yield state
while (true)
yield state = tick(state)
}
Insert cell
Insert cell
function dupe(n) { return (n - 606) % 28 + 606 }
Insert cell
// part2freal = {
// const after10 = run(initial, dupe(1000000000))
// const counts = _.countBy(Object.values(after10))
// return counts['#'] * counts['|']
// }
Insert cell
// part2 = {
// let state = initial
// const seen = {}
// const dupes = []

// for (let i = 0; i < 700; i++) {
// const h = hash(state)
// if (h in seen)
// dupes.push([i, 'would be same as', seen[h]])
// else
// seen[h] = i
// state = tick(state)
// }
// return dupes
// }
Insert cell
Insert cell
Insert cell
function tick(state) {
const nextState = {},
counts = {}
for (const [key, type] of Object.entries(state)) {
for (const n of neighbors(key.split(',').map(Number))) {
if (n[0] < 0 || n[0] >= length || n[1] < 0 || n[1] >= length)
continue
const c = counts[n] = counts[n] || {}
c[type] = (c[type] || 0) + 1
}
}
for (const [key, c] of Object.entries(counts)) {
switch (state[key]) {
case undefined:
if (c['|'] >= 3)
nextState[key] = '|'
break
case '|':
nextState[key] = c['#'] >= 3 ? '#' : '|'
break
case '#':
if (c['#'] >= 1 && c['|'] >= 1)
nextState[key] = '#'
break
}
}

return nextState
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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