aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevSanti12 <santiagoleyva2013@gmail.com>2024-08-07 09:11:05 -0500
committerDevSanti12 <santiagoleyva2013@gmail.com>2024-08-07 09:11:05 -0500
commit45e7a2eb059718b8b0208c80a2531a2b6921e381 (patch)
tree75d5fb4f549f25a5fa87275a88f48a7c29b9177b
parent74d6f5b5d7b341e12055ea73d3e3e0576fdc2b18 (diff)
downloadperlweeklychallenge-club-45e7a2eb059718b8b0208c80a2531a2b6921e381.tar.gz
perlweeklychallenge-club-45e7a2eb059718b8b0208c80a2531a2b6921e381.tar.bz2
perlweeklychallenge-club-45e7a2eb059718b8b0208c80a2531a2b6921e381.zip
added perl challenge 280
-rw-r--r--challenge-280/santiago-leyva/perl/ch-1.pl47
-rw-r--r--challenge-280/santiago-leyva/perl/ch-2.pl63
2 files changed, 110 insertions, 0 deletions
diff --git a/challenge-280/santiago-leyva/perl/ch-1.pl b/challenge-280/santiago-leyva/perl/ch-1.pl
new file mode 100644
index 0000000000..c1aa100e21
--- /dev/null
+++ b/challenge-280/santiago-leyva/perl/ch-1.pl
@@ -0,0 +1,47 @@
+=begin
+
+You are given a string, $str, containing lowercase English letters only.
+Write a script to print the first letter that appears twice.
+
+Example 1
+Input: $str = "acbddbca"
+Output: "d"
+
+Example 2
+Input: $str = "abccd"
+Output: "c"
+
+Example 3
+Input: $str = "abcdabbb"
+Output: "a"
+
+=cut
+
+use strict;
+use warnings;
+use Data::Dumper;
+
+my @strings = ("acbddbca","abccd","abcdabbb");
+
+foreach(@strings){
+ my $result = findletter($_);
+ print "$_ -> $result \n";
+}
+
+sub findletter {
+
+ my $str = shift;
+ my @A = split("",$str);
+ my %seen;
+
+ foreach(@A){
+
+ if(!exists($seen{$_})){
+ $seen{$_} = "";
+ next;
+ }elsif(exists($seen{$_})){
+ return $_;
+ }
+
+ }
+} \ No newline at end of file
diff --git a/challenge-280/santiago-leyva/perl/ch-2.pl b/challenge-280/santiago-leyva/perl/ch-2.pl
new file mode 100644
index 0000000000..c237ec699c
--- /dev/null
+++ b/challenge-280/santiago-leyva/perl/ch-2.pl
@@ -0,0 +1,63 @@
+=begin
+
+You are given a string, $str, where every two consecutive vertical bars are grouped into a pair.
+
+Write a script to return the number of asterisks, *, excluding any between each pair of vertical bars.
+
+Example 1
+Input: $str = "p|*e*rl|w**e|*ekly|"
+Ouput: 2
+The characters we are looking here are "p" and "w**e".
+
+Example 2
+Input: $str = "perl"
+Ouput: 0
+
+Example 3
+Input: $str = "th|ewe|e**|k|l***ych|alleng|e"
+Ouput: 5
+
+The characters we are looking here are "th", "e**", "l***ych" and "e".
+
+=cut
+
+use strict;
+use warnings;
+use Data::Dumper;
+
+my @str = ("p|*e*rl|w**e|*ekly|","perl","th|ewe|e**|k|l***ych|alleng|e");
+
+foreach(@str){
+ my $result = findasterik($_);
+ print "$_ -> $result\n";
+}
+
+
+sub findasterik {
+ my $string = shift;
+ my @A = split("",$string);
+ my @A_split;
+ my $temp;
+ my $pos = 0;
+ my $asterik;
+ foreach(@A){
+
+ if($_ eq '|'){
+ @A_split[$pos] = $temp;
+ $pos++;
+ $temp = '';
+ next;
+ }
+ $temp .= $_;
+ }
+
+ my $occurance = 0;
+
+ for(my $i=0;$i<(scalar @A_split);$i+=2){
+ $asterik = () = @A_split[$i] =~ /\*/g;
+ $occurance += $asterik;
+ }
+
+ return $occurance;
+
+} \ No newline at end of file