Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Golf/Perlish solution to this problem?

by 2Bad4U (Initiate)
on Jan 31, 2008 at 09:11 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://665306]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 21:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found