23
1
Classic code golf challenge. Write the most obscure Perl program to print "Just another Perl hacker". Here's the Wikipedia article on it. Bonus points if it fits in 3 lines / 70 characters each.
23
1
Classic code golf challenge. Write the most obscure Perl program to print "Just another Perl hacker". Here's the Wikipedia article on it. Bonus points if it fits in 3 lines / 70 characters each.
8
@H=@h=(176,138,140,17,87,54,126,182,217,223,136,130,136,117,73,52,154, 134,161,36,33,92,60,51);for(;$j<24;$j++){$x=0;for($k=0;$k<24;$k++){$x +=@h[$k]<<($j*$k%24);$x%=241;}@H[$j]=$x;}print pack('c*',@H)
I'm not sure whether a newline at the end is required: if so, the addition of ."\n"
still doesn't take me up to the limit of 3 lines * 70 chars/line.
If it weren't for encoding issues the initialisation could be much smaller and extracted with unpack, so I expect someone can improve on this. I'm thinking about making a more efficient version - this is O(n^2), and O(n lg n) decoding is possible.
+1 for <3 at the end of character value of your array! – Ry- – 2011-04-28T19:53:24.203
28
eval eval '"'.
('['^"\+").(
('[')^ ')').('`'|')').
('`'|'.'). ('['^'/').('{'^'['
).'\\'.'"' .('`'^ '*').('['^'.').('['^
'(').('['^'/').('{'^ '[').('`'|'!').(('`')|
'.').('`'|'/').("\["^ '/').('`'|'(').('`'|'%'
).('['^')').(('{')^ '[').('{'^'+').('`'|'%').(
'['^')').('`'| ',').('{'^'[').('`'|'(').('`'
|'!').('`'|'#' ).('`'|'+').('`'|'%').('['^')').
'\\'.'"'.("\!"^ '+').'"';$:='.'^'~';$~='@'|"\(";$^=
')'^'[';$/='`'| '.';$,='('^'}';$\='`'|'!';$:=')'^"\}";
$~='*'|"\`";$^= '+'^'_';$/='&'|'@';$,='['&'~';$\=','^'|'
;$:='.'^'~';$~ ='@'|'(';$^=')'^'[';$/='`'|'.';$,='('^'}'
;$\='`'|'!';$: =')'^'}';$~='*'|'`';$^='+'^'_';$/='&'|'@';
$,='['&'~';$\=','^'|';$:='.'^'~';$~='@'|'(';$^=')'^'[';$/=
'`'|'.';$,='('^'}';$\='`'|'!';$:=')'^'}';$~='*'|'`';$^='+'^
'_';$/='&'|'@';$,='['&'~';$\=','^'|';$:='.'^'~';$~='@'|'('
;$^=')'^'[';$/='`'|'.';$,='('^'}';$\='`'|'!';$:=')'^'}';$~=
'*'|'`';$^='+'^'_';$/='&'|'@';$,='['&'~';$\=','^'|';$:='.'^
'~';$~='@'|'(';$^=')'^'[';$/='`'|'.';$,='('^'}';$\='`'|'!'
;$:=')'^'}';$~='*'|'`';$^='+'^'_';$/='&'|'@';$,="\["& '~'
;$\=','^'|';$:='.'^'~';$~='@'|'(';$^=')'^'[';$/='`' |((
'.'));$,='('^'}';$\='`'|'!';$:=')'^'}';$~ ='*'|'`' ;$^
='+'^'_';$/='&'|'@';$,='['&'~';$\=','^ '|';$:= '.'
^'~'; $~='@'|'(';$^=')'^'[';$/="\`"| '.';$,= '('
^'}';$\='`'|'!';$:=')'^'}';$~ =('*')| '`'
;$^='+'^ '_';$/='&' |"\@"; $,='[' &+
'~';$\= ','^'|'; $:='.' ^"\~"; $~
=('@')| "\(";$^= "\)"^ "\["; (
($/))= '`'|'.'; ($,) ='('
^"\}"; $\=('`')| '!'; ($:)
=')'^ "\}";$~= '*'| '`';
($^)= '+'^'_' ;$/= '&'|
'@'; $,='[' &'~' ;$\=
','^ '|' ;$:= '.'^
'~'; $~= '@' |((
'(' )); $^= ')'
^(( '[' )); $/=
'`' |(( '.' ))
;( ($,))= ((
(( '(')) ))
^+ "\}";$\= ((
'`' ))|+ "\!"; $:
=(( ')'))^ '}'; $~=
'*'| "\`";$^= '+' ^'_'
;($/)= ('&')|
"\@";$,= '['&'~'
5
use Time'HiRes"usleep";$|=@q=(a..z,' ');@w=('just another perl hacker' =~/./g);while("@w"ne"@e"){$e[$_]eq$w[$_]or$e[$_]=$q[rand@q]for+0..$#w; print"\r@e";usleep+1e5}
animated version :)
3
$_=unpack("H21","9Ø
HvÂláµöÂ");s/(.)/" "x(hex$1<3).substr
"AHPJocehtunarslk",hex$1,1/eg;say
Care: It's ISO-8859-1 encoded.
perl -E '$_=unpack("H21","9Ø
HvÂláµöÂ");s/(.)/" "x(hex$1<3).substr
"AHPJocehtunarslk",hex$1,1/eg;say'
Just Another Perl Hacker
More than 70 chars at all, but less than 100!
wc -clL <<< '$_=unpack("H21","9Ø
HvÂláµöÂ");s/(.)/" "x(hex$1<3).substr
"AHPJocehtunarslk",hex$1,1/eg;say'
3 92 37
And a little obfuscated!
There is a <1'000 perl script with a full help and some features:
(It's ISO-8859-1 encoded too ;)
#!/usr/bin/perl -s
$;=$/;$_=q=sub'O{un=."\144e".q[f}sub'l{$#_==-1?leng].q[th:leng].'t'.q[h&a}sub'u{($.=
q;?02:;)=~y+0-@+a-q+;$. =~s/^/&a?"un].q[":""/mxe;$..=' "b';$..=do{$.].q[=~m+^u+?&a:1
}<<3;$..='","';$..=do{$.].q[=~m+^u+?"\44_":&a};eval $.."\42"}s].q[ub'a{pop}sub'b{$.=
"Hauri Félix, ";$v?do{$_=$.;y+?-^+_-~+;].q[s/\s.*/.ch/mgx;$_=do{$0=~m-j\w+-?$&.q.@.:
(q.w.x3).q,.,}.q qf-q].q[.$_;$..$_}:sub].q[str("lockpents ".$.,&a,1)}sub'p{pr]."in".
q<t do{$#_+1?&a."\n":do{/\n/?$_:$_.".\n"}}};sub'x{e>.pack("v",27000).q<t}sub't{sel>.
"ec".q<t O,&O,O,&a};$v&&{p $0." \251".(30*67)." ".b}&&x;$j&&do{$_="Îx¹\26§ÕIÕ\220º".
"2Õ";$_=>.q<u 12,1;s/.{4}/b ord u O,"$&",O/meg;tr+@-[+`-{+;s/./($.=$&)=~y.^-{.?-\\>.
q<\\.;$./xe;p;$c&&do{$c!=1&&do{$_=$c." ";p};fo>."reac".q<h$=(1..2*l){s/.//m;$_.=$&;p
"\33[A\r".$_;t.1}};x};$/=O;o>.chr(0x38*2).q-en$_,$0;$_=<$_>;$k&&p&&x||$p&&do{p;op-.q
len$p,$p;p<$p>;x};$h&&do{$_="Usal.q lge: ".$0." [ -v | -h | -j [-c[=string]] | -k |l
.q+ -p=file.pl ]";p;x};1+;eval||die+No.$;;
There are some features:
./japh.pl -h
Usage: ./japh.pl [ -v | -h | -j [-c[=string]] | -k | -p=file.pl ].
Where:
-v
signature-h
help string-j
prompt Just another perl hacker.-c
animate the japh string or a submited string if any-k
dump the script himself-p
polute another scriptSo:
./japh.pl -j
Just another perl hacker.
./japh.pl -k | wc -lcL
14 998 84
./japh.pl -p=$(which perldoc) >japhedPerldoc
chmod +x japhedPerldoc
./japhedPerldoc perl | head
PERL(1) User Contributed Perl Documentation PERL(1)
NAME
perl - The Perl 5 language interpreter
SYNOPSIS
perl [ -sTtuUWX ] [ -hv ] [ -V[:configvar] ]
[ -cw ] [ -d[t][:debugger] ] [ -D[number/list] ]
./japhedPerldoc -j -c
Just another perl hacker.
(The last string is animated:)
There is a nice B::Deparse module available on CPAN:
perl -MO=Deparse japh.pl
$; = $/;
$_ = qq[sub'O{undef}sub'l{\$#_==-1?length:length&a}sub'u{(\$.=\nq;?02:;)=~y+0-\@+a-q+;\$. =~s/^/&a?"un":""/mxe;\$..=' "b';\$..=do{\$.=~m+^u+?&a:1\n}<<3;\$..='","';\$..=do{\$.=~m+^u+?"\\44_":&a};eval\$.."\\42"}sub'a{pop}sub'b{\$.=\n"Hauri F\351lix, ";\$v?do{\$_=\$.;y+?-^+_-~+;s/\\s.*/.ch/mgx;\$_=do{\$0=~m-j\\w+-?\$&.q.\@.:\n(q.w.x3).q,.,}.q qf-q.\$_;\$..\$_}:substr("lockpents ".\$.,&a,1)}sub'p{print do{\$#_+1?&a."\\n":do{/\\n/?\$_:\$_.".\\n"}}};sub'x{e] . pack('v', 27000) . q[t}sub't{sel] . 'ec' . qq[t O,&O,O,&a};\$v&&{p \$0." \\251".(30*67)." ".b}&&x;\$j&&do{\$_="\316x\271\\26\247\325I\325\\220\272".\n"2\325";\$_=] . 'u 12,1;s/.{4}/b ord u O,"$&",O/meg;tr+@-[+`-{+;s/./($.=$&)=~y.^-{.?-\\' . '\\.;$./xe;p;$c&&do{$c!=1&&do{$_=$c." ";p};fo' . 'reac' . qq(h\$=(1..2*l){s/.//m;\$_.=\$&;p\n"\\33[A\\r".\$_;t.1}};x};\$/=O;o) . 'p' . 'en$_,$0;$_=<$_>;$k&&p&&x||$p&&do{p;op' . 'en$p,$p;p<$p>;x};$h&&do{$_="Usa' . 'ge: ".$0." [ -v | -h | -j [-c[=string]] | -k |' . ' -p=file.pl ]";p;x};1';
die 'No' . $; unless eval $_;
japh.pl syntax OK
Well, this is more readable, but...
Ok, there is a pack('v', 27000)
, what it mean:
perl -E "say pack('v', 27000)";
xi
Hmm. so we could try to simplify deparser's work:
perl -MO=Deparse <(sed -e <japh.pl 's/pack("v",27000)/"xi"/')
$; = $/;
$_ = qq(sub'O{undef}sub'l{\$#_==-1?length:length&a}sub'u{(\$.=\nq;?02:;)=~y+0-\@+a-q+;\$. =~s/^/&a?"un":""/mxe;\$..=' "b';\$..=do{\$.=~m+^u+?&a:1\n}<<3;\$..='","';\$..=do{\$.=~m+^u+?"\\44_":&a};eval \$.."\\42"}sub'a{pop}sub'b{\$.=\n"Hauri F\351lix, ";\$v?do{\$_=\$.;y+?-^+_-~+;s/\\s.*/.ch/mgx;\$_=do{\$0=~m-j\\w+-?\$&.q.\@.:\n(q.w.x3).q,.,}.q qf-q.\$_;\$..\$_}:substr("lockpents ".\$.,&a,1)}sub'p{print do{\$#_+1?&a."\\n":do{/\\n/?\$_:\$_.".\\n"}}};sub'x{exit}sub't{select O,&O,O,&a};\$v&&{p \$0." \\251".(30*67)." ".b}&&x;\$j&&do{\$_="\316x\271\\26\247\325I\325\\220\272".\n"2\325";\$_=u 12,1;s/.{4}/b ord u O,"\$&",O/meg;tr+\@-[+`-{+;s/./(\$.=\$&)=~y.^-{.?-\\\\.;\$./xe;p;\$c&&do{\$c!=1&&do{\$_=\$c." ";p};foreach\$=(1..2*l){s/.//m;\$_.=\$&;p\n"\\33[A\\r".\$_;t.1}};x};\$/=O;open\$_,\$0;\$_=<\$_>;\$k&&p&&x||\$p&&do{p;open\$p,\$p;p<\$p>;x};\$h&&do{\$_="Usage: ".\$0." [ -v | -h | -j [-c[=string]] | -k | -p=file.pl ]";p;x};1);
die 'No' . $; unless eval $_;
/dev/fd/63 syntax OK
Well, now it is clear that whole script is contained in qq(...)
on line 2 and have to be submited to eval
. We could now:
perl -MO=Deparse <(sed -e <japh.pl 's/pack("v",27000)/"xi"/') |
sed -ne 's/$_ = \(qq(.*)\);/print \1/p' |
perl
/dev/fd/63 syntax OK
sub'O{undef}sub'l{$#_==-1?length:length&a}sub'u{($.=
q;?02:;)=~y+0-@+a-q+;$. =~s/^/&a?"un":""/mxe;$..=' "b';$..=do{$.=~m+^u+?&a:1
}<<3;$..='","';$..=do{$.=~m+^u+?"\44_":&a};eval $.."\42"}sub'a{pop}sub'b{$.=
"Hauri Félix, ";$v?do{$_=$.;y+?-^+_-~+;s/\s.*/.ch/mgx;$_=do{$0=~m-j\w+-?$&.q.@.:
(q.w.x3).q,.,}.q qf-q.$_;$..$_}:substr("lockpents ".$.,&a,1)}sub'p{print do{$#_+1?&a."\n":do{/\n/?$_:$_.".\n"}}};sub'x{exit}sub't{select O,&O,O,&a};$v&&{p $0." \251".(30*67)." ".b}&&x;$j&&do{$_="Îx¹\26§ÕIÕ\220º".
"2Õ";$_=u 12,1;s/.{4}/b ord u O,"$&",O/meg;tr+@-[+`-{+;s/./($.=$&)=~y.^-{.?-\\.;$./xe;p;$c&&do{$c!=1&&do{$_=$c." ";p};foreach$=(1..2*l){s/.//m;$_.=$&;p
"\33[A\r".$_;t.1}};x};$/=O;open$_,$0;$_=<$_>;$k&&p&&x||$p&&do{p;open$p,$p;p<$p>;x};$h&&do{$_="Usage: ".$0." [ -v | -h | -j [-c[=string]] | -k | -p=file.pl ]";p;x};1
In the hope deparser could better understand, now:
perl -MO=Deparse <(sed -e <japh.pl 's/pack("v",27000)/"xi"/') |
sed -ne 's/$_ = \(qq(.*)\);/print \1/p' |
perl |
perl -MO=Deparse
/dev/fd/63 syntax OK
sub O {
undef;
}
sub l {
$#_ == -1 ? length $_ : length &a;
}
sub u {
($. = '?02:') =~ tr/0-@/a-q/;
$. =~ s/^/&a ? 'un' : '';/emx;
$. .= ' "b';
$. .= do {
$. =~ /^u/ ? &a : 1
} << 3;
$. .= '","';
$. .= do {
$. =~ /^u/ ? '$_' : &a
};
eval $. . '"';
}
sub a {
pop();
}
sub b {
$. = "Hauri F\351lix, ";
$v ? do {
$_ = $.;
tr/?-^/_-~/;
s/\s.*/.ch/gmx;
$_ = do {
$0 =~ /j\w+/ ? $& . '@' : 'w' x 3 . '.'
} . 'f-' . $_;
$. . $_
} : substr('lockpents ' . $., &a, 1);
}
sub p {
print do {
$#_ + 1 ? &a . "\n" : do {
/\n/ ? $_ : $_ . ".\n"
}
};
}
sub x {
exit;
}
sub t {
select O(), &O, O(), &a;
}
x if $v and {p($0 . " \251" . 2010 . ' ' . b())};
if ($j) {
$_ = "\316x\271\cV\247\325I\325\220\2722\325";
$_ = u(12, 1);
s/.{4}/b ord u(O(), "$&", O());/egm;
tr/@-[/`-{/;
s[.][($. = $&) =~ tr/^-{/?-\\/;
$.;]ex;
p ;
if ($c) {
if ($c != 1) {
$_ = $c . ' ';
p ;
}
foreach $= (1 .. 2 * l()) {
s/.//m;
$_ .= $&;
p "\e[A\r" . $_;
t 0.1;
}
}
x ;
}
$/ = O();
open $_, $0;
$_ = <$_>;
$p and do {
p ;
open $p, $p;
p <$p>;
x
} unless $k and p and x ;
if ($h) {
$_ = 'Usage: ' . $0 . ' [ -v | -h | -j [-c[=string]] | -k | -p=file.pl ]';
p ;
x ;
}
'???';
- syntax OK
Well! We got something near readable, now. Do this alway give same result?
perl -MO=Deparse <(sed -e <japh.pl 's/pack("v",27000)/"xi"/') |
sed -ne 's/$_ = \(qq(.*)\);/print \1/p' |
perl |
perl -MO=Deparse |
perl -s /dev/stdin -j -c="That's all folks"
/dev/fd/63 syntax OK
- syntax OK
Just another perl hacker.
That's all folks .
(And the last line is animated:)
1
use strict;*1=*CORE'die,*!=*=,@=='hacker',s??'&1(@!,$/)'?ee;s;;%ENV=~m
,..$,,$&+10;e,@!=(chr.'ust',~~reverse('rehtona'),'Perl',$@);&1("@{=}")
It works with strictures enabled. Although it does not work on all machines/perls, because of CORE'die
and ~~%ENV
.
$ perl
use strict;*1=*CORE'die,*!=*=,@=='hacker',s??'&1(@!,$/)'?ee;s;;%ENV=~m
,..$,,$&+10;e,@!=(chr.'ust',~~reverse('rehtona'),'Perl',$@);&1("@{=}")
^Z
Just another Perl hacker
2Obfuscated instead of obscure? – Josh – 2011-01-27T21:00:07.930
13Code golf has to be about shortest code, not "most obscure". Shortest is objective. "Most obscure" is subjective. – Chris Jester-Young – 2011-01-27T21:00:58.863
2@Chris: Wasn't this also about general programming puzzles? Ok, arguable whether obfuscation falls under that but as far as I understood it this wasn't a pure code golf site. – Joey – 2011-01-27T21:15:06.527
1@Joey: It's not, but, the Stack Exchange platform is much more effective for objective questions, not ones "that the OP likes best". – Chris Jester-Young – 2011-01-27T21:18:28.927