The Computer Language
23.02 Benchmarks Game

pidigits Python 3 #2 program

source code

# The Computer Language Benchmarks Game
# https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
#
# contributed by Rene Bakker
# fixed by Isaac Gouy

import sys
from io import StringIO
from gmpy2 import xmpz,div,mul,add

N = int(sys.argv[1])
f = StringIO()

w = xmpz(0)
k = 1

n1  = xmpz(4)
n2  = xmpz(3)
d   = xmpz(1)
f10 = xmpz(10)
n10 = xmpz(-10)

i = 0
while True:
    # digit
    u = int(div(n1,d))
    v = int(div(n2,d))
    if u == v:
        f.write(chr(48+u))
        i += 1
        if i % 10 == 0:
            f.write("\t:%d\n" % i)

        if i == N:
            break

        # extract
        u  = mul(d, mul(n10, u))
        n1 = mul(n1, f10)
        n1 = add(n1, u)
        n2 = mul(n2, f10)
        n2 = add(n2, u)
    else:
        # produce
        k2 = k << 1
        u  = mul(n1, k2 - 1)
        v  = add(n2, n2)
        w  = mul(n1, k - 1)
        n1 = add(u, v)
        u  = mul(n2, k + 2)
        n2 = add(w, u)
        d  = mul(d, k2 + 1)
        k += 1;

if i % 10 != 0:
    f.write("%s\t:%d\n" % (' ' * (10 - (i%10)),N))
print(f.getvalue(),end="")
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
Python 3.11.1


Sun, 29 Jan 2023 01:18:14 GMT

MAKE:
mv pidigits.python3-2.python3 pidigits.python3-2.py
pyright .
No configuration file found.
No pyproject.toml file found.
stubPath /home/dunham/all-benchmarksgame/benchmarksgame_i53330/pidigits/tmp/typings is not a valid directory.
Assuming Python platform Linux
Searching for source files
Found 1 source file
pyright 1.1.288
/home/dunham/all-benchmarksgame/benchmarksgame_i53330/pidigits/tmp/pidigits.python3-2.py
  /home/dunham/all-benchmarksgame/benchmarksgame_i53330/pidigits/tmp/pidigits.python3-2.py:9:6 - error: Import "gmpy2" could not be resolved (reportMissingImports)
1 error, 0 warnings, 0 informations 
Completed in 1.53sec
make: [/home/dunham/all-benchmarksgame/2000-benchmarksgame/nanobench/makefiles/u64q.programs.Makefile:388: pidigits.python3-2.python3_run] Error 1 (ignored)

3.01s to complete and log all make actions

COMMAND LINE:
/opt/src/Python-3.11.1/bin/python3 -OO pidigits.python3-2.py 2000

UNEXPECTED OUTPUT 

