aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostas <yannakakis.kon@gmail.com>2021-08-26 23:24:16 +0200
committerKostas <yannakakis.kon@gmail.com>2021-08-26 23:24:16 +0200
commit508f0bc4f1e0ef6275ae51751c6bc411c926fcdf (patch)
treecf119fd354adf6c80c216687684ed14c99f2de33
parent6d40480d994bdf86439eacb219d9ac94314204c5 (diff)
downloadperlweeklychallenge-club-508f0bc4f1e0ef6275ae51751c6bc411c926fcdf.tar.gz
perlweeklychallenge-club-508f0bc4f1e0ef6275ae51751c6bc411c926fcdf.tar.bz2
perlweeklychallenge-club-508f0bc4f1e0ef6275ae51751c6bc411c926fcdf.zip
solution for challenge 1
-rw-r--r--challenge-127/kostas-giannakakis/perl/ch-1.pl32
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-127/kostas-giannakakis/perl/ch-1.pl b/challenge-127/kostas-giannakakis/perl/ch-1.pl
new file mode 100644
index 0000000000..35678ad2f9
--- /dev/null
+++ b/challenge-127/kostas-giannakakis/perl/ch-1.pl
@@ -0,0 +1,32 @@
+use strict;
+use warnings;
+
+my @S1 = (1, 2, 5, 3, 4);
+my @S2 = (4, 2, 7, 8, 9);
+
+my @S3;
+my @S3_sort;
+my @result;
+
+foreach (@S1, @S2) {
+ push @S3, $_;
+}
+
+@S3_sort = sort { $a <=> $b } @S3;
+
+for(my $i = 0; $i < $#S3_sort; $i++){
+ last if $i == $#S3-1;
+ if ($S3_sort[$i] == $S3_sort[$i + 1]) {
+ push @result, $S3_sort[$i];
+ }
+}
+
+if (scalar(@result) > 0) {
+ print "0 as the given two sets have common member(s)";
+ foreach (@result) {
+ print " $_";
+ }
+ print ".\n";
+} else {
+ print "1 as the given two sets do not have common member.\n";
+} \ No newline at end of file