Got some code which would take a Perl grand master to understand without running it? Post it in this section so we can stare at it in awe.

Word of warning, though: Don't be too cocky with your post — almost inevitably someone will post a reply that does the exact same thing in even fewer characters!

New Less than Readable Code
First Japh
No replies — Read more | Post response
by blindfire
on Oct 20, 2008 at 17:34
    I don't think I've seen one based on this mechanic:
    s..//s:sy/:/ssy/ss::y:/ss:y:/:ssy/s://y:s///;////:ys:::/;///:sy/s://y: +s///y/::s/y/://:;s///:y/:/s/y//:::y://s:y:/::/y:://:;///:/y/://sy//:/ +/y/:/s:y:s//:ys/:::y/:s::;///s:y/:s//y:s///y//s::y:/:/:y:/::/;///:sy/ +/s:/y/:///y/:s::y:/:ss.;y,y/:s;,|01./,;$/=$_;map{$;=(sprintf'%05b',$_ +);print+chr((eval'0b'.join'',map{eval'$;=~m/('.(split?/?,$/)[$_].')/? +1:0'}0..6)+32)}1..25
    any tips to golf it down a bit, while maintaining reasonable obfuscation?
Coding in smileys
4 direct replies — Read more / Contribute
by biga
on Sep 27, 2008 at 06:44
    Not as stylish as Emotijaph, but whatever... %-)
    #!/usr/bin/perl %) =( $( %( 8-( 8^( $-) ?O_o &-[ 8-( 8) ]:0) )=> $) ,) ;#( $_= X-() ?o_O :q :] #-- Just A.Smiley :| (); s:] .\ *( \#-) \-: :x ;-y ;) <~.Smiley; Another one ~> (; ;s :() [^; ]: Hacker-Smiley: #B-] ;#) Cthulhu Smiley: {:=E ;{ s:( \S*) ?-( \S*) \s*() $:\2 \1:x ;} print ;0| print+q; =B-] ;=> %) &~()
