From d21729c11befcb9b09747e8ae7d79bd3d8d69744 Mon Sep 17 00:00:00 2001 From: drbaggy Date: Mon, 6 Jun 2022 22:38:47 +0100 Subject: add in the next 12 perrin primes using big int support --- challenge-168/james-smith/perl/ch-1.pl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'challenge-168') diff --git a/challenge-168/james-smith/perl/ch-1.pl b/challenge-168/james-smith/perl/ch-1.pl index e8f0ab5d01..2f25fc5369 100644 --- a/challenge-168/james-smith/perl/ch-1.pl +++ b/challenge-168/james-smith/perl/ch-1.pl @@ -4,6 +4,7 @@ use strict; use warnings; use feature qw(say); use Math::Prime::Util qw(is_prime); +use Math::BigInt; ## This is straight forward. ## In each interation of the loop, we remove the lowest number of the triple, @@ -14,6 +15,14 @@ use Math::Prime::Util qw(is_prime); ## then we restart the loop with redo, if not we display the number and ## continue until we have displayed the first 13 perrin primes. +say "\nWith normal ints (first 25)\n\n"; my ($r,$s,$t)=(3,0,2); -($r,$s,$t)=($s,$t,$r+$s), is_prime($t) && $t!=$s ? (say $t) : (redo) for 1..13 +($r,$s,$t)=($s,$t,$r+$s), is_prime($t) && $t!=$s ? (say $t) : (redo) for 1..13; +## Now with big ints... +say "\n\nWith big ints (first 25)\n\n"; + +($r,$s,$t)=(3,0,Math::BigInt->new(2)); +($r,$s,$t)=($s,$t,$r+$s), is_prime($t) && $t!=$s ? (say $t) : (redo) for 1..25; + +say "\n"; -- cgit