The following code runs a one-dimensional cellular automaton.

Code runs until interrupted.  You can change the definitions in the
first two lines to set the scrolling speed of the simulation and the
number of cells to be simulated (which should be less than the width
of your terminal so that lines aren't broken).

   sleepamt=: %40
   columns=: 70
   sleep=: '/lib/libm.so.6 select > i i x x x *x' (15!:0) 0;0;0;0;
[:<._ 1e6#:*&1e6
   0[ (([:sleep]&sleepamt)] [:1!:2&2&.({&' #') 1 3 5 6 e.~ 3 #.\ 0
0&,) ^:_]columns$1
##
###
## #
####
##  #
### #
## ##
######
##    #
###   #
## #  #
####  #
##  # #
### # #
## ## #
#######
##     #
###    #
## #   #
####   #
##  #  #
### #  #
...


It would be nice if I could use the definition (sleep=: 6!:3) for the
delays, but that doesn't work because it seems it rounds the time to
whole seconds.

What's your favorite one-dimensional cellular automaton?  Is there one
with simple enough rules to code it in one line (such as this one)
that gives a more interesting output?

Ambrus
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to