aboutsummaryrefslogtreecommitdiff
path: root/challenge-157
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-03-27 22:02:28 +0100
committerGitHub <noreply@github.com>2022-03-27 22:02:28 +0100
commit166cf57181a4fa7ff6d5808ad1f14e591f5223d7 (patch)
tree63a9db431e5b4de8ed604d0c5e95c9794c3d57df /challenge-157
parent27c9c994dc0179606edc713b01cdff1d8fedd6cf (diff)
parent1923dc78b889c9449de6e14bc7bdc247416cbb96 (diff)
downloadperlweeklychallenge-club-166cf57181a4fa7ff6d5808ad1f14e591f5223d7.tar.gz
perlweeklychallenge-club-166cf57181a4fa7ff6d5808ad1f14e591f5223d7.tar.bz2
perlweeklychallenge-club-166cf57181a4fa7ff6d5808ad1f14e591f5223d7.zip
Merge pull request #5841 from E7-87-83/newt
minor edit for Week 157
Diffstat (limited to 'challenge-157')
-rw-r--r--challenge-157/cheok-yin-fung/perl/ch-1.pl6
-rw-r--r--challenge-157/cheok-yin-fung/perl/ch-2.pl12
2 files changed, 11 insertions, 7 deletions
diff --git a/challenge-157/cheok-yin-fung/perl/ch-1.pl b/challenge-157/cheok-yin-fung/perl/ch-1.pl
index bdb01e53a6..c1879bb565 100644
--- a/challenge-157/cheok-yin-fung/perl/ch-1.pl
+++ b/challenge-157/cheok-yin-fung/perl/ch-1.pl
@@ -29,17 +29,17 @@ sub mean {
use Test::More tests => 3;
is_deeply(
- [4.8, 3.8, 2.8],
[sort {$b<=>$a} map {sprintf("%.1f", $_)} values mean(1,3,5,6,9)->%*],
+ [4.8, 3.8, 2.8],
"Example 1"
);
is_deeply(
- ["6.0", 5.2, 4.4],
[sort {$b<=>$a} map {sprintf("%.1f", $_)} values mean(2,4,6,8,10)->%*],
+ ["6.0", 5.2, 4.4],
"Example 2"
);
is_deeply(
- ["3.0", 2.6, 2.2],
[sort {$b<=>$a} map {sprintf("%.1f", $_)} values mean(1,2,3,4,5)->%*],
+ ["3.0", 2.6, 2.2],
"Example 3"
);
diff --git a/challenge-157/cheok-yin-fung/perl/ch-2.pl b/challenge-157/cheok-yin-fung/perl/ch-2.pl
index bcd6923fda..05c3a20e2d 100644
--- a/challenge-157/cheok-yin-fung/perl/ch-2.pl
+++ b/challenge-157/cheok-yin-fung/perl/ch-2.pl
@@ -8,7 +8,7 @@ my $N = $ARGV[0] || 10;
my $ans = find($N);
if ($ans) {
- say "$N is a repdigit in base-", find($N), "; therefore it's Brazilian.";
+ say "$N is a repdigit in base-", $ans, "; therefore it's Brazilian.";
}
else {
say "$N is not a Brazilian number."
@@ -32,10 +32,14 @@ sub proper_divisors_lt_one {
# lazy way to find divisors
my $num = $_[0];
my @pd = ();
- for my $i (2..$num/2) {
- push @pd, $i if $num % $i == 0;
+ my @rev_pd = ();
+ for my $i (2..int sqrt $num) {
+ if ($num % $i == 0) {
+ push @pd, $i;
+ unshift @rev_pd, $num/$i;
+ }
}
- return [@pd];
+ return [@pd, @rev_pd];
}