Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Golf/Perlish solution to this problem?

by ikegami (Pope)
on Jan 31, 2008 at 02:38 UTC ( #665265=note: print w/replies, xml ) Need Help??


in reply to Golf/Perlish solution to this problem?

Works with any number of elements, non-destructive:

sub a { @_<2 ? @_ : (pop,shift,&b) } sub b { @_<2 ? @_ : (shift,pop,&a) } print a(1..8), "\n";

Works with a multiple of 4 elements, non-destructive:

sub a { @_ ? (@_[-1,0,1,-2],a(@_[2..$#_-2])) : () } print a(1..8), "\n";

Update: Even shorter,

Works with a multiple of 4 elements, non-destructive:

sub a { @_ ? (pop,shift,shift,pop,&a) : () } print a(1..8), "\n";

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2021-01-24 04:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?