Elementary cellular automaton: Difference between revisions

Content added Content deleted
m (Updated description and link for Fōrmulæ solution)
(Added Quackery.)
Line 2,531: Line 2,531:
23: #.#.#.#.#.#.#.#.................#.#.#.#.#.#.#.# ##.####..##.#..###.#...#..####...#..#.##.###### #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#
23: #.#.#.#.#.#.#.#.................#.#.#.#.#.#.#.# ##.####..##.#..###.#...#..####...#..#.##.###### #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#
24: #...............#...............#...............# ##..#...###..####...##.#####...#.#####.#..#.....# #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.# </pre>
24: #...............#...............#...............# ##..#...###..####...##.#####...#.#####.#..#.....# #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.# </pre>

=={{header|Quackery}}==

<lang Quackery> ( the Cellular Automaton is on the stack as 3 items, the )
( Rule (R), the Size of the space (S) and the Current )
( state (C). make-ca sets this up from a string indicating )
( the size and starting state, and a rule number. )

[ [] swap
8 times
[ dup 1 &
rot swap join
swap 1 >> ]
drop swap
dup size swap
0 swap reverse
witheach
[ char # =
dip [ 1 << ]
+ ] ] is make-ca ( $ n --> R S C )

[ $ "" unrot
swap times
[ dup 1 & iff
[ char # ]
else
[ char . ]
rot join swap
1 >> ]
drop echo$ cr ] is echo-ca ( S C --> )

[ dip bit
2dup 1 & iff
| else drop
1 << swap
over & 0 != | ] is wrap ( S C --> C )

[ rot temp put
dip dup 0 unrot wrap
rot times
[ dup 7 &
temp share swap peek if
[ i^ bit rot | swap ]
1 >> ]
drop temp release ] is next-ca ( R S C --> C )
[ dip
[ over echo$ cr
make-ca ]
1 - times
[ dip 2dup next-ca
2dup echo-ca ]
2drop drop ] is generations ( $ n n --> )

say "Rule 30, 50 generations:" cr cr
$ ".........#........." 30 50 generations</lang>

{{out}}

<pre>Rule 30, 50 generations:

.........#.........
........###........
.......##..#.......
......##.####......
.....##..#...#.....
....##.####.###....
...##..#....#..#...
..##.####..######..
.##..#...###.....#.
##.####.##..#...###
...#....#.####.##..
..###..##.#....#.#.
.##..###..##..##.##
.#.###..###.###..#.
##.#..###...#..####
...####..#.#####...
..##...###.#....#..
.##.#.##...##..###.
##..#.#.#.##.###..#
..###.#.#.#..#..###
###...#.#.#######..
#..#.##.#.#......##
.###.#..#.##....##.
##...####.#.#..##.#
..#.##....#.####..#
###.#.#..##.#...###
....#.####..##.##..
...##.#...###..#.#.
..##..##.##..###.##
###.###..#.###...#.
#...#..###.#..#.##.
##.#####...####.#..
#..#....#.##....###
.####..##.#.#..##..
##...###..#.####.#.
#.#.##..###.#....#.
#.#.#.###...##..##.
#.#.#.#..#.##.###..
#.#.#.####.#..#..##
..#.#.#....#######.
.##.#.##..##......#
.#..#.#.###.#....##
.####.#.#...##..##.
##....#.##.##.###.#
..#..##.#..#..#...#
######..########.##
......###........#.
.....##..#......###
#...##.####....##..
##.##..#...#..##.##
</pre>


=={{header|Racket}}==
=={{header|Racket}}==