ChOas has asked for the wisdom of the Perl Monks concerning the following question:
Hey People,
As usual leons and I were coding a bit, and tried
to find a way to mix n number of m lenght arrays
together, preserving the original order of the
original arrays
I came up with this:
Anyway to do it quicker/more efficient/shorter ?
GreetZ!,
print "profeth still\n" if /bird|devil/;
As usual leons and I were coding a bit, and tried
to find a way to mix n number of m lenght arrays
together, preserving the original order of the
original arrays
I came up with this:
Output: 1 2 9 3 4 9 5 6 9 7#!/usr/bin/perl -w use strict; sub Mix; my @Row1=(1,3,5,7); my @Row2=(2,4,6); my @Row3=(9,9,9); my @Row4=Mix(\@Row1,\@Row2,\@Row3); print "@Row4\n"; sub Mix { my @Result; while(1) { my $Old=@Result; push @Result,grep $_,shift @{$_} for @_; last if @Result==$Old; }; @Result; };
Anyway to do it quicker/more efficient/shorter ?
GreetZ!,
- ChOas
print "profeth still\n" if /bird|devil/;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Mixing up da Arrays (Golf)
by jmcnamara (Monsignor) on Apr 18, 2001 at 18:38 UTC | |
(tye)Re: Mixing up da Arrays (Golf)
by tye (Sage) on Apr 18, 2001 at 18:02 UTC | |
Re (tilly) 1: Mixing up da Arrays (Golf)
by tilly (Archbishop) on Apr 18, 2001 at 19:39 UTC | |
Re: Mixing up da Arrays (Golf)
by arhuman (Vicar) on Apr 18, 2001 at 18:44 UTC | |
Re: Mixing up da Arrays (Golf)
by kschwab (Vicar) on Apr 18, 2001 at 18:24 UTC | |
Re: Mixing up da Arrays (Golf) (Russ=53)
by Russ (Deacon) on Apr 19, 2001 at 00:22 UTC | |
by tilly (Archbishop) on Apr 19, 2001 at 03:52 UTC | |
Re: Mixing up da Arrays (Golf)
by little (Curate) on Apr 18, 2001 at 18:04 UTC | |
Re: Mixing up da Arrays (Golf)
by premchai21 (Curate) on Apr 18, 2001 at 22:25 UTC |
Back to
Seekers of Perl Wisdom