aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2023-06-12 03:42:40 +0100
committerGitHub <noreply@github.com>2023-06-12 03:42:40 +0100
commitbba0c56cec0bbfce1d56dfcc85647a6e89422f36 (patch)
tree965781f38000a6460f1c059944a28448e602df51
parent6e4826e533e536538129a4e72b9930c2c6eaaf5d (diff)
parentbb08e3c1a1e3352862f9c795b60a33a9c81ec64a (diff)
downloadperlweeklychallenge-club-bba0c56cec0bbfce1d56dfcc85647a6e89422f36.tar.gz
perlweeklychallenge-club-bba0c56cec0bbfce1d56dfcc85647a6e89422f36.tar.bz2
perlweeklychallenge-club-bba0c56cec0bbfce1d56dfcc85647a6e89422f36.zip
Merge pull request #8193 from zapwai/branch-for-220
Week 220
-rw-r--r--challenge-220/zapwai/perl/ch-1.pl13
-rw-r--r--challenge-220/zapwai/perl/ch-2.pl33
2 files changed, 46 insertions, 0 deletions
diff --git a/challenge-220/zapwai/perl/ch-1.pl b/challenge-220/zapwai/perl/ch-1.pl
new file mode 100644
index 0000000000..737084de80
--- /dev/null
+++ b/challenge-220/zapwai/perl/ch-1.pl
@@ -0,0 +1,13 @@
+use v5.30.0;
+no warnings;
+my @words = ("Perl", "Rust", "Raku");
+say "Input: \@words = (" . join(",",@words) . ")";
+$words[$_] = lc $words[$_] for (0 .. $#words);
+my @intersection = split("",$words[0]);
+for my $i (1 .. $#words) {
+ my @letters = split("",$words[$i]);
+ for my $j (0 .. $#intersection) {
+ splice(@intersection, $j, 1) unless ($intersection[$j] ~~ @letters);
+ }
+}
+say "Output: @intersection";
diff --git a/challenge-220/zapwai/perl/ch-2.pl b/challenge-220/zapwai/perl/ch-2.pl
new file mode 100644
index 0000000000..eb1e023045
--- /dev/null
+++ b/challenge-220/zapwai/perl/ch-2.pl
@@ -0,0 +1,33 @@
+use v5.30.0;
+use Algorithm::Permute;
+my @ints = (1, 17, 8);
+#my @ints = (2,2,2);
+say "Input: \@ints = (" . join(",",@ints) . ")";
+my $p = Algorithm::Permute->new(\@ints);
+print "Output: ";
+my $out;
+while (my @perm = $p->next) {
+ my $current_print = "(" . join(",",@perm) . ")";
+ next if ($out =~ m/$current_print/);
+ $out .= $current_print if is_squareful(@perm);
+}
+$out =~ s/\)\(/\), \(/;
+say $out;
+
+sub is_squareful {
+ my @list = @_;
+ my $cnt;
+ foreach (0 .. $#list-1) {
+ my $sum = $list[$_] + $list[$_+1];
+ $cnt++ if (is_square($sum));
+ }
+ return 1 if ($cnt == $#list);
+ 0
+}
+
+sub is_square {
+ my $num = shift;
+ my $U = int (sqrt($num));
+ return 1 if ($U**2 == $num);
+ 0
+}