Velocity Reviews > Perl > job cull; Warner Brothers; try this

# job cull; Warner Brothers; try this

cate
Guest
Posts: n/a

 01-27-2012
I want to see what a real jones can do with this.. IF you're bored.

Here's the interview question:

http://www.codeeval.com/public_sc/14/

Here's the kluge I came up with (they won't be talking to me!) ... a
mess. Show me the 3 liner you guys could do.

@s = (a,h,t); # sorting would give you this
@result = ();

for (\$i=0; \$i < @s; \$i++) {
my \$pa = [];
push @\$pa, \$s[\$i];
nextone(\$max = 20, \$i, \$pa, @s);
}

print "Answer : " . join (",", @result) . "\n";

sub nextone {
my (\$max,# (u) sentinel
\$i, # (i) index of current character already pushed
\$pa, # (u) word assembly
@s # (u) original, sorted word characters
) = @_;

if (\$max-- < 1) {
print "max reached \n";
exit;
}

my \$lengtharray = scalar(@s);

if (\$lengtharray == 1) {
push @result, join("", @{\$pa});
pop @{\$pa};
return;
}

if (\$i == 0 ) {
@s = @s[1 .. \$lengtharray - 1];
} elsif (\$i > 0) {
@s = @s[0 .. \$i - 1, \$i+1 .. \$lengtharray - 1];
}

for (my \$j = 0; \$j < scalar @s; \$j++) {
\$l = scalar @s;
push @{\$pa}, \$s[\$j];
nextone(\$max, \$j, \$pa, @s);
}
pop @{\$pa};
}

=================================================
in case the site changes

Challenge Description

Write a program to print out all the permutations of a string in
alphabetical order.
Input

The first argument will be a text file containing an input string, one
per line. e.g.

hat

Output

Print to stdout, permutations of the string, comma separated, in
alphabetical order.
e.g.

aht,ath,hat,hta,tah,tha

Tim McDaniel
Guest
Posts: n/a

 01-27-2012
In article <(E-Mail Removed)>,
cate <(E-Mail Removed)> wrote:
>I want to see what a real jones can do with this.. IF you're bored.
>Here's the interview question:

Just speaking for me, I'm not fond of the notion of posting interview
programming questions, and especially not of answers. It feels to me
vaguely like cheating.

--
Tim McDaniel, http://www.velocityreviews.com/forums/(E-Mail Removed)

cate
Guest
Posts: n/a

 01-27-2012
On Jan 27, 10:17*am, (E-Mail Removed) (Tim McDaniel) wrote:
> In article <(E-Mail Removed)..com>,
>
> cate *<(E-Mail Removed)> wrote:
> >I want to see what a real jones can do with this.. IF you're bored.
> >Here's the interview question:

>
> Just speaking for me, I'm not fond of the notion of posting interview
> programming questions, and especially not of answers. *It feels to me
> vaguely like cheating.
>
> --
> Tim McDaniel, (E-Mail Removed)

Rest easy Tim, it was public facing. To get into the real meat of it,

Rainer Weikusat
Guest
Posts: n/a

 01-27-2012
Ben Morrow <(E-Mail Removed)> writes:
> Quoth cate <(E-Mail Removed)>:
>> Here's the interview question:
>>
>> http://www.codeeval.com/public_sc/14/
>>
>>
>> Here's the kluge I came up with (they won't be talking to me!) ... a
>> mess. Show me the 3 liner you guys could do.

>
> #!/opt/perl/bin/perl -nl
>
> use warnings;
> use strict;
>
> sub permute; # grr
> sub permute {
> @_ > 1 or return @_;
> return map {
> my @new = @_;
> my \$first = splice @new, \$_, 1;
> map \$first . \$_, permute @new;
> } 0..\$#_;
> }
>
> print join ",", sort +permute split //;
>
> __END__

This doesn't really work: When the input string contains the same
letter more than once, it will print identical 'permutations' as many
times as this letter occurs (the code posted below had the same
problem initially, I found the error while testing). It is also pretty
inefficient and uses *a lot* of memory.

Below is another one, based on the idea that it should be possible to
generate a list of sorted permutions instead of sorting a list
permutations. At least, it doesn't suffer from the 'double letter
issue' (but may well have other bugs), it is faster and uses a lot
less memory (although still quite a bit):