Place your bets
1 direct reply — Read more / Contribute
by olus
on Sep 26, 2008 at 11:18

    For use when bored or the bamboo sways.

    • 1 to 5 and enter to select cards
    • 1 to 5 and enter to unselect cards
    • d to refresh hand after selecting cards
    • d for a new hand
    • q to quit

    Unfortunately you'll have to hit the 'download' link to see the art, and it is not guaranteed to work on all terminals. Nothing hidden, it's just pure char arrangement.

    @n =(2,3,4,5, 6, 7, 8, 9, 10 ,'J','Q', 'K', 'A');$C =50; $R =''; $e= 0;@c = map{ "\e[31m".$_. " h"} @n; @p = map{ "\e[32m".$_." c"}@n;@o=map{"\e[31m". $_." d"}@n;@e=map {"\e[32m".$_." s"} @n;@D;(%p,@H,@h);%seen;sub cls{print "\e[1J\e[H";}d();$/=\1;$i;while( $i= <STDIN> ) {last if($i eq 'q');if(($i>=1)&&($i<=5)) {$h[$i-1] =( $h [ $i -1] == 0) ?1:0;p(); }if($i eq 'd'){ if ( $e ){ d () if($C>0);$e= +0;} else{$e=1;f();}}}sub b{my @d= (@c,@p,@o,@ +e);@D= ();while(@d){push@D,splice (@d, rand (@d), 1);}@H= +();push@H , shift@D for 0..4 ; } sub p { cls( ); print "\n\t\t\tCr +edit:$C\n"; for(0..4) { if($h[$_] == 1){print " H ";}else{print " +";}}print"\n" ; print" ".$H[$_]." " for 0..4; print "\e[0m\n\n\t\t\t$R\n\n\n"; i +f( $e==0){print "Cards to hold ([d]eal):";} else{if($C>0){print"[d]eal again or [q]uit +?:";}else{print "No more credits. You must [q]uit:";} }}sub f(){ for(0..4){if($h[$_]== +0){$H[$_]=shift @D;}} P(); p();}sub d{ %p= ('p' => 0 ,'t'=>0,'k'=>0,'f'=>0,'s' +=>0,);@h=(0,0 ,0,0,0); $R=''; $e= 0; $C-- ; b() ;p() ; } sub P{ @v = + map{ $_=~ /m(.*) /; $1}@H;for( 0.. $#v){ if($v[$_]eq'J') {$ +v[$_]= 11 ;}elsif($v[$_]eq'Q') {$v [$_]= 12;}elsif($v[$_] +eq'K'){ $v[$_] = 13 ;} elsif($v[ $_]eq'A'){$v[ +$_]= 14;}}@v= sort@v;if (($v[4]-$v +[ 0])==4){for(1 ..4){ if($v[$_] ==$v[$_-1]+1 ){ $p{ 's'}=1;}else{$p{'s' }=0;last;}}}%seen=();map{ $seen{$_}++} @v; foreach$k(keys %seen){if($seen{$k}==2){$p{'p'}++;}if($seen {$k}==3){$p{'t'}=1;}if($seen{$k}==4){$p{'k'}=1;}}if($p{' +t'} &&$p{'p'}) {$p{'f'}=1;}if($p{'s'}){$R='Sequence!';$C+=6;}elsif( +$p{'f'} ){$R='Fullhouse!'; $C+=4; } elsif( $p{'k'} ){ $R= 'Poker!'; $C += 10; +} elsif ($p{'t'} ){$R='trio';$C+=2;}elsif($p{'p'}){$R="$p{'p'}pair"; $C++;}@h =(0,0,0, +0,0);}print"\n";

    Have fun.

Function JAPH
No replies — Read more | Post response
by lamp
on Sep 05, 2008 at 09:56
    #!/usr/bin/perl $__= qq(=!<=>==!<= alarm=! binmode>==!<=>= uc=! bind>= chr: chop<= defined>= do<= crypt=! exec<= lc=! read<= log: next>= msgget=! open<=); map{$__.=$_} <DATA> ;$__ =~ s/\n//g ;$__ =~ s/\s//g; ;$__ =~ y/[a-z]/ / ;$__ =~ s/=!|<=/_\//g ;$__ =~ s/>=/_\//g ;@__= split(/:/,$__); eval{use Time::HiRes qq(sleep)}; map{@___ = split("",$_); map{ print ;$|=((2*2)/4); sleep((((2*2)*2)) /((((((1*16)*5)*2)*5)*2) /(2*5))); }@___; print"\n";}@__; __END__ pipe=!<=>==! no>==!<==! ref:>= my<= rmdir=!=!<=>==! sin>= setpwent<= time=! vec:<=>==! wait<= setgrent>= uc>= getpwent=! kill>= rmdir
A feature of use
4 direct replies — Read more / Contribute
by ambrus
on Aug 19, 2008 at 15:57

    Look at the following snippet.

    perl -e 'open strict, ">&", STDOUT or die; use strict; print strict fo +obar, "\n";'

    This prints foobar so clearly foobar is interpretted as a bareword. However, we use strict, so that should disallow barewords. Why is this? (The title of the post can give a hint.)

Strange-looking Pie
1 direct reply — Read more / Contribute
by betterworld
on Aug 09, 2008 at 18:42

    Hi,
    I have to admit that this number looks a bit scrawly; however, the output from the program appears to be a lot more precise ;-)

    $|++;$_L=$K= '.';$([199].=$_L.=join 10 ,<{\\{,\\}}>; for((@()){ undef$ };*::a={a,$K.$ T,*$=\$:};$$=Y x(((666)));{$; =$$?join$$,$$,$a {a}:$_L;$;=~tr )Y).);**= \$$$;$*=l1 unless 0|| defined $*;$*=~# s{$a{a}} $die unless$g; for($S=$*.$} ){($*)=m(^(?: $;)*($a{a}*) \z)x;$==s $\$;$\$\$$xg ;;y;Y;;dc;y;Y ;z;;m.\.*..[$} =$& ]}redo if chop$$ ;}if(($! =$==~y cccc )!=!!$!){$= -=$=;$__ ++;}$__.=$= ;$__=~s"^(.+)([ -8])"\2"and do{print$1, $K;$T.=chop$K}} print "$__\n"
JAPHs that depend on the version of the module
1 direct reply — Read more / Contribute
by Tux
on Jul 31, 2008 at 07:32

    Following a nice thread in perl5 porters (where you can find the explanation):

    perl -lap -0777 -e'BEGIN{close STDIN;require Text::CSV_XS}$F[$#F/6-$=] +=~s/=b/h/;$_="@F[257,679,435,791]er"'

    Enjoy, Have FUN! H.Merijn
Tristable oscillator
1 direct reply — Read more / Contribute
by Prof Vince
on Jul 08, 2008 at 17:08
    use strict; use warnings; local $\ = "\n"; local $_ = 'y,ys,sy,,s,ys,sy,'; for my $n (1 .. $ARGV[0] || 10) { print; eval; } print;
    It's not really that hard to understand. Do you have longer ones of this kind ?
Sudoku solver
No replies — Read more | Post response
by waldner
on Jun 11, 2008 at 14:38

    This is a simple sudoku solver (if written unformatted, it's about 7x80-char lines of code). I'm a beginner in Perl, and this looked like a good first program, but of course there are surely many naiveties in the code. Any criticism/remark/comments welcome.

    use strict; use warnings;my @r; sub r{my $l=shift;my%x=(); for(0..8){$x{int($l/9)*9+$_}="" ;$x{($l%9)+($_*9)}="";}my$k=int($l /27)*27+int( ($l%9)/3)*3; @x{$k..$k+2, $k+9..$k+11, $k+18..$k+20 }=("")x9; delete $x{$l}; return %x;}sub v{for(0..80){ next if($_[$_ ]eq".");return 0 if (join("", @_[@{$r[$_]}]) =~/$_[$_]/) } return 1}sub z{ my($p,@s)= (shift,@_); v( @s)||return 0; print"Cur: ", @s;for(;$s[$p ]ne".";$p++){ return print"end: ",@s if($p==81); }for(1..9){$s[$p]=$_;return 1 if (z($p+1,@s));}}for(0..80){my %r=r($_);$r[$_]=[keys %r]; };z(0,split(//,<>));

    To use it, just give it the 81-chars string representing the board on stdin, eg

    echo ".21.3.74.9.8...1 (snip) 3.9.65.1.42." | sudoku.pl

Guess what it does ... and a challenge
6 direct replies — Read more / Contribute
by liverpole
on May 24, 2008 at 13:42
    First, can you guess what the following code does before running it? ...
    1x~@;

    This node by shmem gave me the idea, and may give you a hint as well.

    Now for the challenge ... what's the shortest program which does the same thing?  My guess is the obvious:

    How about the smallest program that does the same thing slowly?  The following takes about 11 seconds on my laptop:

    I have no idea if a shorter such program exists.


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Set the new obfuscation standard
Title:
code@?#!:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":


  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.