aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-07-26 10:14:10 +0100
committerGitHub <noreply@github.com>2024-07-26 10:14:10 +0100
commiteab23825583155f271beb85e94b3bf41241a13a5 (patch)
treebdda75953504e53a988730e07751b539af5adfd9
parent2b73288e096743432a16869d662b7ca39dd32784 (diff)
parentdb40d75f603f3fae34944cb3a762b290b18577d8 (diff)
downloadperlweeklychallenge-club-eab23825583155f271beb85e94b3bf41241a13a5.tar.gz
perlweeklychallenge-club-eab23825583155f271beb85e94b3bf41241a13a5.tar.bz2
perlweeklychallenge-club-eab23825583155f271beb85e94b3bf41241a13a5.zip
Merge pull request #10494 from DevSanti12/master
Added challenges for #279 for perl
-rw-r--r--challenge-279/santiago-leyva/perl/ch-01.pl46
-rw-r--r--challenge-279/santiago-leyva/perl/ch-02.pl46
2 files changed, 92 insertions, 0 deletions
diff --git a/challenge-279/santiago-leyva/perl/ch-01.pl b/challenge-279/santiago-leyva/perl/ch-01.pl
new file mode 100644
index 0000000000..51f8683eb8
--- /dev/null
+++ b/challenge-279/santiago-leyva/perl/ch-01.pl
@@ -0,0 +1,46 @@
+=begin
+
+You are given two arrays, @letters and @weights.
+
+Write a script to sort the given array @letters based on the @weights.
+
+Example 1
+Input: @letters = ('R', 'E', 'P', 'L')
+ @weights = (3, 2, 1, 4)
+Output: PERL
+Example 2
+Input: @letters = ('A', 'U', 'R', 'K')
+ @weights = (2, 4, 1, 3)
+Output: RAKU
+Example 3
+Input: @letters = ('O', 'H', 'Y', 'N', 'P', 'T')
+ @weights = (5, 4, 2, 6, 1, 3)
+Output: PYTHON
+
+=cut
+
+use strict;
+use Data::Dumper;
+
+my @letters = (['R', 'E', 'P', 'L'],['A', 'U', 'R', 'K'],['O', 'H', 'Y', 'N', 'P', 'T']);
+my @weights = ([3, 2, 1, 4],[2, 4, 1, 3],[5, 4, 2, 6, 1, 3]);
+
+for(0..(scalar @weights)-1){
+ sortArray($letters[$_],$weights[$_]);
+}
+
+sub sortArray {
+ my $let = shift;
+ my $wgt = shift;
+ my @letters_ = @$let;
+ my @weights_ = @$wgt;
+ my %map;
+ my $n = scalar(@weights_);
+ foreach my $i (0..$n){
+ $map{$weights_[$i]} = $letters_[$i];
+ }
+ foreach(sort(keys %map)){
+ print $map{$_};
+ }
+ print "\n";
+} \ No newline at end of file
diff --git a/challenge-279/santiago-leyva/perl/ch-02.pl b/challenge-279/santiago-leyva/perl/ch-02.pl
new file mode 100644
index 0000000000..13c9e64f08
--- /dev/null
+++ b/challenge-279/santiago-leyva/perl/ch-02.pl
@@ -0,0 +1,46 @@
+=begin
+
+You are given a string, $str.
+
+Write a script to split the given string into two containing exactly same number of vowels and return true if you can otherwise false.
+
+Example 1
+Input: $str = "perl"
+Ouput: false
+
+Example 2
+Input: $str = "book"
+Ouput: true
+Two possible strings "bo" and "ok" containing exactly one vowel each.
+
+Example 3
+Input: $str = "good morning"
+Ouput: true
+Two possible strings "good " and "morning" containing two vowels each or "good m" and "orning" containing two vowels each.
+
+=cut
+use strict;
+use warnings;
+use Data::Dumper;
+
+my @strings = (["perl"],["book"],["good morning"]);
+
+foreach(@strings){
+ print vowelCheck($_)."\n";
+}
+
+sub vowelCheck {
+ my $string_ = shift;
+ my $string = @$string_[0];
+ my @A = split("",$string);
+ my @vowels;
+
+ for(my $i=0;$i<(scalar @A); $i++){
+ if($A[$i] =~ /[aeiouAEIOU]/){
+ push @vowels,$A[$i];
+ }
+ }
+
+ return "True" if(scalar @vowels % 2 == 0);
+ return "False" if(scalar @vowels % 2 != 0);
+} \ No newline at end of file