Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

job cull; Warner Brothers; try this

15 views
Skip to first unread message

cate

unread,
Jan 27, 2012, 8:32:22 AM1/27/12
to
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

Ben Morrow

unread,
Jan 27, 2012, 9:54:40 AM1/27/12
to

Quoth cate <catebe...@yahoo.com>:
>
> 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__

Ben

Tim McDaniel

unread,
Jan 27, 2012, 11:17:13 AM1/27/12
to
In article <a580a8b6-fac3-492b...@t13g2000yqg.googlegroups.com>,
cate <catebe...@yahoo.com> 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, tm...@panix.com

cate

unread,
Jan 27, 2012, 11:29:22 AM1/27/12
to
On Jan 27, 10:17 am, t...@panix.com (Tim McDaniel) wrote:
> In article <a580a8b6-fac3-492b-aa59-0621a5c8a...@t13g2000yqg.googlegroups.com>,
>
> cate  <catebekens...@yahoo.com> 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, t...@panix.com

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

Rainer Weikusat

unread,
Jan 27, 2012, 2:14:55 PM1/27/12
to
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");

Charlton Wilbur

unread,
Jan 27, 2012, 3:30:38 PM1/27/12
to

>>>>> "c" == cate <catebe...@yahoo.com> 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.

Charlton

--
Charlton Wilbur
cwi...@chromatico.net

Rainer Weikusat

unread,
Jan 27, 2012, 4:28:49 PM1/27/12
to
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.

Tim McDaniel

unread,
Jan 27, 2012, 4:48:25 PM1/27/12
to
In article <877h0cy...@sapphire.mobileactivedefense.com>,
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.

--
Tim McDaniel, tm...@panix.com

Rainer Weikusat

unread,
Jan 27, 2012, 5:02:04 PM1/27/12
to
tm...@panix.com (Tim McDaniel) writes:
> In article <877h0cy...@sapphire.mobileactivedefense.com>,
> Rainer Weikusat <rwei...@mssgmbh.com> wrote:
>>Charlton Wilbur <cwi...@chromatico.net> writes:
>>>>>>>> "c" == cate <catebe...@yahoo.com> 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"'
> 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.

Ted Zlatanov

unread,
Jan 28, 2012, 8:01:38 AM1/28/12
to
On Fri, 27 Jan 2012 21:28:49 +0000 Rainer Weikusat <rwei...@mssgmbh.com> wrote:

RW> Charlton Wilbur <cwi...@chromatico.net> writes:
>> 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

Ted Zlatanov

unread,
Jan 28, 2012, 8:06:27 AM1/28/12
to
On Fri, 27 Jan 2012 22:02:04 +0000 Rainer Weikusat <rwei...@mssgmbh.com> wrote:

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

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

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
Message has been deleted

Charlton Wilbur

unread,
Jan 30, 2012, 12:41:38 PM1/30/12
to
>>>>> "TMcD" == Tim McDaniel <tm...@panix.com> writes:

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 Wilbur

unread,
Jan 30, 2012, 12:32:00 PM1/30/12
to
>>>>> "TZ" == Ted Zlatanov <t...@lifelogs.com> writes:

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!

Martijn Lievaart

unread,
Jan 30, 2012, 1:51:28 PM1/30/12
to
On Fri, 27 Jan 2012 22:02:04 +0000, Rainer Weikusat wrote:

> 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

Tim McDaniel

unread,
Jan 30, 2012, 2:43:36 PM1/30/12
to
In article <ge5jv8-...@news.rtij.nl>,
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, tm...@panix.com

Charlton Wilbur

unread,
Jan 30, 2012, 2:24:52 PM1/30/12
to
>>>>> "RW" == Rainer Weikusat <rwei...@mssgmbh.com> writes:

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

Martijn Lievaart

unread,
Jan 31, 2012, 6:55:53 AM1/31/12
to
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

Ted Zlatanov

unread,
Feb 1, 2012, 12:55:24 PM2/1/12
to
On Mon, 30 Jan 2012 19:43:36 +0000 (UTC) tm...@panix.com (Tim McDaniel) wrote:

TM> In article <ge5jv8-...@news.rtij.nl>,
TM> Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
>> On Fri, 27 Jan 2012 22:02:04 +0000, Rainer Weikusat wrote:
>>
>>> 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.

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
Message has been deleted

Ted Zlatanov

unread,
Feb 2, 2012, 7:22:23 AM2/2/12
to
On Wed, 01 Feb 2012 18:52:37 -0800 Michael Vilain <vil...@NOspamcop.net> wrote:

MV> In article <87aa52z...@lifelogs.com>,
MV> Ted Zlatanov <t...@lifelogs.com> wrote:

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

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
0 new messages