pidigits Python 3 #5 program
source code
# The Computer Language Benchmarks Game
# https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
#
# Translated from Mr Ledrug's C program by Jeremy Zerfas.
# Transliterated from GMP to gmpy2 by Isaac Gouy
from sys import argv
from gmpy2 import xmpz
def extract_Digit(nth):
global tmp1, tmp2, acc, den, num
tmp1 = num * nth
tmp2 = tmp1 + acc
tmp1 = tmp2 // den
return tmp1
def eliminate_Digit(d):
global acc, den, num
acc = acc - den * d
acc = acc * 10
num = num * 10
def next_Term(k):
global acc, den, num
k2=k*2+1
acc = acc + num * 2
acc = acc * k2
den = den * k2
num = num * k
def main():
global tmp1, tmp2, acc, den, num
n=int(argv[1])
tmp1 = xmpz(0)
tmp2 = xmpz(0)
acc = xmpz(0)
den = xmpz(1)
num = xmpz(1)
i=0
k=0
while i<n:
k+=1
next_Term(k)
if num > acc:
continue
d=extract_Digit(3)
if d!=extract_Digit(4):
continue
print(chr(48+d), end="")
i+=1
if i%10==0:
print("\t:%d" % (i))
eliminate_Digit(d)
main()
notes, command-line, and program output
NOTES:
64-bit Ubuntu quad core
Python 3.13.0
Sat, 12 Oct 2024 04:51:52 GMT
MAKE:
mv pidigits.python3-5.python3 pidigits.py
pyright .
/home/dunham/all-benchmarksgame/benchmarksgame_i53330/pidigits/tmp/pidigits.py
/home/dunham/all-benchmarksgame/benchmarksgame_i53330/pidigits/tmp/pidigits.py:9:6 - error: Import "gmpy2" could not be resolved (reportMissingImports)
1 error, 0 warnings, 0 informations
make: [/home/dunham/all-benchmarksgame/2000-benchmarksgame/nanobench/makefiles/u64q.programs.Makefile:421: pidigits.python3-5.python3_run] Error 1 (ignored)
4.80s to complete and log all make actions
COMMAND LINE:
/opt/src/Python-3.13.0/bin/python3 -OO pidigits.py 2000
PROGRAM FAILED
PROGRAM OUTPUT:
Traceback (most recent call last):
File "/home/dunham/all-benchmarksgame/benchmarksgame_i53330/pidigits/tmp/pidigits.py", line 9, in <module>
from gmpy2 import xmpz
ModuleNotFoundError: No module named 'gmpy2'