Elementary cellular automaton/Infinite length: Difference between revisions

(→‎{{header|Haskell}}: Added Haskell solution)
(→‎{{header|Tcl}}: added zkl)
Line 710:
….##..#...###..####...##.#####...#.#####.#..#.....#.…
.##.####.##..###...#.##..#....#.##.#.....#####...###.
</pre>
 
=={{header|zkl}}==
{{trans|D}}
<lang zkl>nLines,flipCell := 25, fcn(c){ (c=="1") and "0" or "1" };
foreach rule in (T(90,30)){
println("\nRule: ", rule);
ruleBits:="%08.2B".fmt(rule); // eg 90-->"01011010"
neighs2next:=(8).pump(Dictionary(),
'wrap(n){ T("%03.2B".fmt(n), ruleBits.reverse()[n]) });
C:="1"; // C is "1"s and "0"s, I'll auto cast to Int as needed
foreach i in (nLines){
println("%2d: %s%s".fmt(i," "*(nLines - i), C.translate("01",".#")));
C=String(flipCell(C[0])*2, C, flipCell(C[-1])*2);
C=[1..C.len()-2].pump(String,'wrap(n){ neighs2next[C[n-1,3]] });
}
}</lang>
{{out}}
<pre>
Rule: 90
0: #
1: #.#
2: #...#
3: #.#.#.#
4: #.......#
5: #.#.....#.#
6: #...#...#...#
7: #.#.#.#.#.#.#.#
8: #...............#
9: #.#.............#.#
10: #...#...........#...#
11: #.#.#.#.........#.#.#.#
12: #.......#.......#.......#
13: #.#.....#.#.....#.#.....#.#
14: #...#...#...#...#...#...#...#
15: #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#
16: #...............................#
17: #.#.............................#.#
18: #...#...........................#...#
19: #.#.#.#.........................#.#.#.#
20: #.......#.......................#.......#
21: #.#.....#.#.....................#.#.....#.#
22: #...#...#...#...................#...#...#...#
23: #.#.#.#.#.#.#.#.................#.#.#.#.#.#.#.#
24: #...............#...............#...............#
 
Rule: 30
0: #
1: ###
2: ##..#
3: ##.####
4: ##..#...#
5: ##.####.###
6: ##..#....#..#
7: ##.####..######
8: ##..#...###.....#
9: ##.####.##..#...###
10: ##..#....#.####.##..#
11: ##.####..##.#....#.####
12: ##..#...###..##..##.#...#
13: ##.####.##..###.###..##.###
14: ##..#....#.###...#..###..#..#
15: ##.####..##.#..#.#####..#######
16: ##..#...###..####.#....###......#
17: ##.####.##..###....##..##..#....###
18: ##..#....#.###..#..##.###.####..##..#
19: ##.####..##.#..######..#...#...###.####
20: ##..#...###..####.....####.###.##...#...#
21: ##.####.##..###...#...##....#...#.#.###.###
22: ##..#....#.###..#.###.##.#..###.##.#.#...#..#
23: ##.####..##.#..###.#...#..####...#..#.##.######
24: ##..#...###..####...##.#####...#.#####.#..#.....#
</pre>
Anonymous user