http://qs1969.pair.com?node_id=292590

I was messing around with closures, looking for something interesting to do (other than the obvious JAPH or quine) and came up with this...

#!/usr/bin/perl -- -*- cperl -*- my%t=('H'=>[99,6,0,3,4,0,1],'*'=>[5,3,1,2,1,2,11],'O'=>[7,9,0,4,8,3,4] ,'x'=>[12,3,0,1,9,2,4],'+'=>[17,3,0,1,9,2,4],);sub _{my($x,$y,$t)=@_;$ g[$x][$y]=l($t,$x,$y)}sub l{my($t,$x,$y,$a)=@_;+{v=>$t,i=>sub{++$a;my( $n,$s,$o);my@t=@{$t{$t}};for$u(-1..1){for$z(-1..1){$n=$g[$x+$u][$y+$z] ;if($n->{v}eq$t){++$s}elsif($n->{v}){++$o}}}if($s<$t[2]or$s>$t[1]or$o> $t[4]or$o+$s<$t[5]or$a>$t[0]){undef$g[$x][$y]}if(rand(10)<$t[6]or$s==$ t[3]){my($v,$w)=map{rand(42)%3-1}0..1;$v+=$x;$w+=$y;$g[$v][$w]=l($t,$v ,$w)if not$g[$v][$w];}}}}map{_($$_[0],$$_[1],"H")}([20,10],[20,9],[21, 10],[21,9]);_(40,10,'*');_(39,10,'*');map{my$q=$_;map{_($_,$q,'O')}(29 ,30)}(18,19);_(30,3,"+")^_(29,3,"x");while($:){&c;for$y(1..22){for$x(1 ..60){if($m=$g[$x][$y]){print$$m{v};$$m{i}->()}else{print" "}}print$/} print$/;sleep 1}sub c{`clear`}#To support Win32 make that sub c{`cls`}

If you let it run, it becomes obvious relatively quickly that the fast-growth type won't last, but it takes a bit longer to see what happens between the others. See if you can predict it before it becomes blindingly obvious. (Hint: it's not just how any two types interact with eachother, but how they interact with the others, too. For example, if you remove the symbiotic pair, the interaction between the close-packing and slow-growth types changes.)

Okay, so it's not the most original concept ever... but hey, when I did it in QBasic in 1994, it didn't use a functional paradigm, so that's something.


$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/