The Computer Language
24.11 Benchmarks Game

pidigits Perl #4 program

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
#   modified by Kjetil Skotheim, cleanup + speedup 10%

use Math::GMP;
my $n = $ARGV[0];
my($z0, $z1, $z2) = map Math::GMP->new($_), 1,0,1;
my($k, $s, $d, $f);
for (1..$n) {
    while ( $z0>$z2 or ( $d = ($f=$z0*3+$z1)/$z2 ) != ($f+$z0)/$z2 ) {
        $z2 *= $f = 2*++$k+1;
        $z1  = $f * ($z1+2*$z0);
        $z0 *= $k;
    }
    $z1  = 10 * ($z1-$d*$z2);
    $z0 *= 10;
    $s  .= $d;
    printf "%-10s\t:$_\n", $s and $s="" if $_%10<1 or $_==$n;
}
    

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:26 GMT

COMMAND LINE:
 /opt/src/perl-5.40.0/bin/perl pidigits.perl-4.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-4.perl line 10.
BEGIN failed--compilation aborted at pidigits.perl-4.perl line 10.