Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: •SPOILERS Re: (OT) Interview questions -- your response?

by demerphq (Chancellor)
on Sep 03, 2002 at 18:55 UTC ( #194857=note: print w/replies, xml ) Need Help??


in reply to •SPOILERS Re: (OT) Interview questions -- your response?
in thread (OT) Interview questions -- your response?

merlyn your number two is _way_ too complex
@array[$_,-$_-1]=@array[-$_-1,$_] for 0..@array/2;
UPDATED
As has been pointed out the above is incorrect.
@array[$_,-$_-1]=@array[-$_-1,$_] for 0..$#array/2;
Is what it should have been

I must have been halucinating when I tested it.

But frankly I stand by my too complex comment regardless.

Yves / DeMerphq
---
Software Engineering is Programming when you can't. -- E. W. Dijkstra (RIP)

Replies are listed 'Best First'.
Re: Re: •SPOILERS Re: (OT) Interview questions -- your response?
by Zaxo (Archbishop) on Sep 03, 2002 at 19:28 UTC

    Fencepost error. I think you mean:

    @array[$_,-$_-1]=@array[-$_-1,$_] for 0..$#array/2;

    The middle pair was swapped twice to no effect for even sized arrays, the middle element swapped with itself for odd.

    After Compline,
    Zaxo

      I actually did #2 the way I did to avoid a fencepost error. And it's proveably correct.

      And think of the maintenance programmer. I'd not want to maintain your code.

      -- Randal L. Schwartz, Perl hacker

      Busted.

      Oh well.

      I guess I didn't get the job.

      Yves / DeMerphq
      ---
      Software Engineering is Programming when you can't. -- E. W. Dijkstra (RIP)

Re: Re: •SPOILERS Re: (OT) Interview questions -- your response?
by Dog and Pony (Priest) on Sep 03, 2002 at 19:18 UTC
    Why not go for truly ugly? ;-)
    @array[0..$#array] = @array[map{-$_}(1..@array)];

    You have moved into a dark place.
    It is pitch black. You are likely to be eaten by a grue.
Re: Re: •SPOILERS Re: (OT) Interview questions -- your response?
by ignatz (Vicar) on Sep 03, 2002 at 19:31 UTC
    I'm not sure if treating an interview question like a golf challenge is such a good idea. Well... this guy was good, but this other guy did it in just 14 characters. Not gonna happen. ;-)
    ()-()
     \"/
      `                                                     
    
Re: Re: SPOILERS Re: (OT) Interview questions -- your response?
by perrin (Chancellor) on Sep 03, 2002 at 19:49 UTC
    I like merlyn's answer because it's readable, even by people who are not hardcore perl programmers. It's not tricky, but it doesn't need to be.
      Actually I disagree quite strongly. Its readable by people with a C background (ie who are used to the while() loops being disguised as for() loops) but to people who come from other backgrounds (such as Pascal) I think the above would cause some palpatations on first reading.

      Yves / DeMerphq
      ---
      Software Engineering is Programming when you can't. -- E. W. Dijkstra (RIP)

Re: Re: •SPOILERS Re: (OT) Interview questions -- your response?
by John M. Dlugosz (Monsignor) on Sep 03, 2002 at 21:49 UTC
    In Perl6, will ~= between two lists give their intersection in list context?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://194857]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2019-06-19 04:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (83 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!