job cull; Warner Brothers; try this

Discussion in 'Perl Misc' started by cate, Jan 27, 2012.

  1. cate

    cate Guest

    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
     
    cate, Jan 27, 2012
    #1
    1. Advertising

  2. cate

    Tim McDaniel Guest

    In article <>,
    cate <> 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,
     
    Tim McDaniel, Jan 27, 2012
    #2
    1. Advertising

  3. cate

    cate Guest

    On Jan 27, 10:17 am, (Tim McDaniel) wrote:
    > In article <..com>,
    >
    > cate  <> 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,


    Rest easy Tim, it was public facing. To get into the real meat of it,
    you have to login.
     
    cate, Jan 27, 2012
    #3
  4. Ben Morrow <> writes:
    > Quoth cate <>:
    >> 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
    {
    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");
     
    Rainer Weikusat, Jan 27, 2012
    #4

  5. >>>>> "c" == cate <> 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
     
    Charlton Wilbur, Jan 27, 2012
    #5
  6. Charlton Wilbur <> writes:
    >>>>>> "c" == cate <> 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.
     
    Rainer Weikusat, Jan 27, 2012
    #6
  7. cate

    Tim McDaniel Guest

    In article <>,
    Rainer Weikusat <> wrote:
    >Charlton Wilbur <> writes:
    >>>>>>> "c" == cate <> 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.

    --
    Tim McDaniel,
     
    Tim McDaniel, Jan 27, 2012
    #7
  8. (Tim McDaniel) writes:
    > In article <>,
    > Rainer Weikusat <> wrote:
    >>Charlton Wilbur <> writes:
    >>>>>>>> "c" == cate <> 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.
     
    Rainer Weikusat, Jan 27, 2012
    #8
  9. cate

    Ted Zlatanov Guest

    On Fri, 27 Jan 2012 21:28:49 +0000 Rainer Weikusat <> wrote:

    RW> Charlton Wilbur <> 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, Jan 28, 2012
    #9
  10. cate

    Ted Zlatanov Guest

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

    RW> (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
     
    Ted Zlatanov, Jan 28, 2012
    #10
  11. In article <>,
    Ted Zlatanov <> wrote:

    > On Fri, 27 Jan 2012 22:02:04 +0000 Rainer Weikusat <>
    > wrote:
    >
    > RW> (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


    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]
     
    Michael Vilain, Jan 29, 2012
    #11
  12. >>>>> "TZ" == Ted Zlatanov <> 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!

    Charlton

    --
    Charlton Wilbur
     
    Charlton Wilbur, Jan 30, 2012
    #12
  13. >>>>> "TMcD" == Tim McDaniel <> 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





    --
    Charlton Wilbur
     
    Charlton Wilbur, Jan 30, 2012
    #13
  14. 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
     
    Martijn Lievaart, Jan 30, 2012
    #14
  15. >>>>> "RW" == Rainer Weikusat <> 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.'

    Charlton



    --
    Charlton Wilbur
     
    Charlton Wilbur, Jan 30, 2012
    #15
  16. cate

    Tim McDaniel Guest

    In article <>,
    Martijn Lievaart <> 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.


    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,
     
    Tim McDaniel, Jan 30, 2012
    #16
  17. On Mon, 30 Jan 2012 19:43:36 +0000, Tim McDaniel wrote:

    > In article <>, Martijn Lievaart
    > <> wrote:


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


    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
     
    Martijn Lievaart, Jan 31, 2012
    #17
  18. cate

    Ted Zlatanov Guest

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

    TM> In article <>,
    TM> Martijn Lievaart <> 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
     
    Ted Zlatanov, Feb 1, 2012
    #18
  19. In article <>,
    Ted Zlatanov <> wrote:

    > On Mon, 30 Jan 2012 19:43:36 +0000 (UTC) (Tim McDaniel) wrote:
    >
    > TM> In article <>,
    > TM> Martijn Lievaart <> 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


    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]
     
    Michael Vilain, Feb 2, 2012
    #19
  20. cate

    Ted Zlatanov Guest

    On Wed, 01 Feb 2012 18:52:37 -0800 Michael Vilain <> wrote:

    MV> In article <>,
    MV> Ted Zlatanov <> 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
     
    Ted Zlatanov, Feb 2, 2012
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bienwell
    Replies:
    4
    Views:
    3,900
    bienwell
    May 27, 2005
  2. Replies:
    2
    Views:
    1,108
    jeffc
    Jan 13, 2004
  3. John Salerno
    Replies:
    20
    Views:
    881
    John Salerno
    Aug 11, 2006
  4. Fabio Z Tessitore

    who is simpler? try/except/else or try/except

    Fabio Z Tessitore, Aug 12, 2007, in forum: Python
    Replies:
    5
    Views:
    397
  5. =?Utf-8?B?QUo=?=

    When to TRY and not to TRY

    =?Utf-8?B?QUo=?=, Oct 16, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    345
    sloan
    Oct 17, 2007
Loading...

Share This Page