From 8d0d58de8ba34070228f62b67b8c8fd7a4e27373 Mon Sep 17 00:00:00 2001 From: Steven Wilson Date: Fri, 14 Jan 2022 13:34:14 +0000 Subject: fix for floating point modulus --- challenge-147/steven-wilson/perl/ch-02.pl | 5 +++-- 1 file 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; } -- cgit