diff options
| -rw-r--r-- | challenge-040/paulo-custodio/Makefile | 2 | ||||
| -rw-r--r-- | challenge-040/paulo-custodio/README | 1 | ||||
| -rw-r--r-- | challenge-040/paulo-custodio/perl/ch-1.pl | 40 | ||||
| -rw-r--r-- | challenge-040/paulo-custodio/perl/ch-2.pl | 35 | ||||
| -rw-r--r-- | challenge-040/paulo-custodio/t/test-1.yaml | 13 | ||||
| -rw-r--r-- | challenge-040/paulo-custodio/t/test-2.yaml | 5 |
6 files changed, 96 insertions, 0 deletions
diff --git a/challenge-040/paulo-custodio/Makefile b/challenge-040/paulo-custodio/Makefile new file mode 100644 index 0000000000..c3c762d746 --- /dev/null +++ b/challenge-040/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-040/paulo-custodio/README b/challenge-040/paulo-custodio/README new file mode 100644 index 0000000000..87dc0b2fbd --- /dev/null +++ b/challenge-040/paulo-custodio/README @@ -0,0 +1 @@ +Solution by Paulo Custodio diff --git a/challenge-040/paulo-custodio/perl/ch-1.pl b/challenge-040/paulo-custodio/perl/ch-1.pl new file mode 100644 index 0000000000..a2a0864467 --- /dev/null +++ b/challenge-040/paulo-custodio/perl/ch-1.pl @@ -0,0 +1,40 @@ +#!/usr/bin/env perl + +# Challenge 040 +# +# TASK #1 +# Show multiple arrays content +# You are given two or more arrays. Write a script to display values of each +# list at a given index. +# +# For example: +# +# Array 1: [ I L O V E Y O U ] +# Array 2: [ 2 4 0 3 2 0 1 9 ] +# Array 3: [ ! ? @ $ % ^ & * ] +# We expect the following output: +# +# I 2 ! +# L 4 ? +# O 0 @ +# V 3 $ +# E 2 % +# Y 0 ^ +# O 1 & +# U 9 * + +use Modern::Perl; + +show_multiple([qw( I L O V E Y O U )], + [qw( 2 4 0 3 2 0 1 9 )], + [qw( ! ? @ $ % ^ & * )]); + +sub show_multiple { + my(@data) = @_; + for my $i (0 .. $#{$data[0]}) { + for (@data) { + print $_->[$i]," "; + } + print "\n"; + } +} diff --git a/challenge-040/paulo-custodio/perl/ch-2.pl b/challenge-040/paulo-custodio/perl/ch-2.pl new file mode 100644 index 0000000000..2194cfebb9 --- /dev/null +++ b/challenge-040/paulo-custodio/perl/ch-2.pl @@ -0,0 +1,35 @@ +#!/usr/bin/env perl + +# Challenge 040 +# +# TASK #2 +# Sort SubList +# You are given a list of numbers and set of indices belong to the list. +# Write a script to sort the values belongs to the indices. +# +# For example, +# +# List: [ 10, 4, 1, 8, 12, 3 ] +# Indices: 0,2,5 +# We would sort the values at indices 0, 2 and 5 i.e. 10, 1 and 3. +# +# Final List would look like below: +# +# List: [ 1, 4, 3, 8, 12, 10 ] + +use Modern::Perl; + +my @list = (10, 4, 1, 8, 12, 3); +my @indices = (0,2,5); + +@list = sort_sublist(\@list, \@indices); +say "[", join(", ", @list), "]"; + +sub sort_sublist { + my($list, $indices) = @_; + my @list = @$list; + my @indices = @$indices; + my @values = sort {$a<=>$b} @list[@indices]; + @list[@indices] = @values; + return @list; +} diff --git a/challenge-040/paulo-custodio/t/test-1.yaml b/challenge-040/paulo-custodio/t/test-1.yaml new file mode 100644 index 0000000000..da15f04e81 --- /dev/null +++ b/challenge-040/paulo-custodio/t/test-1.yaml @@ -0,0 +1,13 @@ +- setup: + cleanup: + args: + input: + output: | + |I 2 ! + |L 4 ? + |O 0 @ + |V 3 $ + |E 2 % + |Y 0 ^ + |O 1 & + |U 9 * diff --git a/challenge-040/paulo-custodio/t/test-2.yaml b/challenge-040/paulo-custodio/t/test-2.yaml new file mode 100644 index 0000000000..c5feb3b973 --- /dev/null +++ b/challenge-040/paulo-custodio/t/test-2.yaml @@ -0,0 +1,5 @@ +- setup: + cleanup: + args: + input: + output: [1, 4, 3, 8, 12, 10] |
