 Syntactic Confectionery Delight PerlMonks

### Obfuscated code

 Need Help??

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!

 Advent of Code, Day 15, golfed! 1 direct reply — Read more / Contribute by Jasper on Dec 17, 2021 at 12:32 I was doing the advent of code (https://adventofcode.com/2021/), until I got to day 16, started to read the instructions, got about a third of the way through, and decided that that was enough for the year! LOL However, I really enjoyed day 15, on finding the score path of least resistance through something like ```19999 19111 19191 19191 11191 [download]``` which (being a non-computer scientist), started as a recursive path-finding algorigthm. That worked for tiny sample grids, but for bigger grids (the problem grid was 100x100), I needed to start being clever, so I started remembering the lowest score to a position, and then if I came across that position again with a lower score, I could say, oh, now the score from there can now be this. Then I realised I'd have to start adjusting scores for every point I'd ever moved to (etc.) any previous time I'd been to that point and that became an absolute nightmare. I eventually ended up googling shortest path algorithms, and implementing Dijkstra's shortest path method. Then the golfing started :) I've ended up with this: ```# run with perl -ln prog.pl input push@a,/./g;\$r||=@a}{print\$s{-1+map{\$u{\$_}||=\$a[\$_]+\$s{\$g-1}for grep\$a[\$_]*!\$s{\$_},\$g+\$r,\$g-!!(\$g%\$r),\$g-\$r*(\$g>=\$r),++\$g*!!(\$g %\$r);(\$g)=sort{\$u{\$a}-\$u{\$b}}keys%u;\$s{\$g}=delete\$u{\$g}}@a} [download]``` So, the idea is to enter the maze at the top left and work out what the score of the path is (with no diagonal moves) ending up bottom right. The input is always a square in AoC/2021/15. Dijkstra's algorithm says put the starting position in your tree set (%s) with a score, then add the positions (and the aggregate scores) you can move to the unused set (%u), choose from unused the position with the lowest aggregate score, delete that from unused, add it to the tree set. From that new position, calculate the scores of the positions you can move to from there and continue. Here's my golfed solution blown up: ```1 push @a,/./g; 2 \$r||=@a 3 }{ 4 print \$s{ 5 -1 + map{ 6 \$u{\$_}||=\$a[\$_]+\$s{\$g-1} for 7 grep \$a[\$_] * !\$s{\$_}, 8 \$g+\$r, 9 \$g-!!(\$g%\$r), 10 \$g-\$r*(\$g>=\$r), 11 ++\$g*!!(\$g %\$r); 12 (\$g)=sort{\$u{\$a}-\$u{\$b}}keys%u; 13 \$s{\$g}=delete\$u{\$g} 14 }@a 15 } [download]``` The }{ at line 3 means (when you run with perl -ln) that the lines above are run on each line of input (with the input as \$_) and those below are run after all the input has been read. So, line 1 when the input is read, I'm filling @a with each digit in the maze. It's a single digit array, so I have to be a little bit cleverer later when working out what "coordinates" I can move to from the current position. Line 2 I'm taking the width of the grid, and the ||= just means don't overwrite this when reading input lines 2, 3, 4... or you'd be remembering it wrong! Lines 5-14 is the meat of the map loop, over @a. As I said above, for Dijkstra's algorithm you choose an unused position from your grid and move it into the tree set on each loop, so mapping over @a gives us enought loops to score the entire grid. Line 6-11 is finding the next possible moves, and putting them into the unused hash %u, with a score. \$g is the current position, \$r is the width of the grid, so on lines 8-11 are the possible moves: move down \$g+\$r - if we're on the last row, \$a[\$g+\$r] is out of range and 0, the grep on line 7 filters it out, move left \$g-!!(\$g%\$r) - so \$g-1 if \$p%\$r (i.e. we're not in the first column) otherwise \$g, and because \$s{\$g} exists (that's the position we're in currently), that won't pass through the grep move up \$g-\$r*(\$g>=\$r) if we are on row two or more, \$g>=\$r is true (1), so we pass through \$g-\$r*1, otherwise \$g-\$r*0 (\$g, which gets filtered) move right ++\$g*!!(\$g %\$r) - which is (\$g+1)*!!((\$g+1)%r) with a lot less bracketing - checking if we're in the rightmost column, and passing \$g+1 or \$g. Those 4 positions get filtered by \$a[\$_] * !\$s{\$_} - i.e. is this a valid position with a score in the grid (luckily 0 wasn't a valid score in this AoC), and it hasn't already been put in the set %s. Line 6 - So now we have valid, unused position, we score them, and assign them to the unused hash %s: \$a[\$_] is the score of the position, and \$s[\$g-1] is the score of the current position (we did ++\$g in line 11, remember, so we have to subtract 1. The ||= we have, because you can move to all positions from more than one place, so we've possibly seen this location before, and if we have seen it before, it had a lower score (or the same score) last time. So now we have added some more unused possibles positions, and the scores to get there, to the %u hash, in line 12 we choose the lowest scoring one of those, and in line 13 we remove it from %u, and put it in %s. Actually, the first time we go through this loop, \$g is undef. Dijkstra says you should assign the starting position to %s at the beginning, but it turns out we don't need to do that explicitly. Since we start with undef, 0 for \$a[\$g] purposes, in the top left, means that \$g-!!(\$g%\$r) gets passed through, so 0 and a score (not the right score for starting at 0, but who cares, this is golf) will eventually get assigned to %s. At this stage, we have done the whole loop, so we finish with the print \$s{-1+ map{...} @a  }, sort of equivalent to \$s{\$#a}, the path score of the last element of @a. And that's that. Hope that was clear enough! Hope those of you who are continuing with Advent of Code are still enjoying it. Merry Christmas! A twisty little maze of ampersands, all different 1 direct reply — Read more / Contribute by haj on Jun 08, 2021 at 18:54 The following code prints a 0, a 1, a 2, and an empty line. But which is which? ```use 5.020; sub one { 1 } sub two { 2 } say one&two ; say &one&two ; say &one&&&two ; say &&&one&&&two; [download]``` It is not that difficult to figure out, it was a accidental discovery while messing around with syntax highlighting. For the friends of JAPH, here's one with five consecutive ampersands: ```use 5.020; sub s { say }; \$_ = 'Jusst another Perl hacker'; s&s&&&&&s [download]``` reftype obfu -- oneliner 1 direct reply — Read more / Contribute by Discipulus on Apr 22, 2021 at 16:06 perl -MScalar::Util=reftype -e "\$}=qr/=.=/,print+(join\$\,map{chr(ord(\$_)-8)}((reftype\$})=~/./g))=~s/\$}/A/r" or perl  -e "\$}=qr/=.=/,print+(join\$\,map{chr(ord(\$_)-8)}((uc ref\$})=~/./g))=~s/\$}/A/r" L* There are no rules, there are no thumbs.. Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS. The Backslash Challenge 4 direct replies — Read more / Contribute by choroba on Mar 24, 2021 at 16:12 To return the character that's used as the delimiter in a quote-like operator, you can use a backslash. ```'/' eq q/\// or die "Failed"; [download]``` Your task is to return a backslash using a backslash as the delimiter. Use qq\\ for level easy, use q\\ for level guru. There are definitely many ways how to do it for level easy. I haven't found a way how to do it with the single q. map{substr\$_->,\$_->||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3] The IP address I'd like to own -- oneliner 1 direct reply — Read more / Contribute by Discipulus on Mar 16, 2021 at 03:13 perl -MSocket -le "print eval inet_ntoa(inet_aton([gethostbyaddr(inet_aton('74.65.80.72'),AF_INET)]->))" L* There are no rules, there are no thumbs.. Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS. Emoji can be hard to see on the command line 1 direct reply — Read more / Contribute by kcott on Feb 06, 2021 at 14:16 ++eyepopslikeamosquito's post (a reply in an unrelated SoPW thread) inspired me to look at Acme::EyeDrops. After playing around with that module for a bit, I realised that some of the obfucation code images looked a bit like blown-up versions of emoji. It then occurred to me that not only could I get large, very easy to see, representations of emoji, but I could also use those images to get back the original Unicode® emoji character. Here's a couple of examples. Firstly, a very straightforward one that only required one shape. ```\$ perl -C -e 'print "\x{1f56f}\n"' 🕯 ``` ```\$ cat candle.txt ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( '' ) ) ))) ) ) ) ) ) ))))) ) =~("\(". ( ( '?')).'{' . ( ( '`')|'%') .('['^ ( '-') ) . ( '`'|'!') . ('`'|"\,"). '"'.('['^"\.").( '['^'(').('`'|('%')).( '{'^'[').('`'|'/').(('[')^ '+').('`'|'%').('`'|'.').( '{'^'[').('['^'*').("\["^ ',').'\\'.'{'.':'.(('[')^ '(').('['^'/').('`'|'\$').( '{'^'[').':'.('`'|'%').('`' |'.').('`'|'#').('`'|"\/").( '`'|'\$').('`'|')').(('`')| '.').('`'|"'").'('.(('{')^ '.').('{'^'/').('`'^'&' ).'-'.(':'&'=').')'.''. '\\'.'}'.';'.('!'^'+'). ('['^'+').('['^(')')).( '`'|')').('`'|'.').('[' ^'/').('{'^'[').('\\'). '"'.'\\'.'\\'.('['^'#') .'\\'.'{'.('^'^('`'|'/' )).('`'|'&').('^'^('`'| ( '+'))).('^'^('`'|'(')). ('`'|'&') .'\\'.'}'.'\\'.('\\').( ( ( '`'))|('.')). '\\'.'"'.';'.('!'^'+'). ( '"')."\}". ')');\$:='.'^"\~"; \$~='@'|'(';\$^=')'^"\["; \$/='`'|'.';\$,='(' ^+ '}';\$\='`'|'!';\$:=')'^'}';\$~='*'|'`' ;\$^='+'^'_';\$/="\&"| (( '@'));\$,='['&'~';\$\=','^'|';\$:='.'^'~';\$~='@'|'('; (\$^) =')'^'[';\$/='`'|"\."; \$, = ( ( ( '(')))^"\}"; \$\='`'|'!';\$:= ')'^'}';\$~='*'|'`' ;\$^='+'^'_';\$/='&' |(( '@' )); [download]``` ```\$ perl -Mre=eval candle.txt 🕯 ``` And a tad more complicated one that required two shapes. ```\$ perl -C -e 'print "\x{1f459}\n"' 👙 ``` ```\$ cat bikini.txt ''=~('('. '?'.'{'.( (( (( (( (( (( (( (( (( (( (( ( (( (( (( (( (( (( (( (( (( (( (( (( ( (( (( (( (( (( (( ( ( (( ( (( (( ( (( (( (( ( (( (( (( ( ( (( (( ( (( (( (( (( ( (( ( (( (( ( (( (( (( (( '`' )))) ) )) )))) ))))) )) )) )))))) ))))))) )) )) ))))))) ))))))))) )) )) ))))))))) ))))))))))))) ))))))))))))) ))))))))))))) ))))))))|'%'). ('['^'-').('`'| '!').('`'|"\,"). '"'.('['^'.').('['^ '(').('`'|('%')).( '{'^'[').('`'|"\/").( '['^'+').('`'|('%')).( '`'|'.').('{'^'[').("\["^ '*').('['^',').'\\'.('{'). ':'.('['^'(').('['^('/')).( '`'|'\$').('{'^'[').':'.("\`"| '%').('`'|'.').('`'|'#').('`'|'/').('`'|'\$').('`'|')').('`' |'.').('`'|"'").'('.('{'^'.').('{'^'/').('`'^'&').('-').( ':'&'=').')'.'\\'.'}'.';'.('!'^'+').('['^'+').('['^')') .('`'|')').('`'|'.').( '['^'/').('{'^('[')). '\\'.'"'.('\\'). '\\'.('['^'#'). '\\'.'{'. ('^'^('`' |'/')).('`'|'&').('^'^('`'|'*')).('^'^('`'|'+')).((';')& '=').'\\'.'}'.'\\'.'\\'.('`'|'.').'\\'.'"'.';'.('!'^'+') .'"'.'}'.')');\$:='.'^'~';\$~='@'|'(';\$^=')'^'[';\$/=('`')| '.';\$,='('^'}';\$\='`'|'!';\$:=')'^'}';\$~='*'|'`';\$^="\+"^ '_';\$/='&'|'@';\$,='['&'~';\$\=','^'|';\$:='.'^'~';\$~="\@"| '(';\$^=')'^'[';\$/='`'|'.';\$,='('^'}';\$\='`'|'!';\$:="\)"^ '}';\$~='*'|'`';\$^='+'^'_';\$/='&'|'@';\$,='['&'~';\$\ =','^'|';\$:='.'^'~';\$~='@'|'(';\$^=')'^'[';\$/ ='`'|'.';\$,='('^'}';\$\='`'|'!';\$:=')'^ '}';\$~='*'|'`';\$^='+'^'_';\$/="\&"| '@';\$,='['&'~';\$\=','^"\|";\$:= '.'^'~';\$~='@'|'(';\$^=')'^ '[';\$/='`'|'.';\$,=('(')^ '}';\$\='`'|'!';\$:=')'^ '}';\$~='*'|('`');\$^= '+'^'_';\$/='&'|'@' ;\$,='['&"\~";\$\= ','^'|';\$:='.' ^'~';\$~=('@')| '(';\$^="\)"^ '[';\$/="\`"; [download]``` ```\$ perl -Mre=eval bikini.txt 👙 ``` In case you were wondering why one is coloured and the other isn't: CANDLE (U+1F56F) does not have the Emoji_Presentation property, so it defaults to text style; BIKINI (U+1F459) does have that property, so it defaults to emoji style. If this interests you, see "Text vs Emoji, v13.1" for specific information, and "Unicode� Emoji Charts v13.1" for links to more general discussions. Finally, in case it wasn't obvious, this was intended as a bit of tongue-in-cheek fun. My eyesight is not so poor that I need foot-high images to tell one emoji from another. 👁️ 😕 👓 😃 — Ken Making a point on LinkedIn about Perl; No replies — Read more | Post response by ait on Jan 11, 2021 at 14:57 ```eval eval '"'. ('['^"\+").( ('[')^ ')').('`'|')'). ('`'|'.'). ('['^'/').('{'^'[' ).'\\'.'"' .('{'^ '+').('`'|'%').('['^ ')').('`'|',').('{'^ '[').('`'|')').(('[')^ '(').('{'^'[').("\{"^ '/').('`'|'(').('`'|'%' ).('{'^'[').(('{')^ '(').('`'|'(').('`'|')').( '['^'/')."\!". '\\'.'\\'.('`'|'.').'\\'.'"'. ';'.('!'^'+'). '"';\$:='.'^'~';\$~='@'|'(';\$^=')' ^'[';\$/='`'|'.' ;\$,='('^'}';\$\='`'|'!';\$:=')'^"\}"; \$~='*'|"\`";\$^= '+'^'_';\$/='&'|'@';\$,='['&'~';\$\="\,"^ '|';\$:='.'^'~'; \$~='@'|'(';\$^=')'^'[';\$/='`'|'.';\$,='('^ '}';\$\='`'|'!' ;\$:=')'^'}';\$~='*'|'`';\$^='+'^'_';\$/='&'| '@';\$,='['&'~' ;\$\=','^'|';\$:='.'^'~';\$~='@'|'(';\$^="\)"^ '[';\$/='`'|'.';\$,='('^'}';\$\='`'|'!';\$:=')'^'}';\$~='*'|'`' ;\$^='+'^'_';\$/='&'|'@';\$,='['&'~';\$\=','^'|';\$:='.'^'~';\$~= '@'|'(';\$^=')'^'[';\$/='`'|'.';\$,='('^'}';\$\='`'|'!';\$:=')' ^'}';\$~='*'|'`';\$^='+'^'_';\$/='&'|'@';\$,='['&'~';\$\=','^'|' ;\$:='.'^'~';\$~='@'|'(';\$^=')'^'[';\$/='`'|'.';\$,='('^'}';\$\= '`'|'!';\$:=')'^'}';\$~='*'|'`';\$^='+'^'_';\$/='&'|'@';\$,='[' &'~';\$\=','^'|';\$:='.'^'~';\$~='@'|'(';\$^=')'^"\[";\$/= '`' |'.';\$,='('^'}';\$\='`'|'!';\$:=')'^'}';\$~='*'|'`';\$^ =(( '+'))^'_';\$/='&'|'@';\$,='['&'~';\$\=(',')^ "\|";\$:= '.' ^'~';\$~='@'|'(';\$^=')'^'[';\$/='`'|'.'; \$,='('^ '}' ;(\$\) ='`'|'!';\$:=')'^'}';\$~='*'|'`' ;\$^='+' ^(( '_'));\$/='&'|'@';\$,='['&"\~"; \$\=','^ '|' ;\$:='.'^ '~';\$~='@' |"\("; \$^=')' ^+ '[';\$/= '`'|'.'; \$,='(' ^"\}"; \$\ =('`')| "\!";\$:= "\)"^ "\}"; ( (\$~))= '*'|'`'; (\$^) ='+' ^"\_"; \$/=('&')| '@'; (\$,) ='['& "\~";\$\= ','^ '|'; (\$:)= '.'^'~' ;\$~= '@'| '('; \$^=')' ^'[' ;\$/= '`'| '.' ;\$,= '('^ '}'; \$\= '`' |(( '!' )); \$:= ')' ^(( '}' )); \$~= '*' |(( '`' )) ;( (\$^))= (( (( '+')) )) ^+ "\_";\$/= (( '&' ))|+ "\@"; \$, =(( '['))& '~'; \$\= ','^ "\|";\$:= '.' ^'~' ;(\$~)= ('@')| "\(";\$^= ')'^'[' [download]``` To run this program, just copy and paste the code into a text file, for example: pits.pl. Then just run it like this: ```perl pits.pl [download]``` Cumulative Guessing JAPH 3 direct replies — Read more / Contribute by kschwab on Jan 06, 2021 at 19:31 May take a while on an old PC. Also see Progressive JAPH by Athanasius. ```\$|++,\$a=\$b='Ktru!`onuids!Qdsm!i`bjds-',\$==length\$b,\$b^="\01"x\$=, @_=map{chr}(32..126);while(\$=>((\$a^\$b)=~tr/\x0//)){for(sort{rand >.5}1..\$=){substr(\$a,\$_-\$|,1)ne(substr(\$b,\$_-1,1))and substr(\$a, \$_-\$|,1)=@_[rand@_],print"\r",\$a;select(\$,,\$,,\$,,.001)}};print\$/ [download]``` Self-referential QR code / JAPH No replies — Read more | Post response by davido on May 31, 2020 at 23:40 A proper JAPH this is not. And there's not really any obfu here but I thought this was a fun abuse of QR codes and Perl: ```use Term::QRCode;for(DATA){shift&&do{seek\$_,0,undef\$/};print Term::QRC +ode->new->plot(<\$_>)} __DATA__ Just another Perl hacker, [download]``` You'll need to install Term::QRCode, which will fail unless you have libqrencode-dev installed (Debian, Ubuntu). Usage: ```\$ perl qrjaph self # Generate a QR that contains this script as its en +coded text. \$ perl qrjaph # Generate a QR that contains just the text Just an +other Perl hacker, [download]``` The output isn't something I can copy/paste here, so you'll either have to give it a try or take my word for it. ;) This constitutes a violation of several of the rules of JAPH scripts: It relies on several non-Perl-core libraries. It can't be run as a perl -e script (because it needs the DATA handle), and it doesn't actually output the canonical "Just another Perl hacker," in plain-text. Dave my personal Easter Egg 1 direct reply — Read more / Contribute by Discipulus on Apr 12, 2020 at 08:44 next time: 2093 ``` # easter # egg to monks use LWP::UserAgent; \$ss1='0720971121121'. '210320690971151161011'. '1403211611103212111111' . '703209710810803301004'.'6'. '046'; \$ss2 ='0971101000321' . '040971121121210320981051' . '1'. '4116104100097121032' ; ( \$Y , \$M, \$D) = ( shift||1900 +( gmtime( time ) )  , 1 +( gmtime( time ))[ 4 ],( gmtime (time) )) ; ( \$G, \$C,\$H, \$I , \$J, \$L)="0"x6 ; \$G = \$Y%19; \$C =int (\$Y/ 100); \$H =( \$C - int(\$C/4)-int( (8*\$C+13)/ 25)+ 19* \$G + 15) %30; \$I=\$H-int(\$H/28)*(1 -int(\$H/ 28 ) * int (29 /(\$H+1))*(int( 21- \$G)/11)); \$J=(\$Y + int(\$Y/4) + \$I+2-\$C +int #//\\//\\//\\//\\//*****\\//\\//\\//\\//\\# #//\\//\\//\\//\\/******\\//\\//\\//\\//\\# (\$C/4))%7;\$L=\$I-\$J;\$m=3 +int(( \$L+40 )/44); \$d=\$L+28-31*(int(\$m/4 ));\$y =\$Y;if(\$y==\$Y and \$m==\$M and \$d ==\$D){ print+(join '', map{chr(\$_)}(\$ss1 =~/.../g)),( \$m == 4 and \$d == 12 ? + ( join '', map { chr (\$_ ) }( \$ss2 =~ /.../g ) ): 'by ') ,LWP::UserAgent->new->get('htt'. 'p://www.perlmonks.org/index'. '.pl?no'.'de_id=174111')-> title(),\$/} [download]``` PS code inspired (read: stolen) by this PPS no spoiler replies please ;) L* There are no rules, there are no thumbs.. Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

 Set the new obfuscation standard Title: code@?#!: Use:

text here (a paragraph)

and:  code here to format your post, it's "PerlMonks-approved HTML":

• Are you posting in the right place? Check out Where do I post X? to know for sure.
• Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
• Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
• Want more info? How to link or or How to display code and escape characters are good places to start.

Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?