The Computer Language
24.04 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 38
subversion 2 (v5.38.2)
x86_64-linux-thread-multi


 Sat, 09 Mar 2024 20:39:34 GMT

COMMAND LINE:
 /opt/src/perl-5.38.2/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.38.2/lib/site_perl/5.38.2/x86_64-linux-thread-multi /opt/src/perl-5.38.2/lib/site_perl/5.38.2 /opt/src/perl-5.38.2/lib/5.38.2/x86_64-linux-thread-multi /opt/src/perl-5.38.2/lib/5.38.2) at pidigits.perl-4.perl line 10.
BEGIN failed--compilation aborted at pidigits.perl-4.perl line 10.