diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2019-12-29 23:19:20 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2019-12-29 23:19:20 +0000 |
| commit | f688d52f174dc6038d6f01e487aa6c73990a65a5 (patch) | |
| tree | f2ef58067f6e5ec084cfdf1285ad14f159810cd1 /challenge-040 | |
| parent | fab1fb6bd7153c6c58ee92215621113f1f4cb389 (diff) | |
| download | perlweeklychallenge-club-f688d52f174dc6038d6f01e487aa6c73990a65a5.tar.gz perlweeklychallenge-club-f688d52f174dc6038d6f01e487aa6c73990a65a5.tar.bz2 perlweeklychallenge-club-f688d52f174dc6038d6f01e487aa6c73990a65a5.zip | |
- Added solutions by Adam Russell.
Diffstat (limited to 'challenge-040')
| -rw-r--r-- | challenge-040/adam-russell/perl5/ch-1.pl | 26 | ||||
| -rw-r--r-- | challenge-040/adam-russell/perl5/ch-2.pl | 18 |
2 files changed, 44 insertions, 0 deletions
diff --git a/challenge-040/adam-russell/perl5/ch-1.pl b/challenge-040/adam-russell/perl5/ch-1.pl new file mode 100644 index 0000000000..c3ade63d6f --- /dev/null +++ b/challenge-040/adam-russell/perl5/ch-1.pl @@ -0,0 +1,26 @@ +use strict; +use warnings; +## +# Show multiple arrays content. +## +use Readonly; +Readonly::Array my @A => qw/I L O V E Y O U/; +Readonly::Array my @B => qw/2 4 0 3 2 0 1 9/; +Readonly::Array my @C => qw/! ? £ $ % ^ & */; + +sub display{ + my($arrays) = @_; + my $max_index = (sort {$a <=> $b} map {scalar @{$_}} @{$arrays})[-1] - 1; + for my $x (0 .. $max_index){ + for my $a (@{$arrays}){ + print $a->[$x] // ""; + print "\t"; + } + print "\n"; + } +} + +MAIN:{ + display([\@A, \@B, \@C]); +} + diff --git a/challenge-040/adam-russell/perl5/ch-2.pl b/challenge-040/adam-russell/perl5/ch-2.pl new file mode 100644 index 0000000000..dfaf6f1496 --- /dev/null +++ b/challenge-040/adam-russell/perl5/ch-2.pl @@ -0,0 +1,18 @@ +use strict; +use warnings; +## +# You are given a list of numbers and a set of indices +# belonging to the list. Write a script to sort the values +# that belong to the indices. +## +use Readonly; +Readonly::Array my @A => qw/10 4 1 8 12 3/; +Readonly::Array my @INDICES => qw/0 2 5/; + +my @sorted = @A; +my @sorted_values = sort {$a <=> $b} map {$A[$_]} @INDICES; +my @sorted_indices = sort {$a <=> $b} @INDICES; +for my $i (@sorted_indices){ + $sorted[$i] = shift @sorted_values; +} +print join(", ", @sorted) . "\n"; |
