Elementary cellular automaton: Difference between revisions

m
Cleanup
m (Cleanup)
Line 1,643:
 
// ----------------------------------------------------------------[ Utility ]--
const byteSlotmakeArr = n => Array(n).fill(0);
const reverse = x => Array.from(x).reduce((p, c) => [c, ...p], []);
const numToLine = width => int => {
const test = hasBitAt(int);
const looper = byteSlotmakeArr(width);
return reverse(looper.map((_, i) => test(i) ? alive : dead )).join('');
}
 
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 = byteSlotmakeArr(lines);
const looper = byteSlotmakeArr(width);
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, 6431, 28);</lang>
{{out}}
<pre>
Rule:90 Width:57 Gen:31
 
............................#............................
...........................#.#...........................
Line 1,712 ⟶ 1,715:
.##...#...#...#...#...#...#...#...#...#...#...#...#...##.
####.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.####
...#.................................................#...
..#.#...............................................#.#..
.#...#.............................................#...#.
#.#.#.#...........................................#.#.#.#
#......#.........................................#......#
##....#.#.......................................#.#....##
.##..#...#.....................................#...#..##.
#####.#.#.#...................................#.#.#.#####
....#......#.................................#......#....
...#.#....#.#...............................#.#....#.#...
..#...#..#...#.............................#...#..#...#..
.#.#.#.##.#.#.#...........................#.#.#.##.#.#.#.
#......##......#.........................#......##......#
##....####....#.#.......................#.#....####....##
.##..##..##..#...#.....................#...#..##..##..##.
#############.#.#.#...................#.#.#.#############
............#......#.................#......#............
...........#.#....#.#...............#.#....#.#...........
..........#...#..#...#.............#...#..#...#..........
.........#.#.#.##.#.#.#...........#.#.#.##.#.#.#.........
........#......##......#.........#......##......#........
.......#.#....####....#.#.......#.#....####....#.#.......
......#...#..##..##..#...#.....#...#..##..##..#...#......
.....#.#.#.##########.#.#.#...#.#.#.##########.#.#.#.....
....#......#........#......#.#......#........#......#....
...#.#....#.#......#.#....#...#....#.#......#.#....#.#...
..#...#..#...#....#...#..#.#.#.#..#...#....#...#..#...#..
.#.#.#.##.#.#.#..#.#.#.##.......##.#.#.#..#.#.#.##.#.#.#.
#......##......##......###.....###......##......##......#
##....####....####....##.##...##.##....####....####....##
.##..##..##..##..##..###.###.###.###..##..##..##..##..##.
######################.#.#.#.#.#.#.######################
.....................#.............#.....................
</pre>
 
Anonymous user