aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-147/steven-wilson/perl/ch-02.pl5
1 files changed, 3 insertions, 2 deletions
diff --git a/challenge-147/steven-wilson/perl/ch-02.pl b/challenge-147/steven-wilson/perl/ch-02.pl
index 65f41f0585..d1bf716a76 100644
--- a/challenge-147/steven-wilson/perl/ch-02.pl
+++ b/challenge-147/steven-wilson/perl/ch-02.pl
@@ -3,11 +3,12 @@
# Pentagon Numbers
# Write a sript to find the first pair of Pentagon Numbers
# whose sum and difference are also a Pentagon Number.
-# Answer: First pair is 210 and 330
+# Answer: First pair is 1560090 and 7042750
use strict;
use warnings;
use feature qw/ say /;
+use POSIX qw/ fmod /;
my @pentagonal_numbers = qw/ 1 /;
my $first_pair_found = 0;
@@ -35,6 +36,6 @@ sub pentagonal_number {
sub is_pentagonal_number {
my $x = shift;
- my $remainder = ( sqrt( 24 * $x + 1 ) + 1 ) % 6;
+ my $remainder = fmod( sqrt( 24 * $x + 1 ) + 1, 6 );
$remainder > 0 ? return 0 : return 1;
}