RE: Strange behaviour of prime numbers
(05-26-2019 05:08 PM)Albert Chan Wrote: Hi, pier4r
Tried it with Mathematica. Distribution looks similar within sub-ranges.
Code:
keys = {1, 3, 7, 9};
joinlastdigit[x_, y_] := Mod[x, 10]*10 + Mod[y, 10];
keys = Flatten[Table[joinlastdigit[keys[[i]], keys[[j]]], {i, 4}, {j, 4}]];
lastdigitdist[range_] := Block[{n, p, t}, (* distribution percentages *)
n = Length[range];
p = Map[Prime, range];
t = Map[joinlastdigit[p[[#]], p[[#+1]]]&, Range[n-1]];
0.1 * Round[1000 * Map[Count[t, #]&, keys]/n]];
keys → {11, 13, 17, 19, 31, 33, 37, 39, 71, 73, 77, 79, 91, 93, 97, 99}
lastdigitdist[Range[1, 1000000]] → {4.3, 7.7, 7.9, 5.0, 5.8, 4.0, 7.3, 7.9, 6.4, 6.9, 4.0, 7.8, 8.5, 6.4, 5.8, 4.3}
I'm probably wrong somewhere (or dont understand how you calculate the %) but I dont find the same result with this program in newRPL. For the first million I get :
{ 4.09. 8.02. 8.34. 4.53. 5.59. 3.58. 7.41. 8.47. 6.46. 6.93. 3.66. 7.94. 8.85. 6.51. 5.58. 4.02. }
Code:
«
2 0 9 IDN 0 * → prev new stat
«
2
WHILE NEXTPRIME DUP 1E6 < REPEAT
DUP 0 0 DIGITS 'new' STO
'stat' prev new 2 →LIST DUP2 GET 1 + PUT
new 'prev' STO
END
stat DUP AXL ΣLIST ΣLIST / 100 *
»
»
(the results are in an array 9x9)
I takes only 0.96s with the simulator for the first million, 85sec on a HP50g hdw.
10 millions takes only 15sec
Code:
[
[ 4.26. 0. 7.77. 0. 0. 0. 8.02. 0. 4.94. ]
[ 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
[ 5.79. 0. 3.9. 0. 0. 0. 7.32. 0. 8. ]
[ 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
[ 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
[ 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
[ 6.42. 0. 6.89. 0. 0. 0. 3.9. 0. 7.8. ]
[ 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
[ 8.52. 0. 6.45. 0. 0. 0. 5.76. 0. 4.24. ]
]
|