1,200c1,200
< 3142,/3-+4	:10
< ,/0./324.5	:20
< ,3,434.33.	:30
< 0+03/.420-	:40
< 2-/40/4.+1	:50
< 1,.210-5/4	:60
< 5,/231..2,	:70
< 41,3/,21/0	:80
< 0/,3.035.3	:90
< +34212-1-.	:100
< 0.215.1/-+	:110
< 133.231-,5	:120
< -1/4.45,10	:130
< ,+1,.2232-	:140
< 3+4,/41.13	:150
< .5.112-5+0	:160
< 3.4103-02/	:170
< 4/+2111,,,	:180
< 0,45,23/5/	:190
< 0+5/304.20	:200
< ,443/.110.	:210
< ,--,/3345,	:220
< 13.5.,,5.2	:230
< 34./-..32-	:240
< +3-1202/1/	:250
< 15,,5/,--/	:260
< 235,035/,1	:270
< 05+433-,5.	:280
< 2134/4,1-3	:290
< ,025/1413-	:300
< 4-25,/-01-	:310
< ,1,32,,/.2	:320
< -5/.2+21/2	:330
< 10,3.3/3+4	:340
< 1/2-2+4,44	:350
< -.//3,/04,	:360
< 0011331+31	:370
< +5/.205--+	:380
< 214.415-0+	:390
< 2/42+12,1/	:400
< 4331,-3-04	:410
< -,.,0,/20+	:420
< 31/22/,12-	:430
< 4.2/33,12.	:440
< /311+12/+5	:450
< .1-45,24.0	:460
< 0,3-50,--4	:470
< +2//,.+3-2	:480
< 5//123./4.	:490
< 2.3012/5/1	:500
< 30.34--34,	:510
< 2441-,-,43	:520
< 1/,0214/5/	:530
< 5,40+225-4	:540
< -2/1-022.0	:550
< /,1/44-03.	:560
< -1+4/22-2.	:570
< ,3/32.-.+2	:580
< 4.5--5.2.5	:590
< -.--/41+13	:600
< 2001,-.13-	:610
< 15+3,4,,1.	:620
< 3../,.-134	:630
< 3.,../0,1/	:640
< 2-4,4-2./-	:650
< 215-.441/0	:660
< 12250+3430	:670
< 15-+50,/+4	:680
< -11+1./23.	:690
< 0-//3,//24	:700
< +420200,,1	:710
< 1213/0220,	:720
< 1/,403442.	:730
< 2,0.14,30.	:740
< -5.-13100,	:750
< 1+2/-1-211	:760
< 35000000.4	:770
< -30..0500+	:780
< 11,0-32-33	:790
< .2,10,32/,	:800
< 0+0245,/5,	:810
< +35-/1.303	:820
< ,43+2231.3	:830
< +3345-/+04	:840
< +3,2/312/.	:850
< 2-10100031	:860
< 4..4/.+3//	:870
< -,/.+3321.	:880
< 4.1421,2-2	:890
< ..--/15-30	:900
< 4,0.3+35/0	:910
< 43/.,+5-/-	:920
< 312,0,,3/,	:930
< 4/.24+4./.	:940
< ,/4.+20,..	:950
< .2/,...1+3	:960
< 22-123-.1-	:970
< ,13002/3./	:980
< .-,1120,/1	:990
< /22,42020/	:1000
< /4.10+3,-2	:1010
< 011-+5/,/,	:1020
< 33.//-,/4,	:1030
< 2+34.2.3.0	:1040
< -.2303020+	:1050
< 204+302/+3	:1060
< 0-/00,.-4,	:1070
< 23,0/414//	:1080
< 1250-22..+	:1090
< 3.35./132+	:1100
< 2,,-5/,-24	:1110
< 25+42+1-0,	:1120
< 0+1.30+331	:1130
< 2-/,2-3./,	:1140
< ,///1.+10.	:1150
< 4.2.+5,4-5	:1160
< ,5/4/32/3,	:1170
< +1,0401/3.	:1180
< -02--114/0	:1190
< 10.5/.2401	:1200
< 3/,.4,2,04	:1210
< ,,4-1.-,01	:1220
< 05-102.2/4	:1230
< 30,,,0,20/	:1240
< /5-.-..4-4	:1250
< 5/45.3,+4.	:1260
< 0.-5-3-.5-	:1270
< 10405.+35,	:1280
< 5,21.05--.	:1290
< 43,/1-/5/1	:1300
< 3/3314-.-0	:1310
< 3/0//2+210	:1320
< 5.+22,21,-	:1330
< 0-,0241,.0	:1340
< 4.2+02/4+1	:1350
< 13+34.2430	:1360
< 04,,/.,402	:1370
< 5-50,5-33,	:1380
< 4/1420/3-3	:1390
< ,043-0/23.	:1400
< 0-..24+5..	:1410
< 2,4,01/342	:1420
< -22,41220/	:1430
< 25,/,32+03	:1440
< 03/,2.30-5	:1450
< ,,,-1--50.	:1460
< 4/+1+5/5,/	:1470
< /,/-/3-00,	:1480
< -/1/3-211.	:1490
< 0.+1/3030,	:1500
< +3212-+345	:1510
< 0/-203.,,0	:1520
< ,024,5.1--	:1530
< +50/120/.2	:1540
< .35.0..+4,	:1550
< -,4-0.1-43	:1560
< -+43+3./,3	:1570
< ,+2.2.42.,	:1580
< -5--3//10.	:1590
< ..-3./4.00	:1600
< 1.2,5-1,00	:1610
< 2,15+25/2/	:1620
< 22-322-215	:1630
< .-24+01414	:1640
< 420-4,-/+5	:1650
< .2,14,12,-	:1660
< 4+3,+21335	:1670
< .,-42.5/5-	:1680
< .44/+23324	:1690
< /1-4/41433	:1700
< 35+5..,242	:1710
< -/,3+2/0.4	:1720
< ,-/5/,,,21	:1730
< 0/22/2222.	:1740
< 43-3,+03+4	:1750
< 3,-//.--2.	:1760
< /05/5,02-+	:1770
< 35--.050//	:1780
< ,3-233./2.	:1790
< /,1/,..44.	:1800
< 4.3.0-.0.-	:1810
< -.15+41010	:1820
< +4/.4./,4,	:1830
< 10+1-.01,4	:1840
< 23+13+21+1	:1850
< 2-4/30.5/0	:1860
< ,1.413.5//	:1870
< ,3-/5,,042	:1880
< 420-+3/+02	:1890
< 2211-,12/,	:1900
< 31--443./,	:1910
< 2204/2/5/5	:1920
< +05-124-14	:1930
< ./-0,10,,4	:1940
< ,44-2/2-3/	:1950
< -5-..,5-,.	:1960
< ,-40,2414/	:1970
< /1/-,.33,5	:1980
< ,00,.134/0	:1990
< 5..03.,/01	:2000
---
> 3141592653	:10
> 5897932384	:20
> 6264338327	:30
> 9502884197	:40
> 1693993751	:50
> 0582097494	:60
> 4592307816	:70
> 4062862089	:80
> 9862803482	:90
> 5342117067	:100
> 9821480865	:110
> 1328230664	:120
> 7093844609	:130
> 5505822317	:140
> 2535940812	:150
> 8481117450	:160
> 2841027019	:170
> 3852110555	:180
> 9644622948	:190
> 9549303819	:200
> 6442881097	:210
> 5665933446	:220
> 1284756482	:230
> 3378678316	:240
> 5271201909	:250
> 1456485669	:260
> 2346034861	:270
> 0454326648	:280
> 2133936072	:290
> 6024914127	:300
> 3724587006	:310
> 6063155881	:320
> 7488152092	:330
> 0962829254	:340
> 0917153643	:350
> 6789259036	:360
> 0011330530	:370
> 5488204665	:380
> 2138414695	:390
> 1941511609	:400
> 4330572703	:410
> 6575959195	:420
> 3092186117	:430
> 3819326117	:440
> 9310511854	:450
> 8074462379	:460
> 9627495673	:470
> 5188575272	:480
> 4891227938	:490
> 1830119491	:500
> 2983367336	:510
> 2440656643	:520
> 0860213949	:530
> 4639522473	:540
> 7190702179	:550
> 8609437027	:560
> 7053921717	:570
> 6293176752	:580
> 3846748184	:590
> 6766940513	:600
> 2000568127	:610
> 1452635608	:620
> 2778577134	:630
> 2757789609	:640
> 1736371787	:650
> 2146844090	:660
> 1224953430	:670
> 1465495853	:680
> 7105079227	:690
> 9689258923	:700
> 5420199561	:710
> 1212902196	:720
> 0864034418	:730
> 1598136297	:740
> 7477130996	:750
> 0518707211	:760
> 3499999983	:770
> 7297804995	:780
> 1059731732	:790
> 8160963185	:800
> 9502445945	:810
> 5346908302	:820
> 6425223082	:830
> 5334468503	:840
> 5261931188	:850
> 1710100031	:860
> 3783875288	:870
> 6587533208	:880
> 3814206171	:890
> 7766914730	:900
> 3598253490	:910
> 4287554687	:920
> 3115956286	:930
> 3882353787	:940
> 5937519577	:950
> 8185778053	:960
> 2171226806	:970
> 6130019278	:980
> 7661119590	:990
> 9216420198	:1000
> 9380952572	:1010
> 0106548586	:1020
> 3278865936	:1030
> 1533818279	:1040
> 6823030195	:1050
> 2035301852	:1060
> 9689957736	:1070
> 2259941389	:1080
> 1249721775	:1090
> 2834791315	:1100
> 1557485724	:1110
> 2454150695	:1120
> 9508295331	:1130
> 1686172785	:1140
> 5889075098	:1150
> 3817546374	:1160
> 6493931925	:1170
> 5060400927	:1180
> 7016711390	:1190
> 0984882401	:1200
> 2858361603	:1210
> 5637076601	:1220
> 0471018194	:1230
> 2955596198	:1240
> 9467678374	:1250
> 4944825537	:1260
> 9774726847	:1270
> 1040475346	:1280
> 4620804668	:1290
> 4259069491	:1300
> 2933136770	:1310
> 2898915210	:1320
> 4752162056	:1330
> 9660240580	:1340
> 3815019351	:1350
> 1253382430	:1360
> 0355876402	:1370
> 4749647326	:1380
> 3914199272	:1390
> 6042699227	:1400
> 9678235478	:1410
> 1636009341	:1420
> 7216412199	:1430
> 2458631503	:1440
> 0286182974	:1450
> 5557067498	:1460
> 3850549458	:1470
> 8586926995	:1480
> 6909272107	:1490
> 9750930295	:1500
> 5321165344	:1510
> 9872027559	:1520
> 6023648066	:1530
> 5499119881	:1540
> 8347977535	:1550
> 6636980742	:1560
> 6542527862	:1570
> 5518184175	:1580
> 7467289097	:1590
> 7772793800	:1600
> 0816470600	:1610
> 1614524919	:1620
> 2173217214	:1630
> 7723501414	:1640
> 4197356854	:1650
> 8161361157	:1660
> 3525521334	:1670
> 7574184946	:1680
> 8438523323	:1690
> 9073941433	:1700
> 3454776241	:1710
> 6862518983	:1720
> 5694855620	:1730
> 9921922218	:1740
> 4272550254	:1750
> 2568876717	:1760
> 9049460165	:1770
> 3466804988	:1780
> 6272327917	:1790
> 8608578438	:1800
> 3827967976	:1810
> 6814541009	:1820
> 5388378636	:1830
> 0950680064	:1840
> 2251252051	:1850
> 1739298489	:1860
> 6084128488	:1870
> 6269456042	:1880
> 4196528502	:1890
> 2210661186	:1900
> 3067442786	:1910
> 2203919494	:1920
> 5047123713	:1930
> 7869609563	:1940
> 6437191728	:1950
> 7467764657	:1960
> 5739624138	:1970
> 9086583264	:1980
> 5995813390	:1990
> 4780275900	:2000