-------------------
sub permute
{

\$cur = shift;
return \$cur unless @_;

push(@res, map { \$cur.\$_ } permute(@_));

do {
\$seen{\$cur} = 1;

\$cur = shift;

push(@res, map { \$cur.\$_; } permute(@head, @_)) unless \$seen{\$cur};
} while (@_);

return @res;
}

print(join(',', permute(sort(split(//, \$ARGV[0])))), "\n");

Charlton Wilbur
Guest
Posts: n/a

 01-27-2012

>>>>> "c" == cate <(E-Mail Removed)> writes:

c> I want to see what a real jones can do with this.. IF you're
c> bored. Here's the interview question:

c> http://www.codeeval.com/public_sc/14/

c> Here's the kluge I came up with (they won't be talking to me!)
c> ... a mess. Show me the 3 liner you guys could do.

perl -MAlgorithm:ermute -e 'my \$p = new Algorithm:ermute([split //,
"ham"]); my @perms; while (my @res = \$p->next) { push @perms, join ("",
@res) }; print map { "\$_\n" } sort @perms; '

It could probably be made shorter, but it fits in the 3-line
requirement.

Charlton

--
Charlton Wilbur
(E-Mail Removed)

Rainer Weikusat
Guest
Posts: n/a

 01-27-2012
Charlton Wilbur <(E-Mail Removed)> writes:
>>>>>> "c" == cate <(E-Mail Removed)> writes:

>
> c> I want to see what a real jones can do with this.. IF you're
> c> bored. Here's the interview question:
>
> c> http://www.codeeval.com/public_sc/14/
>
> c> Here's the kluge I came up with (they won't be talking to me!)
> c> ... a mess. Show me the 3 liner you guys could do.
>
> perl -MAlgorithm:ermute -e 'my \$p = new Algorithm:ermute([split //,
> "ham"]); my @perms; while (my @res = \$p->next) { push @perms, join ("",
> @res) }; print map { "\$_\n" } sort @perms; '
>
> It could probably be made shorter, but it fits in the 3-line
> requirement.

Given that the code is

http://cpansearch.perl.org/src/EDPRA....12/Permute.xs

it decidedly doesn't. Also, you should admit that it was written by
Edwin Pratomo and not by you.

Tim McDaniel
Guest
Posts: n/a

 01-27-2012
In article <(E-Mail Removed) >,
Rainer Weikusat <(E-Mail Removed)> wrote:
>Charlton Wilbur <(E-Mail Removed)> writes:
>>>>>>> "c" == cate <(E-Mail Removed)> writes:

>>
>> c> I want to see what a real jones can do with this.. IF you're
>> c> bored. Here's the interview question:
>>
>> c> http://www.codeeval.com/public_sc/14/
>>
>> c> Here's the kluge I came up with (they won't be talking to me!)
>> c> ... a mess. Show me the 3 liner you guys could do.
>>
>> perl -MAlgorithm:ermute -e 'my \$p = new Algorithm:ermute([split //,
>> "ham"]); my @perms; while (my @res = \$p->next) { push @perms, join ("",
>> @res) }; print map { "\$_\n" } sort @perms; '
>>
>> It could probably be made shorter, but it fits in the 3-line
>> requirement.

>
>Given that the code is
>
> http://cpansearch.perl.org/src/EDPRA....12/Permute.xs
>
>it decidedly doesn't. Also, you should admit that it was written by
>Edwin Pratomo and not by you.

The same logic supports a reductio ad absurdum of
perl -e 'print 1 + 1, "\n"'
counting as many thousands of lines (of C) written by lots of people.
By that reasoning, absolutely nothing would be a one liner.

To me, the key figure is: how quickly and reliably can you accomplish
SMTP protocol module, or image-manipulation package, or whatever, and
it's publicly usable, then I think they deserve bonus points: they've
saved hours or months of work and may well have got something more
reliable and featureful than what they could have done on their own.

Of course, I'd still want to test them on writing something else de
novo, for the case that it's not built into Perl or in CPAN or on

--
Tim McDaniel, (E-Mail Removed)

Rainer Weikusat
Guest
Posts: n/a

 01-27-2012
