Anonymous user
Elementary cellular automaton: Difference between revisions
m
Cleanup
m (Cleanup) |
|||
Line 1,643:
// ----------------------------------------------------------------[ Utility ]--
const
const reverse = x => Array.from(x).reduce((p, c) => [c, ...p], []);
const numToLine = width => int => {
const test = hasBitAt(int);
const looper =
return reverse(looper.map((_, i) => test(i) ? alive : dead
}
Line 1,654:
const displayCA = (rule, width, lines, startIndex) => {
const result = [];
result.push(`Rule:${rule} Width:${width} Gen:${lines}\n`)
const ruleTest = hasBitAt(rule);
const lineLoop =
const looper =
const pLine = numToLine(width);
Line 1,668 ⟶ 1,669:
const r = bitTest(i === width - 1 ? 0 : i + 1);
nTarget = ruleTest(
parseInt([l, m, r].join(''), 2))
? setBitAt(nTarget, i)
: clearBitAt(nTarget, i);
Line 1,677 ⟶ 1,678:
}
displayCA(90, 57,
{{out}}
<pre>
Rule:90 Width:57 Gen:31
............................#............................
...........................#.#...........................
Line 1,712 ⟶ 1,715:
.##...#...#...#...#...#...#...#...#...#...#...#...#...##.
####.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.####
</pre>
|