Prime conspiracy: Difference between revisions

→‎{{header|PARI/GP}}: format the pari/gp code
m (→‎{{header|Wren}}: Minor tidy.)
(→‎{{header|PARI/GP}}: format the pari/gp code)
Line 2,076:
 
<syntaxhighlight lang="parigp">
conspiracy(maxx) = {
print("primes considered= ", maxx);
x = matrix(9, 9);cnt=0;p=2;q=2%10;
while( cnt< =maxx, 0;
p = 2;
cnt+=1;
q = p2 % 10;
m=q;
 
p=nextprime(p+1);
while (cnt <= maxx,
q= p%10;
cnt += 1;
x[m,q]+=1);
m = q;
print (2," to ",3, " count: ",x[2,3]," freq ", 100./cnt," %" );
p = nextprime(p + 1);
forstep(i=1,9,2,
q = p % 10;
forstep(j=1,9,2,
x[m, q] += 1
if( x[i,j]<1,continue);
);
print (i," to ",j, " count: ",x[i,j]," freq ", 100.* x[i,j]/cnt," %" )));
 
print ("total transitions= ",cnt);
printf("2 to 3 count: %d freq %.6f %s\n", x[2, 3], 100. *x[2,3]/cnt, "%");
print(p);
 
forstep(i = 1, 9, 2,
forstep(j = 1, 9, 2,
if( (x[i, j] < 1, continue);
printf("%d to %d count: %d freq %.6f %s\n", i, j, x[i, j], 100. *x[i,j]/cnt, "%");
)
);
 
print print("total transitions= ", cnt);
print(p);
}
 
conspiracy(1000000);
</syntaxhighlight>
{{Out}}
<syntaxhighlight lang="parigp">
primes considered= 1000000
2 to 3 count: 1 freq 0.000100 %
1 to 1 count: 42853 freq 4.29 285296 %
1 to 3 count: 77475 freq 7.75 747492 %
1 to 5 count: 0 freq 0 .000000 %
1 to 7 count: 79453 freq 7.95 945292 %
1 to 9 count: 50153 freq 5.02 015295 %
3 to 1 count: 58255 freq 5.83 825494 %
3 to 3 count: 39668 freq 3.97 966796 %
3 to 5 count: 1 freq 0.000100 %
3 to 7 count: 72828 freq 7.28 282793 %
3 to 9 count: 79358 freq 7.94 935792 %
5 to 1 count: 0 freq 0 .000000 %
5 to 3 count: 0 freq 0 .000000 %
5 to 5 count: 0 freq 0 .000000 %
5 to 7 count: 1 freq 0.000100 %
5 to 9 count: 0 freq 0 .000000 %
7 to 1 count: 64230 freq 6.42 422994 %
7 to 3 count: 68595 freq 6.86 859493 %
7 to 5 count: 0 freq 0 .000000 %
7 to 7 count: 39604 freq 3.96 960396 %
7 to 9 count: 77586 freq 7.76 758592 %
9 to 1 count: 84596 freq 8.46 459592 %
9 to 3 count: 64371 freq 6.44 437094 %
9 to 5 count: 0 freq 0 .000000 %
9 to 7 count: 58130 freq 5.81 812994 %
9 to 9 count: 42843 freq 4.28 284296 %
total transitions= 1000001
15485917
 
time = 5,016 ms.
</syntaxhighlight>
 
338

edits