Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Golf/Perlish solution to this problem?

by 2Bad4U (Initiate)
on Jan 31, 2008 at 09:11 UTC ( #665306=note: print w/replies, xml ) Need Help??


in reply to Golf/Perlish solution to this problem?

here is my solution (hopefully i haven't overseen something...):
#!/usr/bin/perl use strict; use warnings; my @in = (1 .. 12); my @out = reverse @in[$#in / 2 + 1 .. $#in]; splice @out, $_ * 2 - (($_ % 2) ? 1 : 2), 0, $_ for (@in[0 .. $#in / 2 +]); print "in: \t@in\n"; print "out: \t@out\n";
prints:
in: 1 2 3 4 5 6 7 8 9 10 11 12
out: 12 1 2 11 10 3 4 9 8 5 6 7

bye

update 1: corrected the code and added the output

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2021-01-15 22:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?