How to resolve the algorithm Prime conspiracy step by step in the J programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Prime conspiracy step by step in the J programming language
Table of Contents
Problem Statement
A recent discovery, quoted from Quantamagazine (March 13, 2016): and
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.
Considering the first one million primes. Count, for any pair of successive primes, the number of transitions i -> j and print them along with their relative frequency, sorted by i . You can see that, for a given i , frequencies are not evenly distributed.
(Modulo 10), primes whose last digit is 9 "prefer" the digit 1 to the digit 9, as its following prime.
Do the same for one hundred million primes.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Prime conspiracy step by step in the J programming language
Source code in the j programming language
/:~ (~.,. ' ',. ":@(%/&1 999999)@(#/.~)) 2 (,'->',])&":/\ 10|p:i.1e6
1->1 42853 0.042853
1->3 77475 0.0774751
1->7 79453 0.0794531
1->9 50153 0.0501531
2->3 1 1e_6
3->1 58255 0.0582551
3->3 39668 0.039668
3->5 1 1e_6
3->7 72827 0.0728271
3->9 79358 0.0793581
5->7 1 1e_6
7->1 64230 0.0642301
7->3 68595 0.0685951
7->7 39603 0.039603
7->9 77586 0.0775861
9->1 84596 0.0845961
9->3 64371 0.0643711
9->7 58130 0.0581301
9->9 42843 0.042843
/:~ (~.,. ' ',. '%',.~ ":@(%/&1 9999.99)@(#/.~)) 2 (,'->',])&":/\ 10|p:i.1e6
1->1 42853 4.2853%
1->3 77475 7.74751%
1->7 79453 7.94531%
1->9 50153 5.01531%
2->3 1 0.0001%
3->1 58255 5.82551%
3->3 39668 3.9668%
3->5 1 0.0001%
3->7 72827 7.28271%
3->9 79358 7.93581%
5->7 1 0.0001%
7->1 64230 6.42301%
7->3 68595 6.85951%
7->7 39603 3.9603%
7->9 77586 7.75861%
9->1 84596 8.45961%
9->3 64371 6.43711%
9->7 58130 5.81301%
9->9 42843 4.2843%
dgpairs=: 2 (,'->',])&":/\ 10 | p:
combine=: ~.@[ ,. ' ',. ":@(%/&1 99999999)@(+//.)
/:~ combine&;/|: (~.;#/.~)@dgpairs@((+ i.)/)"1 (1e6*i.100),.1e6+99>i.100
1->1 4.62304e6 0.0462304
1->3 7.42944e6 0.0742944
1->7 7.50461e6 0.0750461
1->9 5.44234e6 0.0544234
2->3 1 1e_8
3->1 6.01098e6 0.0601098
3->3 4.44256e6 0.0444256
3->5 1 1e_8
3->7 7.0437e6 0.070437
3->9 7.5029e6 0.075029
5->7 1 1e_8
7->1 6.37398e6 0.0637398
7->3 6.7552e6 0.067552
7->7 4.43936e6 0.0443936
7->9 7.43187e6 0.0743187
9->1 7.99143e6 0.0799143
9->3 6.37294e6 0.0637294
9->7 6.01274e6 0.0601274
9->9 4.62292e6 0.0462292
You may also check:How to resolve the algorithm Loop over multiple arrays simultaneously step by step in the Objeck programming language
You may also check:How to resolve the algorithm Sort an integer array step by step in the Fōrmulæ programming language
You may also check:How to resolve the algorithm Topological sort step by step in the Elixir programming language
You may also check:How to resolve the algorithm Linear congruential generator step by step in the Elixir programming language
You may also check:How to resolve the algorithm Arithmetic/Complex step by step in the BASIC programming language