(E-Mail Removed) (Tim McDaniel) writes:
> In article <(E-Mail Removed) >,
> Rainer Weikusat <(E-Mail Removed)> wrote:
>>Charlton Wilbur <(E-Mail Removed)> writes:
>>>>>>>> "c" == cate <(E-Mail Removed)> writes:
>>>
>>> c> I want to see what a real jones can do with this.. IF you're
>>> c> bored. Here's the interview question:
>>>
>>> c> http://www.codeeval.com/public_sc/14/
>>>
>>> c> Here's the kluge I came up with (they won't be talking to me!)
>>> c> ... a mess. Show me the 3 liner you guys could do.
>>>
>>> perl -MAlgorithm:ermute -e 'my \$p = new Algorithm:ermute([split //,
>>> "ham"]); my @perms; while (my @res = \$p->next) { push @perms, join ("",
>>> @res) }; print map { "\$_\n" } sort @perms; '
>>>
>>> It could probably be made shorter, but it fits in the 3-line
>>> requirement.

>>
>>Given that the code is
>>
>> http://cpansearch.perl.org/src/EDPRA....12/Permute.xs
>>
>>it decidedly doesn't. Also, you should admit that it was written by
>>Edwin Pratomo and not by you.

>
> The same logic supports a reductio ad absurdum of
> perl -e 'print 1 + 1, "\n"'
> By that reasoning, absolutely nothing would be a one liner.

This depends on the challenge: If it was 'design and implemented a
programming language at least capable of calculating the some of 1 and
1 and printing it in response to some input', your example above is
not 'the one line solution' but just an attempt to pass off stuff
others wrote as your own. If it was 'write code which prints the sum
of 1 + 1' the example is a possible solution. The people who posted
the challenge presumably weren't interested in 'Charton Wilbers' 'rip
free stuff off the internet' skills. Actually, I doubt anyone else
was, either.

> To me, the key figure is: how quickly and reliably can you accomplish
> SMTP protocol module, or image-manipulation package, or whatever, and
> it's publicly usable, then I think they deserve bonus points: they've
> saved hours or months of work and may well have got something more
> reliable and featureful than what they could have done on their own.

If you're convinced of that everybody who ever published some code
somewhere must have been more competent than you, as this seems to
suggest, this obviously implies that you have exactly no competence in
this area and consequently, your opinions on 'programming' don't
matter.

Ted Zlatanov
Guest
Posts: n/a

 01-28-2012
On Fri, 27 Jan 2012 21:28:49 +0000 Rainer Weikusat <(E-Mail Removed)> wrote:

RW> Charlton Wilbur <(E-Mail Removed)> writes:
>> perl -MAlgorithm:ermute -e 'my \$p = new Algorithm:ermute([split //,
>> "ham"]); my @perms; while (my @res = \$p->next) { push @perms, join ("",
>> @res) }; print map { "\$_\n" } sort @perms; '
>>
>> It could probably be made shorter, but it fits in the 3-line
>> requirement.

RW> Given that the code is

RW> http://cpansearch.perl.org/src/EDPRA....12/Permute.xs

RW> it decidedly doesn't. Also, you should admit that it was written by
RW> Edwin Pratomo and not by you.

Charlton is a known plagiarist. He's been using other people's modules
in his code for YEARS. But, of course, among Perl programmers this is
hardly exceptional, they wrote CPAN so they could steal credit more easily.

Ted

Ted Zlatanov
Guest
Posts: n/a

 01-28-2012
On Fri, 27 Jan 2012 22:02:04 +0000 Rainer Weikusat <(E-Mail Removed)> wrote:

RW> (E-Mail Removed) (Tim McDaniel) writes:

>> To me, the key figure is: how quickly and reliably can you accomplish
>> SMTP protocol module, or image-manipulation package, or whatever, and
>> it's publicly usable, then I think they deserve bonus points: they've
>> saved hours or months of work and may well have got something more
>> reliable and featureful than what they could have done on their own.

Reason and logic do not work on Rainer, unfortunately. It's like
talking to Eliza.

RW> If you're convinced of that everybody who ever published some code
RW> somewhere must have been more competent than you, as this seems to
RW> suggest, this obviously implies that you have exactly no competence in
RW> this area and consequently, your opinions on 'programming' don't
RW> matter.

Rainer, this is exactly the conversation we should be having. I'm so
glad you've stopped beating the "undef" horse.

Ted