# job cull; Warner Brothers; try this

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
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("", @);
pop @;
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 @, \$s[\$j];
nextone(\$max, \$j, \$pa, @s);
}
pop @;
}

=================================================
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

## Re: job cull; Warner Brothers; try this

#!/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__

Ben

## Re: job cull; Warner Brothers; try this

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 = 1;

\$cur = shift;

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

return @res;
}

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

## Re: job cull; Warner Brothers; try this

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, tmcd@panix.com

## Re: job cull; Warner Brothers; try this

On Jan 27, 10:17=A0am, t...@panix.com (Tim McDaniel) wrote:

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

## Re: job cull; Warner Brothers; try this

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::Permute -e 'my \$p = new Algorithm::Permute([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
cwilbur@chromatico.net

## Re: job cull; Warner Brothers; try this

Given that the code is

http://cpansearch.perl.org/src/EDPRATOMO/Algorithm-Permute-0.12/Permute.xs

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

## Re: job cull; Warner Brothers; try this

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, tmcd@panix.com

## Re: job cull; Warner Brothers; try this

tmcd@panix.com (Tim McDaniel) writes:

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.

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.

## Re: job cull; Warner Brothers; try this

wrote:

RW> tmcd@panix.com (Tim McDaniel) writes:

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

## Re: job cull; Warner Brothers; try this

The reason I'd use a CPAN module is the 'Hallmark programming' idea ("We
care enough to steal the very best.").  If it's to get a job done, I see
no harm it using publicly available code.  Here the result is something
that works, is maintainable, and fairly well documented (so you or
whomever don't have to go back 6 months later and wonder "What the hell
is going on here?")

If it's a programming challenge, that's different.  The mental exercise
of figuring out the problem yourself (and seeing how others did it) is
the result of the exercise.

--
DeeDee, don't press that button!  DeeDee!  NO!  Dee...
[I filter all Goggle Groups posts, so any reply may be automatically ignored]

## Re: job cull; Warner Brothers; try this

On Fri, 27 Jan 2012 22:02:04 +0000, Rainer Weikusat wrote:

I *expect* an applicant to be able to reuse code where ever possible. I
would give Charlton extra points for his solution.

M4

## Re: job cull; Warner Brothers; try this

And then ask the candidate to implement it from scratch, or give them
another problem for which there is no CPAN module.  'Cause it's nice
to know that they'll be sensible about getting fast solutions where
possible, but you do want to know their coding skills.

--
Tim McDaniel, tmcd@panix.com

## Re: job cull; Warner Brothers; try this

On Mon, 30 Jan 2012 19:43:36 +0000, Tim McDaniel wrote:

Possibly, probably. But note that coding skills take many forms. Do they
know basic algorithms and can they apply them to real world problems? Can
they code in a team? Can they write maintainable code?

M4

## Re: job cull; Warner Brothers; try this

On Mon, 30 Jan 2012 19:43:36 +0000 (UTC) tmcd@panix.com (Tim McDaniel) wrote:

TM> And then ask the candidate to implement it from scratch, or give them
TM> another problem for which there is no CPAN module.  'Cause it's nice
TM> to know that they'll be sensible about getting fast solutions where
TM> possible, but you do want to know their coding skills.

My favorite interview question, 5 years ago, was to implement a hash in
Perl that could map bidirectionally between keys and values.  I said I'd
use Tie::Hash::TwoWay from CPAN.  They asked me to write my own code.

I pointed out I was the author of the module and offered to walk them
through it.

Ted

## Re: job cull; Warner Brothers; try this

Sweet.  But I'll bet you still didn't get the job.  Idiots who do
interviews oftentimes don't have a clue.

--
DeeDee, don't press that button!  DeeDee!  NO!  Dee...
[I filter all Goggle Groups posts, so any reply may be automatically ignored]

## Re: job cull; Warner Brothers; try this

MV> Sweet.  But I'll bet you still didn't get the job.  Idiots who do
MV> interviews oftentimes don't have a clue.

Nah, the interview went well; I was offered the job and I'm still
friends with the guy who interviewed me.  It was a Java shop so in that
context it makes sense--only recently (with Google's Guava, Maven, etc.)
has Java had some kind of popular centralized module facility.

Ted

## Re: job cull; Warner Brothers; try this

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

Actually, what I find at this stage of my career is that my skill at
coding _de novo_ is less and less relevant.  "Write a program to
compute all permutations of this string," as an interview problem, is as
pointless a waste of time as asking me why manhole covers are round.

Well, possibly not *as* pointless -- more than once I have interviewed
applicants for a position who could not handle the rudiments of
programming, and that question would definitely eliminate them.  But
translating algorithms into code is the *beginning* of programming, not
the end -- just as programming is the *beginning* of professional
software development, not the end.

Charlton

--
Charlton Wilbur
cwilbur@chromatico.net

## Re: job cull; Warner Brothers; try this

wrote:

RW> Given that the code is

RW>     http://cpansearch.perl.org/src/EDPRATOMO/Algorithm-Permute-0.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