diff options
| author | David Ferrone <zapwai@gmail.com> | 2023-11-20 11:48:12 -0500 |
|---|---|---|
| committer | David Ferrone <zapwai@gmail.com> | 2023-11-20 11:48:12 -0500 |
| commit | 7a80ccb85e3c923fe061fac9f4912c7b2c6f7e70 (patch) | |
| tree | af2c8fb14bc0aa6b754da66c78eeea8f0bb86b22 | |
| parent | d3c171ecb6715a7bd21a52fab583c4171605f5c0 (diff) | |
| download | perlweeklychallenge-club-7a80ccb85e3c923fe061fac9f4912c7b2c6f7e70.tar.gz perlweeklychallenge-club-7a80ccb85e3c923fe061fac9f4912c7b2c6f7e70.tar.bz2 perlweeklychallenge-club-7a80ccb85e3c923fe061fac9f4912c7b2c6f7e70.zip | |
Week 244
| -rw-r--r-- | challenge-244/zapwai/perl/ch-1.pl | 12 | ||||
| -rw-r--r-- | challenge-244/zapwai/perl/ch-2.pl | 22 |
2 files changed, 34 insertions, 0 deletions
diff --git a/challenge-244/zapwai/perl/ch-1.pl b/challenge-244/zapwai/perl/ch-1.pl new file mode 100644 index 0000000000..354f993e36 --- /dev/null +++ b/challenge-244/zapwai/perl/ch-1.pl @@ -0,0 +1,12 @@ +use v5.30; +my @int = (8,1,2,2,3); +my @ans; +foreach my $i (@int) { + my $cnt = 0; + for my $j (@int) { + $cnt++ if ($j < $i); + } + push @ans, $cnt; +} +say "Input : \@int = (" .join(", ",@int).")"; +say "Output: \@ans = (" .join(", ",@ans).")"; diff --git a/challenge-244/zapwai/perl/ch-2.pl b/challenge-244/zapwai/perl/ch-2.pl new file mode 100644 index 0000000000..1e5176add2 --- /dev/null +++ b/challenge-244/zapwai/perl/ch-2.pl @@ -0,0 +1,22 @@ +use v5.30; +use List::Util qw(sum max min); +use Math::Combinatorics; +my @nums = (2,1,4); +my $sum = 0; +for my $cnt (1 .. @nums) { + my $comb = Math::Combinatorics->new( + count => $cnt, + data => [@nums] + ); + while (my @combo = $comb->next_combination) { + # say @combo," --> ", pow(@combo); + $sum += pow(@combo); + } +} +sub pow { + my $m = min @_; + my $M = max @_; + return $m*$M**2; +} +say "Input : \@nums = (" .join(", ",@nums).")"; +say "Output: $sum"; |
