aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevSanti12 <santiagoleyva2013@gmail.com>2024-07-08 09:04:08 -0500
committerDevSanti12 <santiagoleyva2013@gmail.com>2024-07-08 09:04:08 -0500
commit9eb20bfdab43e09c69a4975a26e21d4df64b9408 (patch)
treee43c7078abd921354cfeff1bca34cf1612f9b61d
parent40125a7671e65336f2b00e5dd385015ea62d51f3 (diff)
downloadperlweeklychallenge-club-9eb20bfdab43e09c69a4975a26e21d4df64b9408.tar.gz
perlweeklychallenge-club-9eb20bfdab43e09c69a4975a26e21d4df64b9408.tar.bz2
perlweeklychallenge-club-9eb20bfdab43e09c69a4975a26e21d4df64b9408.zip
added perl challenge 277
-rw-r--r--challenge-277/santiago-leyva/TASK_1.pl35
-rw-r--r--challenge-277/santiago-leyva/TASK_2.pl36
2 files changed, 71 insertions, 0 deletions
diff --git a/challenge-277/santiago-leyva/TASK_1.pl b/challenge-277/santiago-leyva/TASK_1.pl
new file mode 100644
index 0000000000..5811987afe
--- /dev/null
+++ b/challenge-277/santiago-leyva/TASK_1.pl
@@ -0,0 +1,35 @@
+use strict;
+use Data::Dumper;
+
+my @words1 = ("Perl", "is", "my", "friend");
+my @words2 = ("Perl", "and", "Raku", "are", "friend");
+
+#my @words1 = ("Perl", "and", "Python", "are", "very", "similar");
+#my @words2 = ("Python", "is", "top", "in", "guest", "languages");
+
+#my @words1 = ("Perl", "is", "imperative", "Lisp", "is", "functional");
+#my @words2 = ("Crystal", "is", "similar", "to", "Ruby");
+
+#You are given two array of strings, @words1 and @words2.
+
+#Write a script to return the count of words that appears in both arrays exactly once.
+
+my %hash1;
+my %hash2;
+my $counter;
+
+for(my $i;$i<(scalar @words1);$i++){
+ if(!exists($hash1{$words1[$i]})){
+ $hash1{$words1[$i]} = '';
+ next;
+ }else{
+ delete $hash1{$words1[$i]};
+ }
+}
+for(my $i;$i<(scalar @words2);$i++){
+ if(exists($hash1{$words2[$i]})){
+ $counter+=1;
+ }
+}
+
+print $counter; \ No newline at end of file
diff --git a/challenge-277/santiago-leyva/TASK_2.pl b/challenge-277/santiago-leyva/TASK_2.pl
new file mode 100644
index 0000000000..6c7b0ff090
--- /dev/null
+++ b/challenge-277/santiago-leyva/TASK_2.pl
@@ -0,0 +1,36 @@
+#!/usr/bin/perl
+use strict;
+use Data::Dumper;
+use List::Util qw(min);
+
+
+#You are given an array of integers, @ints.
+
+#Write a script to return the count of all strong pairs in the given array.
+#A pair of integers x and y is called strong pair if it satisfies: 0 < |x - y| < min(x, y)
+my @ints = (1, 2, 3, 4, 5);
+#my @ints = (5, 7, 1, 7);
+my @pairs;
+my %seen;
+my $key;
+my $j;
+# 0 < |2-3| < min(2,3)
+
+for(my $i; $i<(scalar @ints); $i++){
+ $j = $i+1;
+ while($j < (scalar @ints)){
+
+ if((abs($ints[$i]-$ints[$j]) > 0) && ((abs($ints[$i]-$ints[$j])) < min($ints[$i],$ints[$j]))){
+ $key = $ints[$i].",".$ints[$j];
+ if(!exists($seen{$key})){
+ $seen{$key} = '';
+ push @pairs,[$ints[$i],$ints[$j]];
+ }else{}
+ }
+ $j+=1;
+ }
+}
+
+foreach(@pairs){
+ print Dumper $_;
+} \ No newline at end of file