in reply to Life!

Nice. You've managed to be fundamentally a lot terser than my version, probably by not generalizing so much. Yours can still be golfed down a good bit by using the usual dirty tricks, of course (like, using the trinary ?: operator instead of regular if/elsif/else blocks), but it's already about half as long as mine and probably more portable to boot :-)


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

Replies are listed 'Best First'.
Re: Re: Life! (golf)
by cLive ;-) (Prior) on Mar 20, 2004 at 02:46 UTC
    you mean, something like this? :)
    use Storable 'dclone';for$y(0..23){$l[$_][$y]=int(rand 7)?0:1for(0..79 +)}while(1){@f=@{dclone\@l};print"\033[2J";for$y(0..23){for$x(0..79){p +rint$l[$x][$y]?O:" ";$n=0;for $h(-1..1){!$_&&!$h or$n+=$l[($x+$_)%79] +[($y+$h)%23]for-1..1}$l[$x][$y]?$n<2||$n>3?$f[$x][$y]=0:0:$n==3?$f[$x +][$y]=1:0}print$/}@l=@{dclone\@f};sleep 1}

    cLive ;-)

      Yeah, something like that. I managed to save another dozen strokes, though...

      use Storable 'dclone';@l=map{[map{int rand 7?0:1}0..23]}0..79;while(1){@f=@{dclone\@l};print"\033[2J";for$y(0..23){for$x(0..79){print$l[$x][$y]?O:$";$n=0;for$h(-1..1){!$_&&!$h or$n+=$l[($x+$_)%79][($y+$h)%23]for-1..1}$l[$x][$y]?$n<2||$n>3?$f[$x][$y]=0:0:$n==3?$f[$x][$y]=1:0}print$/}@l=@{dclone\@f};sleep 1}

      It's probably possible to do still better by devious means, but that's as short as I can make it without changing the logic. I'm not really a golf pro.


      ;$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$;[-1]->();print
Re: Re: Life!
by teamster_jr (Curate) on Mar 19, 2004 at 11:03 UTC
    or indeed my version, but it's a hell of a lot more portable!
    ++.
    al