job cull; Warner Brothers; try this

C

cate

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
 
T

Tim McDaniel

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.
 
C

cate

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.

Rest easy Tim, it was public facing. To get into the real meat of it,
you have to login.
 
R

Rainer Weikusat

Ben Morrow said:
#!/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
{
my ($cur, @head, @res, %seen);

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

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

do {
$seen{$cur} = 1;

push(@head, $cur);
$cur = shift;

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

return @res;
}

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

Charlton Wilbur

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
 
R

Rainer Weikusat

Charlton Wilbur said:
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.

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.
 
T

Tim McDaniel

Charlton Wilbur said:
"c" == cate <[email protected]> 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::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.

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.

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
your tasks? If you quickly find that someone has already done that
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
download.com or whatever.
 
R

Rainer Weikusat

Charlton Wilbur said:
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.

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.

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
your tasks? If you quickly find that someone has already done that
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.
 
T

Ted Zlatanov

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.

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
 
T

Ted Zlatanov

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
 
M

Michael Vilain

Ted Zlatanov said:
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

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.
 
C

Charlton Wilbur

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

And I've been giving useless answers to stupid questions for even
longer!

Charlton
 
C

Charlton Wilbur

TMcD> To me, the key figure is: how quickly and reliably can you
TMcD> accomplish your tasks? If you quickly find that someone has
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
 
M

Martijn Lievaart

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.

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

M4
 
C

Charlton Wilbur

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

The person who posted the challenge here wanted a solution in three
lines, which I delivered. And the module is explicitly called out in
the one-liner: if I said, "According to the Encylopedia Britannica" in a
thread, would you accuse me of trying to pass off that work as my own?

Finally, if you're going to attempt to insult me by putting my name in
scare quotes, the very least you could do would be to spell it
correctly, 'Reiner Wiekusat.'

Charlton
 
T

Tim McDaniel

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

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.
 
M

Martijn Lievaart

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.

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
 
T

Ted Zlatanov

On Mon, 30 Jan 2012 19:43:36 +0000 (UTC) (e-mail address removed) (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
 
M

Michael Vilain

Ted Zlatanov said:
On Mon, 30 Jan 2012 19:43:36 +0000 (UTC) (e-mail address removed) (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

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

Ted Zlatanov

MV> In article <[email protected]>,

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top