PROGRAM OUTPUT:
3142,/3-+4	:10
,/0./324.5	:20
,3,434.33.	:30
0+03/.420-	:40
2-/40/4.+1	:50
1,.210-5/4	:60
5,/231..2,	:70
41,3/,21/0	:80
0/,3.035.3	:90
+34212-1-.	:100
0.215.1/-+	:110
133.231-,5	:120
-1/4.45,10	:130
,+1,.2232-	:140
3+4,/41.13	:150
.5.112-5+0	:160
3.4103-02/	:170
4/+2111,,,	:180
0,45,23/5/	:190
0+5/304.20	:200
,443/.110.	:210
,--,/3345,	:220
13.5.,,5.2	:230
34./-..32-	:240
+3-1202/1/	:250
15,,5/,--/	:260
235,035/,1	:270
05+433-,5.	:280
2134/4,1-3	:290
,025/1413-	:300
4-25,/-01-	:310
,1,32,,/.2	:320
-5/.2+21/2	:330
10,3.3/3+4	:340
1/2-2+4,44	:350
-.//3,/04,	:360
0011331+31	:370
+5/.205--+	:380
214.415-0+	:390
2/42+12,1/	:400
4331,-3-04	:410
-,.,0,/20+	:420
31/22/,12-	:430
4.2/33,12.	:440
/311+12/+5	:450
.1-45,24.0	:460
0,3-50,--4	:470
+2//,.+3-2	:480
5//123./4.	:490
2.3012/5/1	:500
30.34--34,	:510
2441-,-,43	:520
1/,0214/5/	:530
5,40+225-4	:540
-2/1-022.0	:550
/,1/44-03.	:560
-1+4/22-2.	:570
,3/32.-.+2	:580
4.5--5.2.5	:590
-.--/41+13	:600
2001,-.13-	:610
15+3,4,,1.	:620
3../,.-134	:630
3.,../0,1/	:640
2-4,4-2./-	:650
215-.441/0	:660
12250+3430	:670
15-+50,/+4	:680
-11+1./23.	:690
0-//3,//24	:700
+420200,,1	:710
1213/0220,	:720
1/,403442.	:730
2,0.14,30.	:740
-5.-13100,	:750
1+2/-1-211	:760
35000000.4	:770
-30..0500+	:780
11,0-32-33	:790
.2,10,32/,	:800
0+0245,/5,	:810
+35-/1.303	:820
,43+2231.3	:830
+3345-/+04	:840
+3,2/312/.	:850
2-10100031	:860
4..4/.+3//	:870
-,/.+3321.	:880
4.1421,2-2	:890
..--/15-30	:900
4,0.3+35/0	:910
43/.,+5-/-	:920
312,0,,3/,	:930
4/.24+4./.	:940
,/4.+20,..	:950
.2/,...1+3	:960
22-123-.1-	:970
,13002/3./	:980
.-,1120,/1	:990
/22,42020/	:1000
/4.10+3,-2	:1010
011-+5/,/,	:1020
33.//-,/4,	:1030
2+34.2.3.0	:1040
-.2303020+	:1050
204+302/+3	:1060
0-/00,.-4,	:1070
23,0/414//	:1080
1250-22..+	:1090
3.35./132+	:1100
2,,-5/,-24	:1110
25+42+1-0,	:1120
0+1.30+331	:1130
2-/,2-3./,	:1140
,///1.+10.	:1150
4.2.+5,4-5	:1160
,5/4/32/3,	:1170
+1,0401/3.	:1180
-02--114/0	:1190
10.5/.2401	:1200
3/,.4,2,04	:1210
,,4-1.-,01	:1220
05-102.2/4	:1230
30,,,0,20/	:1240
/5-.-..4-4	:1250
5/45.3,+4.	:1260
0.-5-3-.5-	:1270
10405.+35,	:1280
5,21.05--.	:1290
43,/1-/5/1	:1300
3/3314-.-0	:1310
3/0//2+210	:1320
5.+22,21,-	:1330
0-,0241,.0	:1340
4.2+02/4+1	:1350
13+34.2430	:1360
04,,/.,402	:1370
5-50,5-33,	:1380
4/1420/3-3	:1390
,043-0/23.	:1400
0-..24+5..	:1410
2,4,01/342	:1420
-22,41220/	:1430
25,/,32+03	:1440
03/,2.30-5	:1450
,,,-1--50.	:1460
4/+1+5/5,/	:1470
/,/-/3-00,	:1480
-/1/3-211.	:1490
0.+1/3030,	:1500
+3212-+345	:1510
0/-203.,,0	:1520
,024,5.1--	:1530
+50/120/.2	:1540
.35.0..+4,	:1550
-,4-0.1-43	:1560
-+43+3./,3	:1570
,+2.2.42.,	:1580
-5--3//10.	:1590
..-3./4.00	:1600
1.2,5-1,00	:1610
2,15+25/2/	:1620
22-322-215	:1630
.-24+01414	:1640
420-4,-/+5	:1650
.2,14,12,-	:1660
4+3,+21335	:1670
.,-42.5/5-	:1680
.44/+23324	:1690
/1-4/41433	:1700
35+5..,242	:1710
-/,3+2/0.4	:1720
,-/5/,,,21	:1730
0/22/2222.	:1740
43-3,+03+4	:1750
3,-//.--2.	:1760
/05/5,02-+	:1770
35--.050//	:1780
,3-233./2.	:1790
/,1/,..44.	:1800
4.3.0-.0.-	:1810
-.15+41010	:1820
+4/.4./,4,	:1830
10+1-.01,4	:1840
23+13+21+1	:1850
2-4/30.5/0	:1860
,1.413.5//	:1870
,3-/5,,042	:1880
420-+3/+02	:1890
2211-,12/,	:1900
31--443./,	:1910
2204/2/5/5	:1920
+05-124-14	:1930
./-0,10,,4	:1940
,44-2/2-3/	:1950
-5-..,5-,.	:1960
,-40,2414/	:1970
/1/-,.33,5	:1980
,00,.134/0	:1990
5..03.,/01	:2000