diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-01-29 11:35:46 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-29 11:35:46 +0000 |
| commit | 271b545bdf999895f716e3fdd1294e0f522a047e (patch) | |
| tree | dec3bac2ed44e6464d16d29fb57e32e1154bc5c4 | |
| parent | 308f27664fba4114bde4771c5a5d5204c8b43467 (diff) | |
| parent | 06cc3b3b9b79c144194dcd0a82b3d984a1320d7e (diff) | |
| download | perlweeklychallenge-club-271b545bdf999895f716e3fdd1294e0f522a047e.tar.gz perlweeklychallenge-club-271b545bdf999895f716e3fdd1294e0f522a047e.tar.bz2 perlweeklychallenge-club-271b545bdf999895f716e3fdd1294e0f522a047e.zip | |
Merge pull request #7481 from E7-87-83/newt
Week 201
| -rw-r--r-- | challenge-201/cheok-yin-fung/perl/ch-1.pl | 20 | ||||
| -rw-r--r-- | challenge-201/cheok-yin-fung/perl/ch-2.pl | 34 |
2 files changed, 54 insertions, 0 deletions
diff --git a/challenge-201/cheok-yin-fung/perl/ch-1.pl b/challenge-201/cheok-yin-fung/perl/ch-1.pl new file mode 100644 index 0000000000..f6034aaa70 --- /dev/null +++ b/challenge-201/cheok-yin-fung/perl/ch-1.pl @@ -0,0 +1,20 @@ +# The Weekly Challenge 201 +# Task 1 Missing Numbers + +sub mn { + my @arr = @_; + my $tail = scalar @arr; + my %check; + $check{$_} = 1 for @arr; + my @ans; + for (0..$tail) { + push @ans, $_ if !$check{$_}; + } + return [@ans]; +} + + +use Test::More tests=>2; +use Test::Deep; +cmp_deeply(mn(0,1,3), [2]); +cmp_deeply(mn(0,1), [2]); diff --git a/challenge-201/cheok-yin-fung/perl/ch-2.pl b/challenge-201/cheok-yin-fung/perl/ch-2.pl new file mode 100644 index 0000000000..0e01f45f52 --- /dev/null +++ b/challenge-201/cheok-yin-fung/perl/ch-2.pl @@ -0,0 +1,34 @@ +# The Weekly Challenge 201 +# Task 2 Penny Piles + +use v5.30.0; +use warnings; + +# algorithm devised by J. Kelleher + +my $n = $ARGV[0] || 5; + +my $num_of_ways = 0; +my @a = (0) x ($n+2); +$a[1] = $n; +my $cnt = 1; +while ($cnt != 0) { + my $xdum = $a[$cnt-1]+1; + my $ydum = $a[$cnt]-1; + $cnt--; + while ($xdum <= $ydum) { + $a[$cnt] = $xdum; + $ydum -= $xdum; + $cnt++; + } + $a[$cnt] = $xdum+$ydum; + # Print Result + for my $i (0..$cnt) { + print $a[$i], " "; + } + $num_of_ways++; + say ""; +} + +# Print Final Result +say "Number of Ways: ", $num_of_ways; |
