[QUIZ] Perl 'What does this code do?' Quiz
Shlomi Fish <shlomif-ik1l9ssToec+JF/[email protected]> Sun, 28 Oct 2007 19:06:31 +0200
| Newsgroups | gmane.comp.lang.perl.qotw.discuss |
|---|---|
| Message-ID | <[email protected]> |
Hi all!
Here's another "What does this code do?" Quiz. I obfuscated the names of the
variable names to prevent hinting their purpose, but the code itself is
not obfuscated. You have to guess what the "m2()" function does.
Good luck!
Please post spoilers as response to this post with "SPOILER".
Regards,
Shlomi Fish
<<<<<<<<<<<<<<<<<<<<<
use strict;
use warnings;
sub m2
{
my $c = shift;
my $d = sub {
my $e = shift;
return +(ref($e) eq "ARRAY") ? $e->[1] : $e;
};
my $f = sub {
my $e = shift;
return +(ref($e) eq "ARRAY") ? $e->[0] : 1;
};
my $g;
$g = sub {
my ($h, $i, $j) = @_;
if (($h == @$c) && ($j == 0))
{
return ();
}
elsif ($j == 0)
{
return $g->($h+1,
$d->($c->[$h]),
$f->($c->[$h])
);
}
else
{
return ($i, $g->($h, $i, $j-1));
}
};
return [ $g->(0, 0, 0) ];
}
1;
>>>>>>>>>>>>>>>>>>>>>
Regards,
Shlomi Fish
---------------------------------------------------------------------
Shlomi Fish shlomif-ik1l9ssToec+JF/[email protected]
Homepage: http://www.shlomifish.org/
If it's not in my E-mail it doesn't happen. And if my E-mail is saying
one thing, and everything else says something else - E-mail will conquer.
-- An Israeli Linuxer