diff options
| -rw-r--r-- | challenge-243/cheok-yin-fung/perl/ch-1.pl | 19 | ||||
| -rw-r--r-- | challenge-243/cheok-yin-fung/perl/ch-2.pl | 19 |
2 files changed, 38 insertions, 0 deletions
diff --git a/challenge-243/cheok-yin-fung/perl/ch-1.pl b/challenge-243/cheok-yin-fung/perl/ch-1.pl new file mode 100644 index 0000000000..bd99fce9c2 --- /dev/null +++ b/challenge-243/cheok-yin-fung/perl/ch-1.pl @@ -0,0 +1,19 @@ +# The Weekly Challenge 243 +# Task 1 Reverse Pairs +use v5.30.0; +use warnings; + +sub rp { + my @nums = @_; + my $ans = 0; + for my $j (reverse 1..$#nums) { + for my $i (0..$j-1) { + $ans++ if $nums[$i] > 2*$nums[$j]; + } + } + return $ans; +} + +use Test::More tests=>2; +ok rp(1,3,2,3,1) == 2; +ok rp(2,4,3,5,1) == 3; diff --git a/challenge-243/cheok-yin-fung/perl/ch-2.pl b/challenge-243/cheok-yin-fung/perl/ch-2.pl new file mode 100644 index 0000000000..d7148a55f2 --- /dev/null +++ b/challenge-243/cheok-yin-fung/perl/ch-2.pl @@ -0,0 +1,19 @@ +# The Weekly Challenge 243 +# Task 2 Floor Sum +use v5.30.0; +use warnings; + +sub fs { + my @nums = @_; + my $sum = 0; + for my $m (@nums) { + for my $n (@nums) { + $sum += int($m/$n); + } + } + return $sum; +} + +use Test::More tests=>2; +ok fs(2,5,9) == 10; +ok fs(7,7,7,7,7,7,7) == 49; |
