Prime conspiracy

From Rosetta Code
Revision as of 19:43, 19 March 2016 by rosettacode>G.Brougnard (Created page with "{{draft task}} '''Prime Conspiracy''' A recent discovery, quoted from [https://www.quantamagazine.org/20160313-mathematicians-discover-prime-conspiracy/ Quantamagazine] , Mar...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Prime conspiracy is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Prime Conspiracy

A recent discovery, quoted from Quantamagazine , Marsh 23,2016 : "A previously unnoticed property of prime numbers seems to violate a longstanding assumption about how they behave. Prime numbers, it seems, have decided preferences about the final digits of the primes that immediately follow them."

The task is to check this assertion, modulo 10. Lets call i -> j a transition if i is the last decimal digit of a prime, and j the last decimal digit of the following prime.

Task

Considering the first 1_000_000 primes, count the number of transitions i -> j , print them along with their relative frequency. i and j are in (1,3,7,9) . Check that frequencies are not evenly distributed.

Extra credit : The same for 100_000_000 primes.

Example

10000 first primes. Transitions prime % 10 → next-prime % 10.
1 → 1 count:        365 frequency: 3.65 %
1 → 3 count:        833 frequency: 8.33 %
1 → 7 count:        889 frequency: 8.89 %
1 → 9 count:        397 frequency: 3.97 %
3 → 1 count:        529 frequency: 5.29 %
3 → 3 count:        324 frequency: 3.24 %
3 → 7 count:        754 frequency: 7.54 %
3 → 9 count:        907 frequency: 9.07 %
7 → 1 count:        655 frequency: 6.55 %
7 → 3 count:        722 frequency: 7.22 %
7 → 7 count:        323 frequency: 3.23 %
7 → 9 count:        808 frequency: 8.08 %
9 → 1 count:        935 frequency: 9.35 %
9 → 3 count:        636 frequency: 6.36 %
9 → 7 count:        541 frequency: 5.41 %
9 → 9 count:        379 frequency: 3.79 %