source code
# The Computer Language Benchmarks Game
# https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
#
# contributed by Robert Bradshaw
# modified by Ruud H.G.van Tol
# modified by Emanuele Zeppieri
# modified to use Math:GMP by Kuang-che Wu
use strict;
use Math::GMP;
my($z0, $z1, $z2) = map Math::GMP->new($_),1,0,1;
sub extract_digit { return ($z0*$_[0]+$z1)/$z2; }
sub compose {
if ( defined $_[3] ) {
$z1 = $z1*$_[0]+$_[1]*$z2;
} else {
$z1 = $z1*$_[2]+$_[1]*$z0;
}
$z0 = $z0*$_[0];
$z2 = $z2*$_[2];
return;
}
my $n = $ARGV[0];
($,, $\) = ("\t", "\n");
my ($i, $s, $d); my $k = 0;
# main loop
for $i (1..$n) {
while (
$z0>$z2 || ( $d = extract_digit(3) ) != extract_digit(4)
) {
# y not safe
$k++; compose($k, 4*$k+2, 2*$k+1)
}
compose(10, -10*$d, 1, 1);
$s .= $d;
unless ( $i % 10 ) { print $s, ":$i"; undef $s }
}
$s .= ' ' x (10-$i) if $i = $n % 10;
print $s, ":$n" if $s
notes, command-line, and program output
NOTES:
64-bit Ubuntu quad core
This is perl 5, version 40
subversion 0 (v5.40.0)
x86_64-linux-thread-multi
Mon, 10 Jun 2024 22:53:23 GMT
COMMAND LINE:
/opt/src/perl-5.40.0/bin/perl pidigits.perl-2.perl 2000
PROGRAM FAILED
PROGRAM OUTPUT:
Can't locate Math/GMP.pm in @INC (you may need to install the Math::GMP module) (@INC entries checked: /opt/src/perl-5.40.0/lib/site_perl/5.40.0/x86_64-linux-thread-multi /opt/src/perl-5.40.0/lib/site_perl/5.40.0 /opt/src/perl-5.40.0/lib/5.40.0/x86_64-linux-thread-multi /opt/src/perl-5.40.0/lib/5.40.0) at pidigits.perl-2.perl line 10.
BEGIN failed--compilation aborted at pidigits.perl-2.perl line 10.