Better random magic
No replies — Read more | Post response
|
by BenGoldberg
on Dec 29, 2013 at 15:11
|
|
|
Although the text of the japh is plainly readable in the code, what exactly happens to the split up letters that are
passed to _ and __ is... a secret!
sub r{srand$^T; @_}sub b{do{@b=map.5<rand,@_}until grep($_,@b)&&grep(
!$_,@b);@b}sub _{print(@_),return if@_<2;my(@L,@R);push@{$_?\@L:\@R},
shift for&b;_(@L);_(@R)};sub __{1<@_ or return@_;my@b=&b;my$c=grep$_,
@b;my@L=__(@_[0..$c-1]);my@R=__(@_[$c..$#_]);map shift@{$_?\@L:\@R},
@b}_ r __ r split//,"Just Another Perl Hacker,\n";
If you aren't confused yet, run the code in a debugger, and note the list that __ returns, then try to figure out how _ magically prints the letters in the correct order.
Also... I'm fairly sure that this code (unlike my previous randomized JAPH) should be run ok on any perl, even though I've only tested it on 5.12.1
|
fork/wait JAPH
No replies — Read more | Post response
|
by BenGoldberg
on Dec 27, 2013 at 22:33
|
|
|
sub _{fork?wait:return$_ for@_}
print _(split //,qq{Just another Perl Hacker,});
This is mostly inspired by my first implementation of the "amb" operator for the RosettaCode project, but also partly by mjd's amazing japh http://perl.plover.com/obfuscated/solution.html
Mine is obviously much simpler... but still moderately cool.
|
Golf: Cabbage, Goat, Wolf
3 direct replies — Read more / Contribute
|
by educated_foo
on Dec 27, 2013 at 21:00
|
|
|
I was reminded by a recent Reddit thread of the classic "get a goat, wolf, and cabbage across a river" problem (spazzy kittens version, painfully verbose Haskell version). You're on the left side of a river with a cabbage, goat, and wolf, and want to get them to the right side. The wolf will eat the goat, and the goat the cabbage, but only if you leave them alone. You can only fit one of them in your boat at a time.
The problem can be solved by computer with some backtracking, or by hand with some thought. Being a Perl programmer, I naturally thought to golf it, and thought that the best solution would involve a clever regex or substitution. Here's a terse, but un-obfuscated version:
sub wgc {
return if $seen{"@_"}++;
my%x=@_;
if ($x{b} && $x{c} && $x{g} && $x{w}) {
print+(sort keys%$_),"\n" for @h;
exit;
} elsif ((!$x{b} && ($x{c} && $x{g} || $x{g} && $x{w})) ||
($x{b} && (!$x{c} && !$x{g} || !$x{g} && !$x{w}))) {
return;
} else {
if ($x{b}) {
delete $x{b};
for ('xx', keys %x) {
my %y=%x;
delete $y{$_};
local @h=(@h, \%y);
wgc(%y);
}
} else {
$x{b}=1; {
local (@h) = (@h, \%x);
wgc(%x);
}
for my $k (qw(c g w)) {
if (!$x{$k}) {
my %y=(%x,$k,1);
local (@h) = (@h, \%y);
wgc(%y);
};
}
}
}
}
wgc
And here's the output, where "b", "c", "g", and "w" represent the boat, cabbage, goat, and wolf being on the right bank:
bg
g
bcg
c
bcw
cw
bcgw
I wasn't clever enough to come up with the regex solution, but here's a compressed version of the above, weighing in at 382379 strokes:
sub w{return if$s{"@_"}++;my%x=@_;if($x{b}&$x{c}&$x{g}&$x{w}){print+(s
+ort keys%$_),"\n"for@h;exit;}elsif(($x{b}||!($x{c}&&$x{g}||$x{g}&&$x{
+w}))&&(!$x{b}||!(!$x{c}&&!$x{g}||!$x{g}&&!$x{w}))){if($x{b}){delete$x
+{b};for(A,keys%x){my%y=%x;delete$y{$_};local@h=(@h,\%y);w(%y)}}else{$
+x{b}=1;{local@h=(@h,\%x);w(%x);}for(qw(c g w)){if(!$x{$_}){my%y=(%x,$
+_,1);local@h=(@h,\%y);w(%y)}}}}}w
Have at it!
|
Christmas Eve Obfu
No replies — Read more | Post response
|
by tobyink
on Dec 24, 2013 at 08:18
|
|
|
use v5.14;
use strict;
use warnings FATAL => 'all';
our $days_until_christmas = 1
*
map
s([+]
)( )gix
&&printf(
'%5s'
.'%-4s'
.'%s',$_,
substr(~~~~
reverse,!$^C)
=~y[/(]
[\\)]r,$/
),my@ xmas=
qw 1 +.- _(+"
(_++: /+' +(_/^
1;1
;1;
Update: I've posted the Technicolor™ version to blogs.perl.org.
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
|
Slightly Srandom JAPH
1 direct reply — Read more / Contribute
|
by BenGoldberg
on Dec 23, 2013 at 19:50
|
|
|
This isn't super obfuscated, but it's got some coolness to it, nonetheless :)
print sort {4-rand 9} split //, HnlcrhJsre_Pt_aeAeuot_kr if srand JAPH
+;
|
oh for y///e
2 direct replies — Read more / Contribute
|
by bhildred
on Dec 10, 2013 at 15:54
|
|
|
|
|
asccii modern art obfu
1 direct reply — Read more / Contribute
|
by perlaintdead
on Nov 29, 2013 at 22:39
|
|
|
Trying to step my game up and brake my bad habit of putting cyphered text in an array every obfu. Enjoy my ASCII modern art and the Easter eggs.
WARNING:This program is resource heavy!!!
Built with v5.16.3
no warnings;no strict; while(perl_is_not_dead){
+ goto ghs;sub jerry{v3}gns:$ b=~s/^.{3}//;our
@change=((9,65),23);$ feld =gn::n;package gn 4.242{sub n{sr
+and $ VERSION}package queen;
sub boxxy{pop @change and $ boxxy="love, light, joy, and hap
+pyness"}} ;goto g.n.S;ghs:sub dx{$i=2e-2
;@a=queen'boxxy;$i+=1while$a[0]=~s[(?#\x89\x90*{,23}).(?#%?\x59)+?(\
+W{1})][];@a ,$i}sub q{&^>=9*&^+$^%$^^}
package split{sub b{@change[eof fileno *STACKFRAME],@change}}$ b
+=~q((?{$b=substr lc$~,0,-2,}));goto gns;gnS:;sub n{
return $_ >> dx}sub _:{sub(;){( "\x3c".(sqrt(.218_01330_1491_73
+7)/rand+oct+1e2+4x~~2) .chr.chr 0x.99=>)[${(}].$ b.(
(chr(-(&dx)*-25.5).chr(&dx*25.5) .chr((ord reverse split$]=>$~
+,jerry sin$feld)
- -(__METAL__)-"\m/"-_-"\m/"-(__METAL__)- -($!+qw^1 *&9$# @^[quot
+emeta${!}
]^((int exp(v6 cmp v5)) **gn::n)))x2 .$/)=>(ref*a+
+%gin).[*62
,*41])[$#b+3%2+hex( gns)],(prototype ge rea
+dpipe)[tell]}}} continue{printf(::_([])->((
+)),)}+cream and sugar
|
JAPH with a smiley
1 direct reply — Read more / Contribute
|
by choroba
on Sep 03, 2013 at 18:20
|
|
|
I think the idea is not bad, but the JAPH phrase is a bit long for that, so it gets boring quickly.
sub e{sub _{-72} er}eval($/='sub J{map{substr$/,ref('.q:)?pop@$_\:$_,$
+$_[0]||1}
@_}sub f{uc join "system",J(@_)}print J 4=>1,[2,13],-1,010-1,[ _ ],42-
+020,hex"e
";print+h,e,$",f(__LINE__*2+2),e,qw,l,,J(-1,-hex 20),q{ack},e,J hex or
+d(0)/4 :)
A variant that is a bit profane:
|
Felling a tree JAPH
2 direct replies — Read more / Contribute
|
by MidLifeXis
on Aug 30, 2013 at 10:28
|
|
|
Still not a great JAPH, and it exceeds 4x79, but it is more obfuscated than yesterday's.
# Cutting down a tree
$t=t->p;$t->g;$t->f;sub t::p{@n=map{x($_)}'Just another Perl hacker,'=
+~m/(.)/g;
bless{n=>\@n},$_[0]}sub t::g{$_[0]->{t}=$_[0]->f(0,$#{$_[0]->{n}});$_[
+0]->{n}=1
;$_[0]}sub t::f{($a,$b,$e)=@_;$m=int(($b+$e)/2);$f=$_[0]->{n}[$m];$l=$
+_[0]->f(
$b,$m-1)if$b<$m;$r=$_[0]->f($m+1,$e)if$m<$e;bless [$l,$f,$r],'f'}sub t
+::f{$_[0]
->{t}=1}sub x{bless \$_[0],"x"}sub x::DESTROY{print${$_[0]}}sub f::DES
+TROY{$_[0
]->[$_]=1 for(0..2)}
|
Destructive JAPH
1 direct reply — Read more / Contribute
|
by MidLifeXis
on Aug 29, 2013 at 10:48
|
|
|
Starting my foray into JAPH to explore various aspects and corners of the language. Not necessarily obfuscated, but more using different aspects of Perl to accomplish the goals of a JAPH. 4x79 code max, Just another Perl hacker, output to stdout. I am hoping to explore a different technique each day, but it will probably devolve to one a week.
This implementation is pretty obvious how it works, but it uses the DESTROY method of object destruction to output the characters of the output.
@x = map{ x($_) } split('','Just another Perl hacker,');
shift(@x) while @x;
sub x{ bless \$_[0],"x"}
sub x::DESTROY{print ${$_[0]}}
|
|