Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Goofy leaping ninja stickmen

by davido (Archbishop)
on Oct 07, 2003 at 21:18 UTC ( #297394=note: print w/ replies, xml ) Need Help??


in reply to Goofy leaping ninja stickmen

Great obfu. Funky!

Just as a matter of curiosity I tore into it and made a few modifications:

  • Pushed everything that is to be printed into an array so that the script could get away with only one print, with less processing inside the print function, for a little better (maybe?) output efficiency.
  • Changed sleep 1 to select, with a timeout of .2 sec., for smoother action without loss of synchronization.
  • Golfed it down as much as I could without changing logic, flow, or behavior. Saved 82 keystrokes.
  • Reformatted script for seventeen full lines and one partial, plus the shebang.

Here's the result:

#!/usr/bin/perl sub r{int rand pop}++$|;@g=map{[map{' '}0..$=]}0..25;my$j=pop||2+r 3; @f=map{my$k=my$n=$b++;my$z=1;my$x=r$=;;my($q,$v,$e)=my@l=(0x4);my$h=r 9;$w={i=>sub{$k=r$j while$k==$n or!$f[$k];my$o=$f[$k];$h+=$e?-1:1;if( $h<1){$e=0;$k=$n}$e=$h>6?1:$e;if(!$z){my$u=$x<$$o{x}()?1:-1;$u*=$e>1? -1:1;$q=$e?$u*r 7:0;$q||=4if$e>1;$v=r 6 if($e&&r(7)>3)}my$t=($$o{z}() cmp$z)+1;$t=0if$x==$$o{x}();my$s=$x<$$o{x}()?1:0;for(0,2){$l[$_+$s]+= $t cmp$l[$_+$s]}for(0,2){$l[$_+($s?0:1)]=0}$v-=2if$z;$x+=$q;$z+=$v;$z =0if$z<0;if($x<2){$x=2;$q*=-1if$q<0}if($x>$=-2){$x=$=-2;$q*=-1if$q>0} if((abs($x-$$o{x}())+1)*(1+abs($z+1-$$o{z}()))<9){r 2?$$o{c}($n)||($e =1):${$f[$n]}{c}($k)}},d=>sub{$g[20-$z][$x]='O';$g[21-$z][$x]='+';$g[ 22-$z][$x]='|';for(0,1){my@c=$_?qw!/ - \\!:qw!\\ - /!;$g[21-$z][$x+($ _?1:-1)]=$l[$_]?'-':$c[2];$g[22-$z-$l[$_]][$x+($_?2:-2)]=$c[2-$l[$_]] ;$g[23-$z][$x+($_?1:-1)]=$l[2+$_]>1?'-':$c[2];$g[24-$z-($l[2+$_]>1?1: 0)][$x+($_?2:-2)]=$c[$l[2+$_]>1?1:2]}},z=>sub{$z},x=>sub{$x},n=>sub{$ n=pop},c=>sub{$h=0;$e=2;$k=pop;$q=0;if(!r(7)){splice@f,$n,1;$$_{n}($h ++)for@f;}}}}1..$j;while(1){exit if@f==1;for$m(@f){$$m{i}();$$m{d}()} my@n;for$a(1..25){push@n,join'',"$/|",@{$g[$a]},'|';@{$g[$a]}=map{' ' }0..$=}print$/x$=,@n;select$c,$c,$c,.2}
Loved the obfu. Good job! Wading through the maps and logic was quite a challenge. Especially the outtermost map, with a hashtable of subs inside.... ugg, what a mess! That's not a bad thing, in the context of a fantastic obfu. Keep it up!


Dave


"If I had my life to do over again, I'd be a plumber." -- Albert Einstein


Comment on Re: Goofy leaping ninja stickmen
Download Code
Re: Goofy leaping ninja stickmen
by jonadab (Parson) on Oct 07, 2003 at 21:33 UTC

    ++ for pointing out that select can be used this way; I had thought it had to do with filehandles, and had not realised this use for it.

    As for the rest of your improvements... well, I'll have to look at those when I have more time.

    update: I've looked at them now, and they all seem pretty straightforward; you just did a more thorough job of golfing than I.


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://297394]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2014-12-25 15:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls