diff options
| -rw-r--r-- | challenge-157/cheok-yin-fung/perl/ch-2.pl | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/challenge-157/cheok-yin-fung/perl/ch-2.pl b/challenge-157/cheok-yin-fung/perl/ch-2.pl index 9f9aeb2a2e..05c3a20e2d 100644 --- a/challenge-157/cheok-yin-fung/perl/ch-2.pl +++ b/challenge-157/cheok-yin-fung/perl/ch-2.pl @@ -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]; } |
