aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2023-08-01 11:32:29 +0100
committerGitHub <noreply@github.com>2023-08-01 11:32:29 +0100
commitec6683ae9baac445cc516cef50432f6b23362b1a (patch)
tree9c1de3fb83374f1df08818d45cbceff9abe1eaab
parentb7c6ba230d95ffad246f0f9874e82cbd95e12f56 (diff)
parent552e1f5454e2ba7433c0a85c15290740f0d8839f (diff)
downloadperlweeklychallenge-club-ec6683ae9baac445cc516cef50432f6b23362b1a.tar.gz
perlweeklychallenge-club-ec6683ae9baac445cc516cef50432f6b23362b1a.tar.bz2
perlweeklychallenge-club-ec6683ae9baac445cc516cef50432f6b23362b1a.zip
Merge pull request #8486 from zapwai/branch-for-228
Week 228
-rw-r--r--challenge-228/zapwai/perl/ch-1.pl16
-rw-r--r--challenge-228/zapwai/perl/ch-2.pl28
2 files changed, 44 insertions, 0 deletions
diff --git a/challenge-228/zapwai/perl/ch-1.pl b/challenge-228/zapwai/perl/ch-1.pl
new file mode 100644
index 0000000000..1c51e0588b
--- /dev/null
+++ b/challenge-228/zapwai/perl/ch-1.pl
@@ -0,0 +1,16 @@
+use v5.30;
+my @int1 = (2,1,3,2);
+my @int2 = (1,1,1,1);
+my @int3 = (1,2,3,4);
+for my $r (\@int1, \@int2, \@int3) {
+ my @int = @$r;
+ say "Input: \@int = (" . join(",",@int) . ")";
+ print "Output: ";
+ my %h;
+ $h{$_}++ for (@int);
+ my $sum = 0;
+ for (keys %h) {
+ $sum = $sum + $_ if ($h{$_} == 1);
+ }
+ say $sum;
+}
diff --git a/challenge-228/zapwai/perl/ch-2.pl b/challenge-228/zapwai/perl/ch-2.pl
new file mode 100644
index 0000000000..7034fe626c
--- /dev/null
+++ b/challenge-228/zapwai/perl/ch-2.pl
@@ -0,0 +1,28 @@
+use v5.30;
+my @int = (3,4,2);
+say "Input: \@int = (" . join(",",@int) .")";
+print "Output: ";
+my $c = run(@int);
+say $c;
+sub run {
+ my @l = @_;
+ my $cnt = 0;
+ do {
+ if ( min(@l) == $l[0] ) {
+ shift @l;
+ } else {
+ my $r = shift @l;
+ push @l, $r;
+ }
+ $cnt++;
+ } while (@l);
+ return $cnt;
+}
+sub min {
+ my @l = @_;
+ my $min = 1000000;
+ for (@l) {
+ $min = $_ if ($min > $_);
+ }
+ return $min;
+}