Prime conspiracy: Difference between revisions

→‎{{header|REXX}}: rewritten to be readable
m (Minor edit)
(→‎{{header|REXX}}: rewritten to be readable)
 
(28 intermediate revisions by 15 users not shown)
Line 58:
</pre>
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">V limit = 1000000
V k = limit
V n = k * 17
V primes = [1B] * n
primes[0] = primes[1] = 0B
 
L(i) 2..Int(sqrt(n))
I !primes[i]
L.continue
L(j) (i * i .< n).step(i)
primes[j] = 0B
 
DefaultDict[(Int, Int), Int] trans_map
V prev = -1
 
L(i) 0 .< n
I primes[i]
I prev != -1
trans_map[(prev, i % 10)]++
prev = i % 10
 
I --k == 0
L.break
 
print(‘First #. primes. Transitions prime % 10 > next-prime % 10.’.format(limit))
L(trans) sorted(trans_map.keys())
print(‘#. -> #. count #5 frequency: #.4%’.format(trans[0], trans[1], trans_map[trans], 100.0 * trans_map[trans] / limit))</syntaxhighlight>
 
{{out}}
<pre>
First 1000000 primes. Transitions prime % 10 > next-prime % 10.
1 -> 1 count 42853 frequency: 4.2853%
1 -> 3 count 77475 frequency: 7.7475%
1 -> 7 count 79453 frequency: 7.9453%
1 -> 9 count 50153 frequency: 5.0153%
2 -> 3 count 1 frequency: 0.0001%
3 -> 1 count 58255 frequency: 5.8255%
3 -> 3 count 39668 frequency: 3.9668%
3 -> 5 count 1 frequency: 0.0001%
3 -> 7 count 72827 frequency: 7.2827%
3 -> 9 count 79358 frequency: 7.9358%
5 -> 7 count 1 frequency: 0.0001%
7 -> 1 count 64230 frequency: 6.4230%
7 -> 3 count 68595 frequency: 6.8595%
7 -> 7 count 39603 frequency: 3.9603%
7 -> 9 count 77586 frequency: 7.7586%
9 -> 1 count 84596 frequency: 8.4596%
9 -> 3 count 64371 frequency: 6.4371%
9 -> 7 count 58130 frequency: 5.8130%
9 -> 9 count 42843 frequency: 4.2843%
</pre>
 
=={{header|ALGOL 68}}==
Solves the basic task (1 000 000 primes) using the standard sieve of Eratosthanes.
The sieve is represented by an array of BITS (32-bit items in Algol 68G).
<langsyntaxhighlight lang="algol68"># extend SET, CLEAR and ELEM to operate on rows of BITS #
OP SET = ( INT n, REF[]BITS b )REF[]BITS:
BEGIN
Line 140 ⟶ 195:
FI
OD
OD</langsyntaxhighlight>
{{out}}
<pre>
Line 164 ⟶ 219:
9->9 42843 4.28
</pre>
 
=={{header|AppleScript}}==
<big><code>&nbsp;i </code></big>'s "preference" for any <big><code>&nbsp;j </code></big> is a percentage of the transitions from <big><code>&nbsp;i </code></big>, not of all the transitions in the collection!
 
This takes three and a half minutes on my machine. But it's not a script you'd need to use every day.
 
<syntaxhighlight lang="applescript">on isPrime(n)
if ((n < 4) or (n is 5)) then return (n > 1)
if ((n mod 2 = 0) or (n mod 3 = 0) or (n mod 5 = 0)) then return false
repeat with i from 7 to (n ^ 0.5) div 1 by 30
if ((n mod i = 0) or (n mod (i + 4) = 0) or (n mod (i + 6) = 0) or ¬
(n mod (i + 10) = 0) or (n mod (i + 12) = 0) or (n mod (i + 16) = 0) or ¬
(n mod (i + 22) = 0) or (n mod (i + 24) = 0)) then return false
end repeat
return true
end isPrime
 
on conspiracy(limit)
script o
property counters : {{0, 0, 0, 0, 0, 0, 0, 0, 0}}
end script
repeat 8 times
copy beginning of o's counters to end of o's counters
end repeat
if (limit > 1) then
set primeCount to 1
set i to 2 -- First prime.
set n to 3 -- First number to test for primality.
repeat until (primeCount = limit)
if (isPrime(n)) then
set primeCount to primeCount + 1
set j to n mod 10
set item j of item i of o's counters to (item j of item i of o's counters) + 1
set i to j
end if
set n to n + 2
end repeat
end if
set output to {"First " & limit & " primes: transitions between end digits of consecutive primes."}
set totalTransitions to limit - 1
repeat with i in {1, 2, 3, 5, 7, 9}
set iTransitions to 0
repeat with j from 1 to 9 by 2
set iTransitions to iTransitions + (item j of item i of o's counters)
end repeat
repeat with j from 1 to 9 by 2
set ijCount to item j of item i of o's counters
if (ijCount > 0) then ¬
set end of output to ¬
(i as text) & " → " & j & ¬
(" count: " & ijCount) & ¬
(" preference for " & j & ": " & (ijCount * 10000 / iTransitions as integer) / 100) & ¬
("% overall occurrence: " & (ijCount * 10000 / totalTransitions as integer) / 100 & "%")
end repeat
end repeat
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to linefeed
set output to output as text
set AppleScript's text item delimiters to astid
return output
end conspiracy
 
conspiracy(1000000)</syntaxhighlight>
 
{{output}}
<syntaxhighlight lang="applescript">"First 1000000 primes: transitions between end digits of consecutive primes.
1 → 1 count: 42853 preference for 1: 17.15% overall occurrence: 4.29%
1 → 3 count: 77475 preference for 3: 31.0% overall occurrence: 7.75%
1 → 7 count: 79453 preference for 7: 31.79% overall occurrence: 7.95%
1 → 9 count: 50153 preference for 9: 20.07% overall occurrence: 5.02%
2 → 3 count: 1 preference for 3: 100.0% overall occurrence: 0.0%
3 → 1 count: 58255 preference for 1: 23.29% overall occurrence: 5.83%
3 → 3 count: 39668 preference for 3: 15.86% overall occurrence: 3.97%
3 → 5 count: 1 preference for 5: 0.0% overall occurrence: 0.0%
3 → 7 count: 72827 preference for 7: 29.12% overall occurrence: 7.28%
3 → 9 count: 79358 preference for 9: 31.73% overall occurrence: 7.94%
5 → 7 count: 1 preference for 7: 100.0% overall occurrence: 0.0%
7 → 1 count: 64230 preference for 1: 25.69% overall occurrence: 6.42%
7 → 3 count: 68595 preference for 3: 27.44% overall occurrence: 6.86%
7 → 7 count: 39603 preference for 7: 15.84% overall occurrence: 3.96%
7 → 9 count: 77586 preference for 9: 31.03% overall occurrence: 7.76%
9 → 1 count: 84596 preference for 1: 33.85% overall occurrence: 8.46%
9 → 3 count: 64371 preference for 3: 25.75% overall occurrence: 6.44%
9 → 7 count: 58130 preference for 7: 23.26% overall occurrence: 5.81%
9 → 9 count: 42843 preference for 9: 17.14% overall occurrence: 4.28%"</syntaxhighlight>
 
=={{header|C}}==
{{trans|C++}}
<langsyntaxhighlight lang="c">#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
Line 287 ⟶ 430:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>1000000 primes, last prime considered: 15485863
Line 312 ⟶ 455:
=={{header|C sharp|C#}}==
{{trans|Java}}
<langsyntaxhighlight lang="csharp">using System;
 
namespace PrimeConspiracy {
Line 358 ⟶ 501:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>1 -> 1 count: 42853 frequency : 4.29%
Line 381 ⟶ 524:
 
=={{header|C++}}==
<langsyntaxhighlight Cpplang="cpp">#include <vector>
#include <iostream>
#include <cmath>
Line 435 ⟶ 578:
}
return 0 ;
}</langsyntaxhighlight>
{{out}}
<pre>1 -> 1 count: 42853 frequency: 4.29 %
Line 456 ⟶ 599:
9 -> 7 count: 58130 frequency: 5.81 %
9 -> 9 count: 42843 frequency: 4.28 %
</pre>
 
===Alternative using primesieve library===
{{libheader|Primesieve}}
<syntaxhighlight lang="cpp">#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <primesieve.hpp>
 
void compute_transitions(uint64_t limit) {
primesieve::iterator it;
std::map<std::pair<uint64_t, uint64_t>, uint64_t> transitions;
for (uint64_t count = 0, prev = 0; count < limit; ++count) {
uint64_t prime = it.next_prime();
uint64_t digit = prime % 10;
if (prev != 0)
++transitions[std::make_pair(prev, digit)];
prev = digit;
}
std::cout << "First " << limit << " prime numbers:\n";
for (auto&& pair : transitions) {
double freq = (100.0 * pair.second)/limit;
std::cout << pair.first.first << " -> " << pair.first.second
<< ": count = " << std::setw(7) << pair.second
<< ", frequency = " << std::setprecision(2)
<< std::fixed << freq << " %\n";
}
}
 
int main(int argc, const char * argv[]) {
compute_transitions(1000000);
compute_transitions(100000000);
return 0;
}</syntaxhighlight>
 
{{out}}
<pre>
First 1000000 prime numbers:
1 -> 1: count = 42853, frequency = 4.29 %
1 -> 3: count = 77475, frequency = 7.75 %
1 -> 7: count = 79453, frequency = 7.95 %
1 -> 9: count = 50153, frequency = 5.02 %
2 -> 3: count = 1, frequency = 0.00 %
3 -> 1: count = 58255, frequency = 5.83 %
3 -> 3: count = 39668, frequency = 3.97 %
3 -> 5: count = 1, frequency = 0.00 %
3 -> 7: count = 72827, frequency = 7.28 %
3 -> 9: count = 79358, frequency = 7.94 %
5 -> 7: count = 1, frequency = 0.00 %
7 -> 1: count = 64230, frequency = 6.42 %
7 -> 3: count = 68595, frequency = 6.86 %
7 -> 7: count = 39603, frequency = 3.96 %
7 -> 9: count = 77586, frequency = 7.76 %
9 -> 1: count = 84596, frequency = 8.46 %
9 -> 3: count = 64371, frequency = 6.44 %
9 -> 7: count = 58130, frequency = 5.81 %
9 -> 9: count = 42843, frequency = 4.28 %
First 100000000 prime numbers:
1 -> 1: count = 4623041, frequency = 4.62 %
1 -> 3: count = 7429438, frequency = 7.43 %
1 -> 7: count = 7504612, frequency = 7.50 %
1 -> 9: count = 5442344, frequency = 5.44 %
2 -> 3: count = 1, frequency = 0.00 %
3 -> 1: count = 6010981, frequency = 6.01 %
3 -> 3: count = 4442561, frequency = 4.44 %
3 -> 5: count = 1, frequency = 0.00 %
3 -> 7: count = 7043695, frequency = 7.04 %
3 -> 9: count = 7502896, frequency = 7.50 %
5 -> 7: count = 1, frequency = 0.00 %
7 -> 1: count = 6373982, frequency = 6.37 %
7 -> 3: count = 6755195, frequency = 6.76 %
7 -> 7: count = 4439355, frequency = 4.44 %
7 -> 9: count = 7431870, frequency = 7.43 %
9 -> 1: count = 7991431, frequency = 7.99 %
9 -> 3: count = 6372940, frequency = 6.37 %
9 -> 7: count = 6012739, frequency = 6.01 %
9 -> 9: count = 4622916, frequency = 4.62 %
</pre>
 
=={{header|D}}==
{{trans|Kotlin}}
<langsyntaxhighlight Dlang="d">import std.algorithm;
import std.range;
import std.stdio;
Line 512 ⟶ 733:
writefln(" frequency: %4.2f%%", transMap[trans] / 10_000.0);
}
}</langsyntaxhighlight>
{{out}}
<pre>First 1,000,000 primes. Transitions prime % 10 -> next-prime % 10.
Line 534 ⟶ 755:
9 -> 7 count: 58130 frequency: 5.81%
9 -> 9 count: 42843 frequency: 4.28%</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
fastfunc isprim num .
# test only odd numbers
i = 3
while i <= sqrt num
if num mod i = 0
return 0
.
i += 2
.
return 1
.
func nextprim num .
repeat
num += 2
until isprim num = 1
.
return num
.
len d[][] 9
for i to 9
len d[i][] 9
.
d[2][3] = 1
p = 3
for i to 1000000
pp = p
p = nextprim p
d[pp mod 10][p mod 10] += 1
.
for i to 9
for j to 9
if d[i][j] > 0
print i & " -> " & j & ": " & d[i][j] & " = " & d[i][j] / 10000 & "%"
.
.
.
</syntaxhighlight>
 
=={{header|EchoLisp}}==
<langsyntaxhighlight lang="scheme">
(lib 'math) ;; (in-primes n) stream
(decimals 4)
Line 556 ⟶ 817:
(vector+= trans (+ (* (% p1 m) m) (% p2 m)) 1))
(print-trans trans m N))
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 579 ⟶ 840:
 
=={{header|Elixir}}==
<langsyntaxhighlight lang="elixir">defmodule Prime do
def conspiracy(m) do
IO.puts "#{m} first primes. Transitions prime % 10 → next-prime % 10."
Line 605 ⟶ 866:
end
 
Prime.conspiracy(1000000)</langsyntaxhighlight>
 
{{out}}
Line 633 ⟶ 894:
=={{header|F_Sharp|F#}}==
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_function Extensible Prime Generator (F#)]
<langsyntaxhighlight lang="fsharp">
// Prime Conspiracy. Nigel Galloway: March 27th., 2018
primes|>Seq.take 10000|>Seq.map(fun n->n%10)|>Seq.pairwise|>Seq.countBy id|>Seq.groupBy(fun((n,_),_)->n)|>Seq.sortBy(fst)
|>Seq.iter(fun(_,n)->Seq.sortBy(fun((_,n),_)->n) n|>Seq.iter(fun((n,g),z)->printfn "%d -> %d ocurred %3d times" n g z))
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 662 ⟶ 923:
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: assocs formatting grouping kernel math math.primes math.statistics
sequences sorting ;
IN: rosetta-code.prime-conspiracy
Line 681 ⟶ 942:
1,000,000 dup header transitions [ print-trans ] each ;
MAIN: main</langsyntaxhighlight>
{{out}}
<pre>
Line 707 ⟶ 968:
 
=={{header|Fortran}}==
Avoiding base ten chauvinism, here are results for bases two to thirteen. The source file relies on the [[Extensible_prime_generator]] project for its collection of primes. The bitbag file being in place, execution takes about two minutes for a hundred million primes, approaching the thirty-two bit limit. <langsyntaxhighlight Fortranlang="fortran"> PROGRAM INHERIT !Last digit persistence in successive prime numbers.
USE PRIMEBAG !Inherit this also.
INTEGER MBASE,P0,NHIC !Problem bounds.
Line 750 ⟶ 1,011:
END DO !On to the next successor digit.
END DO !On to the next base.
END !That was easy.</langsyntaxhighlight>
 
Results: just the counts - with the total number being a power of ten, percentages are deducible by eye. Though one could add row and column percentages as a further feature.
Line 971 ⟶ 1,232:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' version 13-04-2017
' updated 09-08-2018 Using bit-sieve of odd numbers
' compile with: fbc -s console
Line 1,028 ⟶ 1,289:
Sleep
End
</syntaxhighlight>
</lang>
{{out}}
Output is shown side by side
Line 1,057 ⟶ 1,318:
 
Expect a run time of ~20−60 seconds to generate and process the full 100 million primes.
<langsyntaxhighlight Golang="go">package main
 
import (
Line 1,128 ⟶ 1,389:
}
fmt.Println()
}</langsyntaxhighlight>
 
{{out}}
Line 1,197 ⟶ 1,458:
=={{header|Haskell}}==
Uses Primes library: http://hackage.haskell.org/package/primes-0.2.1.0/docs/Data-Numbers-Primes.html
<langsyntaxhighlight lang="haskell">import Data.List (group, sort)
import Text.Printf (printf)
import Data.Numbers.Primes (primes)
Line 1,209 ⟶ 1,470:
main :: IO ()
main = mapM_ line $ groups primes
where groups = tail . group . sort . (\n -> zip (0: n) n) . fmap (`mod` 10) . take 10000</langsyntaxhighlight>
{{out}}
<pre>
Line 1,237 ⟶ 1,498:
This gets the job done:
 
<langsyntaxhighlight Jlang="j"> /:~ (~.,. ' ',. ":@(%/&1 999999)@(#/.~)) 2 (,'->',])&":/\ 10|p:i.1e6
1->1 42853 0.042853
1->3 77475 0.0774751
Line 1,256 ⟶ 1,517:
9->3 64371 0.0643711
9->7 58130 0.0581301
9->9 42843 0.042843</langsyntaxhighlight>
 
Note that the [[Sieve of Eratosthenes]] task has some important implications for how often we will see the various transitions here.
Line 1,280 ⟶ 1,541:
Or, if you prefer the ratios formatted as percents, you could do this:
 
<langsyntaxhighlight Jlang="j"> /:~ (~.,. ' ',. '%',.~ ":@(%/&1 9999.99)@(#/.~)) 2 (,'->',])&":/\ 10|p:i.1e6
1->1 42853 4.2853%
1->3 77475 7.74751%
Line 1,299 ⟶ 1,560:
9->3 64371 6.43711%
9->7 58130 5.81301%
9->9 42843 4.2843%</langsyntaxhighlight>
 
'''Extra Credit:'''
Line 1,309 ⟶ 1,570:
In other words:
 
<langsyntaxhighlight Jlang="j"> dgpairs=: 2 (,'->',])&":/\ 10 | p:
combine=: ~.@[ ,. ' ',. ":@(%/&1 99999999)@(+//.)
/:~ combine&;/|: (~.;#/.~)@dgpairs@((+ i.)/)"1 (1e6*i.100),.1e6+99>i.100
Line 1,330 ⟶ 1,591:
9->3 6.37294e6 0.0637294
9->7 6.01274e6 0.0601274
9->9 4.62292e6 0.0462292</langsyntaxhighlight>
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">public class PrimeConspiracy {
 
public static void main(String[] args) {
Line 1,377 ⟶ 1,638:
return composite;
}
}</langsyntaxhighlight>
 
<pre>1 -> 1 : 4,285300
Line 1,398 ⟶ 1,659:
9 -> 7 : 5,813000
9 -> 9 : 4,284300</pre>
 
=={{header|jq}}==
<syntaxhighlight lang=jq>
# Input should be an integer
def isPrime:
. as $n
| if ($n < 2) then false
elif ($n % 2 == 0) then $n == 2
elif ($n % 3 == 0) then $n == 3
else 5
| until( . <= 0;
if .*. > $n then -1
elif ($n % . == 0) then 0
else . + 2
| if ($n % . == 0) then 0
else . + 4
end
end)
| . == -1
end;
 
# The first $n primes
def sieved($n):
[limit($n; range(2;infinite) | select(isPrime)) ];
 
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
 
# right-pad with 0
def rpad($len): tostring | ($len - length) as $l | ("0" * $l)[:$l] + .;
 
# Input: a string of digits with up to one "."
# Output: the corresponding string representation with exactly $n decimal digits
def align_decimal($n):
tostring
| (capture("(?<i>[0-9]*[.])(?<j>[0-9]{0," + ($n|tostring) + "})") as $ix
| $ix.i + ($ix.j|rpad($n)) )
// . + "." + ($n*"0") ;
 
# Report the noteworthy transitions recorded in the input object
def reportTransitions:
([.[]] | add) as $num
| keys as $keys
| "For the first \($num + 1) primes, the noteworthy transitions of the last digit from prime to next-prime are:",
($keys[] as $key
| .[$key] as $count
| select($key | IN("2 => 3", "3 => 5", "5 => 7") | not)
| ($count / $num * 100) as $freq
| "\($key) count: \($count|lpad(6)) frequency: \($freq | align_decimal(4))%" ) ;
 
def tasks:
1E6 as $n
| sieved($n) as $sieved
| (1e4, 1e6) as $num
| reduce range(1; $num) as $i ({};
($sieved[$i] % 10) as $p
| ($sieved[$i-1] % 10) as $q
| "\($q) => \($p)" as $key
| .[$key] += 1)
| reportTransitions, "";
 
tasks
</syntaxhighlight>
'''Invocation''': jq -nr -f prime-conspiracy.jq
{{output}}
<pre>
For the first 10000 primes, the noteworthy transitions of the last digit from prime to next-prime are:
1 => 1 count: 365 frequency: 3.6503%
1 => 3 count: 833 frequency: 8.3308%
1 => 7 count: 889 frequency: 8.8908%
1 => 9 count: 397 frequency: 3.9703%
3 => 1 count: 529 frequency: 5.2905%
3 => 3 count: 324 frequency: 3.2403%
3 => 7 count: 754 frequency: 7.5407%
3 => 9 count: 907 frequency: 9.0709%
7 => 1 count: 655 frequency: 6.5506%
7 => 3 count: 722 frequency: 7.2207%
7 => 7 count: 323 frequency: 3.2303%
7 => 9 count: 808 frequency: 8.0808%
9 => 1 count: 935 frequency: 9.3509%
9 => 3 count: 635 frequency: 6.3506%
9 => 7 count: 541 frequency: 5.4105%
9 => 9 count: 379 frequency: 3.7903%
 
For the first 1000000 primes, the noteworthy transitions of the last digit from prime to next-prime are:
1 => 1 count: 42853 frequency: 4.2853%
1 => 3 count: 77475 frequency: 7.7475%
1 => 7 count: 79453 frequency: 7.9453%
1 => 9 count: 50153 frequency: 5.0153%
3 => 1 count: 58255 frequency: 5.8255%
3 => 3 count: 39668 frequency: 3.9668%
3 => 7 count: 72827 frequency: 7.2827%
3 => 9 count: 79358 frequency: 7.9357%
7 => 1 count: 64230 frequency: 6.4229%
7 => 3 count: 68595 frequency: 6.8595%
7 => 7 count: 39603 frequency: 3.9603%
7 => 9 count: 77586 frequency: 7.7586%
9 => 1 count: 84596 frequency: 8.4596%
9 => 3 count: 64371 frequency: 6.4371%
9 => 7 count: 58130 frequency: 5.0813%
9 => 9 count: 42843 frequency: 4.2843%
</pre>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Printf, Primes
using DataStructures
 
Line 1,421 ⟶ 1,784:
for ((i, j), fr) in trans
@printf("%i → %i: freq. %3.4f%%\n", i, j, 100fr / tot)
end</langsyntaxhighlight>
 
{{out}}
Line 1,446 ⟶ 1,809:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.1.2
// compiled with flag -Xcoroutines=enable to suppress 'experimental' warning
 
Line 1,493 ⟶ 1,856:
println(" frequency: ${"%4.2f".format(transMap[trans]!! / 10000.0)}%")
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,521 ⟶ 1,884:
=={{header|Lua}}==
Takes about eight seconds with a limit of 10^6. It could of course be changed to 10^8 for the extra credit but the execution time is longer than my patience lasted.
<langsyntaxhighlight Lualang="lua">-- Return boolean indicating whether or not n is prime
function isPrime (n)
if n <= 1 then return false end
Line 1,571 ⟶ 1,934:
end
end
end</langsyntaxhighlight>
{{out}}
<pre>1 -> 1 count: 42853 frequency: 4.2853 %
Line 1,592 ⟶ 1,955:
9 -> 7 count: 58130 frequency: 5.813 %
9 -> 9 count: 42843 frequency: 4.2843 %</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
We do just the challenge with 10^8 primes, 10^6 primes is an easy modification by changing the 10^8 to 10^6. The first line is just the string formatting, the actual calculation is the smaller second line.
<syntaxhighlight lang="mathematica">
StringForm["`` count: `` frequency: ``", Rule@@ #[[1]], StringPadLeft[ToString@ #[[2]], 8], PercentForm[N@ #[[2]]/(10^8 -1)]]& /@
Sort[Tally[Partition[Mod[Prime[Range[10^8]], 10], 2, 1]]] // Column
</syntaxhighlight>
 
 
{{out}}
<pre>
1->1 count: 4623041 frequency: 4.623%
1->3 count: 7429438 frequency: 7.429%
1->7 count: 7504612 frequency: 7.505%
1->9 count: 5442344 frequency: 5.442%
2->3 count: 1 frequency: 0.000001%
3->1 count: 6010981 frequency: 6.011%
3->3 count: 4442561 frequency: 4.443%
3->5 count: 1 frequency: 0.000001%
3->7 count: 7043695 frequency: 7.044%
3->9 count: 7502896 frequency: 7.503%
5->7 count: 1 frequency: 0.000001%
7->1 count: 6373982 frequency: 6.374%
7->3 count: 6755195 frequency: 6.755%
7->7 count: 4439355 frequency: 4.439%
7->9 count: 7431870 frequency: 7.432%
9->1 count: 7991431 frequency: 7.991%
9->3 count: 6372940 frequency: 6.373%
9->7 count: 6012739 frequency: 6.013%
9->9 count: 4622916 frequency: 4.623%
</pre>
 
=={{header|Nim}}==
We use a sieve of Erathostenes for odd values only. This allows to find the result for 10 000, 1 000 000 and 100 000 000 primes in about 16 seconds.
 
<syntaxhighlight lang="nim"># Prime conspiracy.
 
import std/[algorithm, math, sequtils, strformat, tables]
 
const N = 1_020_000_000 # Size of sieve of Eratosthenes.
 
proc newSieve(): seq[bool] =
## Create a sieve with only odd values.
## Index "i" in sieve represents value "n = 2 * i + 3".
result.setLen(N)
for item in result.mitems: item = true
# Apply sieve.
var i = 0
const Limit = sqrt(2 * N.toFloat + 3).int
while true:
let n = 2 * i + 3
if n > Limit:
break
if result[i]:
# Found prime, so eliminate multiples.
for k in countup((n * n - 3) div 2, N - 1, n):
result[k] = false
inc i
 
var isPrime = newSieve()
 
proc countTransitions(isPrime: seq[bool]; nprimes: int) =
## Build the transition count table and print it.
 
var counts = [(2, 3)].toCountTable() # Count of transitions.
var d1 = 3 # Last digit of first prime in transition.
var count = 2 # Count of primes (starting with 2 and 3).
for i in 1..isPrime.high:
if isPrime[i]:
inc count
let d2 = (2 * i + 3) mod 10 # Last digit of second prime in transition.
counts.inc((d1, d2))
if count == nprimes: break
d1 = d2
 
# Check if sieve was big enough.
if count < nprimes:
echo &"Found only {count} primes; expected {nprimes} primes. Increase value of N."
quit(QuitFailure)
 
# Print result.
echo &"{nprimes} first primes. Transitions prime (mod 10) → next-prime (mod 10)."
for key in sorted(counts.keys.toSeq):
let count = counts[key]
let freq = count.toFloat * 100 / nprimes.toFloat
echo &"{key[0]} → {key[1]} Count: {count:7d} Frequency: {freq:4.2f}%"
echo ""
 
isPrime.countTransitions(10_000)
isPrime.countTransitions(1_000_000)
isPrime.countTransitions(100_000_000)
</syntaxhighlight>
{{out}}
<pre>
10000 first primes. Transitions prime (mod 10) → next-prime (mod 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%
2 → 3 Count: 1 Frequency: 0.01%
3 → 1 Count: 529 Frequency: 5.29%
3 → 3 Count: 324 Frequency: 3.24%
3 → 5 Count: 1 Frequency: 0.01%
3 → 7 Count: 754 Frequency: 7.54%
3 → 9 Count: 907 Frequency: 9.07%
5 → 7 Count: 1 Frequency: 0.01%
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: 635 Frequency: 6.35%
9 → 7 Count: 541 Frequency: 5.41%
9 → 9 Count: 379 Frequency: 3.79%
 
1000000 first primes. Transitions prime (mod 10) → next-prime (mod 10).
1 → 1 Count: 42853 Frequency: 4.29%
1 → 3 Count: 77475 Frequency: 7.75%
1 → 7 Count: 79453 Frequency: 7.95%
1 → 9 Count: 50153 Frequency: 5.02%
2 → 3 Count: 1 Frequency: 0.00%
3 → 1 Count: 58255 Frequency: 5.83%
3 → 3 Count: 39668 Frequency: 3.97%
3 → 5 Count: 1 Frequency: 0.00%
3 → 7 Count: 72827 Frequency: 7.28%
3 → 9 Count: 79358 Frequency: 7.94%
5 → 7 Count: 1 Frequency: 0.00%
7 → 1 Count: 64230 Frequency: 6.42%
7 → 3 Count: 68595 Frequency: 6.86%
7 → 7 Count: 39603 Frequency: 3.96%
7 → 9 Count: 77586 Frequency: 7.76%
9 → 1 Count: 84596 Frequency: 8.46%
9 → 3 Count: 64371 Frequency: 6.44%
9 → 7 Count: 58130 Frequency: 5.81%
9 → 9 Count: 42843 Frequency: 4.28%
 
100000000 first primes. Transitions prime (mod 10) → next-prime (mod 10).
1 → 1 Count: 4623041 Frequency: 4.62%
1 → 3 Count: 7429438 Frequency: 7.43%
1 → 7 Count: 7504612 Frequency: 7.50%
1 → 9 Count: 5442344 Frequency: 5.44%
2 → 3 Count: 1 Frequency: 0.00%
3 → 1 Count: 6010981 Frequency: 6.01%
3 → 3 Count: 4442561 Frequency: 4.44%
3 → 5 Count: 1 Frequency: 0.00%
3 → 7 Count: 7043695 Frequency: 7.04%
3 → 9 Count: 7502896 Frequency: 7.50%
5 → 7 Count: 1 Frequency: 0.00%
7 → 1 Count: 6373982 Frequency: 6.37%
7 → 3 Count: 6755195 Frequency: 6.76%
7 → 7 Count: 4439355 Frequency: 4.44%
7 → 9 Count: 7431870 Frequency: 7.43%
9 → 1 Count: 7991431 Frequency: 7.99%
9 → 3 Count: 6372940 Frequency: 6.37%
9 → 7 Count: 6012739 Frequency: 6.01%
9 → 9 Count: 4622916 Frequency: 4.62%
</pre>
 
=={{header|PARI/GP}}==
 
<langsyntaxhighlight 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 = 2 % 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("total transitions= ", cnt);
print(p);
}
 
</lang>
conspiracy(1000000);
</syntaxhighlight>
{{Out}}
<langsyntaxhighlight 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>
</lang>
 
=={{header|Pascal}}==
Line 1,655 ⟶ 2,187:
 
'''Extra credit:''' is included PrimeLimit = 2038074743-> 100'000'000 Primes
<langsyntaxhighlight lang="pascal">
program primCons;
{$IFNDEF FPC}
Line 1,783 ⟶ 2,315:
OutputTransitions(CntTransitions);
end.
</syntaxhighlight>
</lang>
{{Out}}
<pre>PrimCnt 10000 100000 1000000 10000000 100000000
Line 1,817 ⟶ 2,349:
{{libheader|ntheory}}
 
<langsyntaxhighlight lang="perl">use ntheory qw/forprimes nth_prime/;
 
my $upto = 1_000_000;
Line 1,831 ⟶ 2,363:
printf "%s → %s count:\t%7d\tfrequency: %4.2f %%\n",
substr($_,0,1), substr($_,1,1), $freq{$_}, 100*$freq{$_}/$upto
for sort keys %freq;</langsyntaxhighlight>
{{out}}
<pre>1000000 first primes. Transitions prime % 10 → next-prime % 10.
Line 1,877 ⟶ 2,409:
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
Using primes() from [[Almost_prime#Phix]]
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<lang Phix>sequence p10k = primes(10000)
<span style="color: #004080;">sequence</span> <span style="color: #000000;">p10k</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">get_primes</span><span style="color: #0000FF;">(-</span><span style="color: #000000;">10_000</span><span style="color: #0000FF;">),</span>
sequence transitions = repeat(repeat(0,9),9)
<span style="color: #000000;">transitions</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">),</span><span style="color: #000000;">9</span><span style="color: #0000FF;">)</span>
integer last = p10k[1], this
<span style="color: #004080;">integer</span> <span style="color: #000000;">l</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">p10k</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">last</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">p10k</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">],</span> <span style="color: #000000;">curr</span>
for i=2 to length(p10k) do
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">2</span> <span style="color: #008080;">to</span> <span style="color: #000000;">l</span> <span style="color: #008080;">do</span>
this = remainder(p10k[i],10)
<span style="color: #000000;">curr</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">p10k</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">],</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)</span>
transitions[last][this] += 1
<span style="color: #000000;">transitions</span><span style="color: #0000FF;">[</span><span style="color: #000000;">last</span><span style="color: #0000FF;">][</span><span style="color: #000000;">curr</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
last = this
<span style="color: #000000;">last</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">curr</span>
end for
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
for i=1 to 9 do
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">9</span> <span style="color: #008080;">do</span>
for j=1 to 9 do
<span style="color: #008080;">for</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">9</span> <span style="color: #008080;">do</span>
if transitions[i][j]!=0 then
<span style="color: #004080;">atom</span> <span style="color: #000000;">tij</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">transitions</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">][</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]</span>
printf(1,"%d->%d:%3.2f%%\n",{i,j,transitions[i][j]*100/length(p10k)})
<span style="color: #008080;">if</span> <span style="color: #000000;">tij</span><span style="color: #0000FF;">!=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span>
end if
<span style="color: #004080;">atom</span> <span style="color: #000000;">pc</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">tij</span><span style="color: #0000FF;">*</span><span style="color: #000000;">100</span><span style="color: #0000FF;">/</span><span style="color: #000000;">l</span>
end for
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d-&gt;%d:%3.2f%%\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">j</span><span style="color: #0000FF;">,</span><span style="color: #000000;">pc</span><span style="color: #0000FF;">})</span>
end for</lang>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
Line 1,915 ⟶ 2,451:
9->9:3.79%
</pre>
Of course it is very silly to include 2 and 5 in the analysis since they're only going to appear once, and in fact if you remove them and sort by difference, with 0 here meaning +10 and -ve diffs being a "roll over", the only real outlier is 1->9, being about half what you might expect, though there does seem to be a bit of a clear bias between rolled-over and not-rolled over, namely the 6%s vs. the 7%s:
Unfortunately, that prime number generator uses a table: while 1 million primes needs ~16MB*4|8, 10 million needs ~180MB*4|8, (both easily done on either 32 or 64 bit) 100 million would need ~2GB*8, (clearly 64 bit only) which is more than this 4GB box can allocate, it seems.
<!--<syntaxhighlight lang="phix">(phixonline)-->
But it might work on a machine with lots more memory.
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">p1m</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">get_primes</span><span style="color: #0000FF;">(-</span><span style="color: #000000;">1_000_000</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">transitions</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">),</span><span style="color: #000000;">9</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">results</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">l</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">p1m</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">last</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">p1m</span><span style="color: #0000FF;">[</span><span style="color: #000000;">4</span><span style="color: #0000FF;">],</span> <span style="color: #000000;">curr</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">5</span> <span style="color: #008080;">to</span> <span style="color: #000000;">l</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">curr</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">p1m</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">],</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">transitions</span><span style="color: #0000FF;">[</span><span style="color: #000000;">last</span><span style="color: #0000FF;">][</span><span style="color: #000000;">curr</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #000000;">last</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">curr</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">9</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">9</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">tij</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">transitions</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">][</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">tij</span><span style="color: #0000FF;">!=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">pc</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">tij</span><span style="color: #0000FF;">*</span><span style="color: #000000;">100</span><span style="color: #0000FF;">/</span><span style="color: #000000;">l</span>
<span style="color: #000000;">results</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">results</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">j</span><span style="color: #0000FF;">-</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">j</span><span style="color: #0000FF;">,</span><span style="color: #000000;">pc</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #000000;">results</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sort</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">deep_copy</span><span style="color: #0000FF;">(</span><span style="color: #000000;">results</span><span style="color: #0000FF;">))</span>
<span style="color: #7060A8;">papply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">printf</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,{</span><span style="color: #008000;">"%2d, %d-&gt;%d:%3.2f%%\n"</span><span style="color: #0000FF;">},</span><span style="color: #000000;">results</span><span style="color: #0000FF;">})</span>
<!--</syntaxhighlight>-->
<pre>
-8, 9->1:8.46%
-6, 7->1:6.42%
-6, 9->3:6.44%
-4, 7->3:6.86%
-2, 3->1:5.83%
-2, 9->7:5.81%
0, 1->1:4.29%
0, 3->3:3.97%
0, 7->7:3.96%
0, 9->9:4.28%
2, 1->3:7.75%
2, 7->9:7.76%
4, 3->7:7.28%
6, 1->7:7.95%
6, 3->9:7.94%
8, 1->9:5.02%
</pre>
 
=={{header|Picat}}==
(Note: Adjustment for 1-based indices.)
<syntaxhighlight lang="picat">go =>
N = 15_485_863, % 1_000_000 primes
Primes = {P mod 10 : P in primes(N)},
Len = Primes.len,
A = new_array(10,10), bind_vars(A,0),
foreach(I in 2..Len)
P1 = 1 + Primes[I-1], % adjust for 1-based
P2 = 1 + Primes[I],
A[P1,P2] := A[P1,P2] + 1
end,
foreach(I in 0..9, J in 0..9, V = A[I+1,J+1], V > 0)
printf("%d -> %d count: %5d frequency: %0.4f%%\n", I,J,V,100*V/Len)
end,
nl.</syntaxhighlight>
 
{{out}}
<pre>num_primes = 1000000
1 -> 1 count: 42853 frequency: 4.2853%
1 -> 3 count: 77475 frequency: 7.7475%
1 -> 7 count: 79453 frequency: 7.9453%
1 -> 9 count: 50153 frequency: 5.0153%
2 -> 3 count: 1 frequency: 0.0001%
3 -> 1 count: 58255 frequency: 5.8255%
3 -> 3 count: 39668 frequency: 3.9668%
3 -> 5 count: 1 frequency: 0.0001%
3 -> 7 count: 72827 frequency: 7.2827%
3 -> 9 count: 79358 frequency: 7.9358%
5 -> 7 count: 1 frequency: 0.0001%
7 -> 1 count: 64230 frequency: 6.4230%
7 -> 3 count: 68595 frequency: 6.8595%
7 -> 7 count: 39603 frequency: 3.9603%
7 -> 9 count: 77586 frequency: 7.7586%
9 -> 1 count: 84596 frequency: 8.4596%
9 -> 3 count: 64371 frequency: 6.4371%
9 -> 7 count: 58130 frequency: 5.8130%
9 -> 9 count: 42843 frequency: 4.2843%</pre>
 
 
=={{header|PicoLisp}}==
I'm using the fast version from the Sieve of Eratosthanes task to create the list of primes.
<syntaxhighlight lang="picolisp">
<lang PicoLisp>
(load "pluser/sieve.l") # See the task "Sieve of Eratosthanes"
 
Line 1,967 ⟶ 2,583:
(T
(cons (car Tally) (bump-trans Trans (cdr Tally))))))
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 1,995 ⟶ 2,611:
=={{header|Prolog}}==
While the program can handle a million primes, it's rather slow, so I've capped it to accept up to 100,000 primes.
<langsyntaxhighlight lang="prolog">
% table of nth prime values (up to 100,000)
 
Line 2,055 ⟶ 2,671:
plus(M, N, M2),
remove_multiples(N, M2, L, R).
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 2,083 ⟶ 2,699:
=={{header|Python}}==
{{trans|D}}
<langsyntaxhighlight lang="python">def isPrime(n):
if n < 2:
return False
Line 2,131 ⟶ 2,747:
print "First {:,} primes. Transitions prime % 10 > next-prime % 10.".format(limit)
for trans in sorted(transMap):
print "{0} -> {1} count {2:5} frequency: {3}%".format(trans[0], trans[1], transMap[trans], 100.0 * transMap[trans] / limit)</langsyntaxhighlight>
{{out}}
<pre>First 1,000,000 primes. Transitions prime % 10 > next-prime % 10.
Line 2,155 ⟶ 2,771:
 
=={{header|R}}==
<langsyntaxhighlight lang="rsplus">
suppressMessages(library(gmp))
 
Line 2,181 ⟶ 2,797:
cat(sprintf("%d",limit),"first primes. Transitions prime % 10 -> next-prime % 10\n")
invisible(sapply(1:99,getOutput))
</syntaxhighlight>
</lang>
<pre>
1000000 first primes. Transitions prime % 10 -> next-prime % 10
Line 2,207 ⟶ 2,823:
=={{header|Racket}}==
 
<langsyntaxhighlight lang="racket">#lang racket
 
(require math/number-theory)
Line 2,225 ⟶ 2,841:
(match-define (cons (cons x y) freq) item)
(printf "~a → ~a count: ~a frequency: ~a %\n"
x y (~a freq #:min-width 8 #:align 'right) (~r (* 100 freq (/ 1 limit)) #:precision '(= 2))))</langsyntaxhighlight>
 
{{out}}
Line 2,255 ⟶ 2,871:
{{works with|Rakudo|2018.9}}
Using module <code>Math::Primesieve</code> to generate primes, as much faster than the built-in (but extra credit still very slow).
<syntaxhighlight lang="raku" perl6line>use Math::Primesieve;
 
my %conspiracy;
Line 2,268 ⟶ 2,884:
}
 
say "$_ \tfrequency: {($_.value/$upto*100).round(.01)} %" for %conspiracy.sort;</langsyntaxhighlight>
{{out}}
<pre>1 → 1 count: 42853 frequency: 4.29 %
Line 2,292 ⟶ 2,908:
=={{header|REXX}}==
The first &nbsp; '''do''' &nbsp; loop is a modified ''Sieve of Eratosthenes'' &nbsp; &nbsp; (just for odd numbers).
<langsyntaxhighlight lang="rexx">/*REXX pgm shows a table of whatwhich last digit follows the previous last digit for N primes*/
parse/* argfor N .primes /*N: the number of primes to be genned*/
Call time 'R'
if N=='' | N=="," then N=1000000 /*Not specified? Then use the default.*/
Numeric Digits 12
Np=N+1; w=length(N-1) /*W: width used for formatting output.*/
H=N*Parse (2**max(4,Arg (w%2+1)n ) ). /*used asN: a roughthe limitnumber forof theprimes sieve.to be looked at */
@.If n==''|n==."," Then /* Not specified? /*assume all numbers are prime (so far)*/
# n=11000000 /* Use the default /*primes found so far {assume prime 2}.*/
w=length(n-1) do j=3 by 2; if @.j=='' then iterate /*Is composite?W: width Thenused skipfor thisformatting number.o*/
#=#+1 /*bump the prime number counter. */
do m=j*j to H by j+j; @.m=; end /*strike odd multiples as composite. */
if #==Np then leave /*Enough primes? Then done with gen. */
end /*j*/ /* [↑] gen using Eratosthenes' sieve. */
!.=0 /*initialize all the frequency counters*/
say 'For ' N " primes used in this study:" /*show hdr information about this run. */
r=2 /*the last digit of the very 1st prime.*/
#=1 /*the number of primes looked at so far*/
do i=3 by 2; if @.i=='' then iterate /*This number composite? Then ignore it*/
#=#+1; parse var i '' -1 x /*bump prime counter; get its last dig.*/
!.r.x=!.r.x+1; r=x /*bump the last digit counter for prev.*/
if #==Np then leave /*Done? Then leave this DO loop. */
end /*i*/ /* [↑] examine almost all odd numbers.*/
say /* [↓] display the results to the term*/
do d=1 for 9; if d//2 | d==2 then say /*display a blank line (if appropriate)*/
do f=1 for 9; if !.d.f==0 then iterate /*Frequency count=0? Then don't show.*/
say 'digit ' d "──►" f ' has a count of: ',
right(!.d.f, w)", frequency of:" right(format(!.d.f/N*100, , 4)'%.', 10)
end /*v*/
end /*d*/ /*stick a fork in it, we're all done. */</lang>
'''output''' &nbsp; when using the default input:
<pre>
For 1000000 primes used in this study:
 
h=n*(2**max(4,(w%2+1))) /* used as a rough limit for the sieve */
h=h*1.2 /* make sure it is large enough */
prime.=1 /* assume all numbers are prime */
nn=1 /* primes found so far {2 is the firt prime)*/
Do j=3 By 2 while nn<n
If prime.j Then Do
nn=nn+1 /* bump the prime number counter. */
Do m=j*j To h By j+j
prime.m=0 /* strike odd multiples as composite */
End
End
End
Say 'Sieve of Eratosthenes finished' time('E') 'seconds'
Call time 'R'
frequency.=0 /* initialize all the frequency counts */
Say 'For' n 'primes used in this study:'
/*show hdr information about this run. */
r=2 /* the last digit of the very 1st prime (2) */
nn=1 /* the number of primes looked at */
cnt.=0
cnt.2=1
Do i=3 By 2 While nn<n+1 /* Inspect all odd numbers */
If prime.i Then Do /* it is a prime number */
nn=nn+1
Parse Var i ''-1 x /* get last digit of current prime */
cnt.x+=1 /* bump last digit counter */
frequency.r.x=frequency.r.x+1 /* bump the frequency counter */
r=x /* current becomes previous */
End
End
Say 'i='i 'largest prime'
Say 'h='h
Say /* display the results */
Do d=1 For 9
If d//2|d==2 Then
Say '' /* display a blank line (if appropriate) */
Do f=1 For 9
If frequency.d.f>0 Then
Say 'digit ' d '-->' f ' has a count of: ' right(frequency.d.f,w)||,
', frequency of:' right(format(frequency.d.f/n*100,,4)'%.',10)
End
End
Say 'Frequency analysis:' time('E') 'seconds'
sum=0
Say 'last digit Number of occurrences'
Do i=1 To 9
If cnt.i>0 Then
Say ' 'i format(cnt.i,8)
sum+=cnt.i
End
Say ' 'format(sum,10)</syntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
<pre>Sieve of Eratosthenes finished 23.526000 seconds
For 1000000 primes used in this study:
i=15485869 largest prime
h=19200000.0
 
digit 1 ──►--> 1 has a count of: 42853, frequency of: 4.2853%.
digit 1 ──►--> 3 has a count of: 77475, frequency of: 7.7475%.
digit 1 ──►--> 7 has a count of: 79453, frequency of: 7.9453%.
digit 1 ──►--> 9 has a count of: 50153, frequency of: 5.0153%.
 
digit 2 ──►--> 3 has a count of: 1, frequency of: 0.0001%.
 
digit 3 ──►--> 1 has a count of: 58255, frequency of: 5.8255%.
digit 3 ──►--> 3 has a count of: 39668, frequency of: 3.9668%.
digit 3 ──►--> 5 has a count of: 1, frequency of: 0.0001%.
digit 3 ──►--> 7 has a count of: 72828, frequency of: 7.2828%.
digit 3 ──►--> 9 has a count of: 79358, frequency of: 7.9358%.
 
digit 5 ──►--> 7 has a count of: 1, frequency of: 0.0001%.
 
digit 7 ──►--> 1 has a count of: 64230, frequency of: 6.4230%.
digit 7 ──►--> 3 has a count of: 68595, frequency of: 6.8595%.
digit 7 ──►--> 7 has a count of: 39603, frequency of: 3.9603%.
digit 7 ──►--> 9 has a count of: 77586, frequency of: 7.7586%.
 
digit 9 ──►--> 1 has a count of: 84596, frequency of: 8.4596%.
digit 9 ──►--> 3 has a count of: 64371, frequency of: 6.4371%.
digit 9 ──►--> 7 has a count of: 58130, frequency of: 5.8130%.
digit 9 ──►--> 9 has a count of: 42843, frequency of: 4.2843%.
Frequency analysis: 5.640000 seconds
</pre>
last digit Number of occurrences
1 249934
2 1
3 250110
5 1
7 250015
9 249940
1000001</pre>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">require "prime"
 
def prime_conspiracy(m)
Line 2,363 ⟶ 3,020:
end
 
prime_conspiracy(1_000_000)</langsyntaxhighlight>
{{out}}
<pre>1000000 first primes. Transitions prime % 10 → next-prime % 10.
Line 2,388 ⟶ 3,045:
=={{header|Rust}}==
Execution time is about 13 seconds on my system (macOS 10.15.4, 3.2GHz Quad-Core Intel Core i5).
<syntaxhighlight lang ="rust">struct BitArray// {main.rs
mod bit_array;
array : Vec<u32>
mod prime_sieve;
}
 
use prime_sieve::PrimeSieve;
impl BitArray {
fn new(size : usize) -> BitArray {
BitArray { array : vec![0; (size+31)/32] }
}
fn get(&self, index : usize) -> bool {
let bit = 1 << (index & 31);
(self.array[index >> 5] & bit) != 0
}
fn set(&mut self, index : usize, new_val : bool) {
let bit = 1 << (index & 31);
if new_val {
self.array[index >> 5] |= bit;
} else {
self.array[index >> 5] &= !bit;
}
}
}
 
struct Sieve {
composite : BitArray
}
 
impl Sieve {
fn new(limit : usize) -> Sieve {
let size : usize = 1 + 2 * (limit/2);
let mut sieve = Sieve { composite : BitArray::new(size/2) };
let mut p = 3;
while p * p <= size {
if !sieve.composite.get(p/2 - 1) {
let inc = p * 2;
let mut q = p * p;
while q <= size {
sieve.composite.set(q/2 - 1, true);
q += inc;
}
}
p += 2;
}
sieve
}
fn is_prime(&self, n : usize) -> bool {
if n < 2 {
return false;
}
if n % 2 == 0 {
return n == 2;
}
!self.composite.get(n/2 - 1)
}
}
 
// See https://en.wikipedia.org/wiki/Prime_number_theorem#Approximations_for_the_nth_prime_number
fn upper_bound_for_nth_prime(n : usize) -> usize {
let x = n as f64;
(x * (x.ln() + x.ln().ln())) as usize
}
 
fn compute_transitions(limit : usize) {
use std::collections::BTreeMap;
let mut transitions = BTreeMap::new();
let mut prev = 2;
let mut count = 0;
let sieve = SievePrimeSieve::new(upper_bound_for_nth_prime(limit));
let mut n = 3;
while count < limit {
Line 2,471 ⟶ 3,079:
}
println!("First {} prime numbers:", limit);
for ((from, to), c) in & transitions {
let freq = 100.0 * (*c as f32) / (limit as f32);
println!("{} -> {}: count = {:7}, frequency = {:.2} %", from, to, c, freq);
"{} -> {}: count = {:7}, frequency = {:.2} %",
from, to, c, freq
);
}
}
Line 2,481 ⟶ 3,092:
println!();
compute_transitions(100000000);
}</langsyntaxhighlight>
 
<syntaxhighlight lang="rust">// prime_sieve.rs
use crate::bit_array;
 
pub struct PrimeSieve {
composite: bit_array::BitArray,
}
 
impl PrimeSieve {
pub fn new(limit: usize) -> PrimeSieve {
let mut sieve = PrimeSieve {
composite: bit_array::BitArray::new(limit / 2),
};
let mut p = 3;
while p * p <= limit {
if !sieve.composite.get(p / 2 - 1) {
let inc = p * 2;
let mut q = p * p;
while q <= limit {
sieve.composite.set(q / 2 - 1, true);
q += inc;
}
}
p += 2;
}
sieve
}
pub fn is_prime(&self, n: usize) -> bool {
if n < 2 {
return false;
}
if n % 2 == 0 {
return n == 2;
}
!self.composite.get(n / 2 - 1)
}
}</syntaxhighlight>
 
<syntaxhighlight lang="rust">// bit_array.rs
pub struct BitArray {
array: Vec<u32>,
}
 
impl BitArray {
pub fn new(size: usize) -> BitArray {
BitArray {
array: vec![0; (size + 31) / 32],
}
}
pub fn get(&self, index: usize) -> bool {
let bit = 1 << (index & 31);
(self.array[index >> 5] & bit) != 0
}
pub fn set(&mut self, index: usize, new_val: bool) {
let bit = 1 << (index & 31);
if new_val {
self.array[index >> 5] |= bit;
} else {
self.array[index >> 5] &= !bit;
}
}
}</syntaxhighlight>
 
{{out}}
Line 2,530 ⟶ 3,203:
===Using "primal" crate===
Execution time is about 3 seconds on my system (macOS 10.15.4, 3.2GHz Quad-Core Intel Core i5).
Same output as above.
<lang rust>// [dependencies]
<syntaxhighlight lang="rust">// [dependencies]
// primal = "0.2"
 
fn compute_transitions(limit: usize) {
fn main() {
use std::collections::BTreeMap;
let mut transitions = BTreeMap::new();
let mut prev = 0;
let limit = 100_000_000;
for n in primal::Primes::all().take(limit) {
let digit = n % 10;
Line 2,551 ⟶ 3,224:
}
println!("First {} prime numbers:", limit);
for ((from, to), c) in & transitions {
let freq = 100.0 * (*c as f32) / (limit as f32);
println!("{} -> {}: count = {:7}, frequency = {:.2} %", from, to, c, freq);
"{} -> {}: count = {:7}, frequency = {:.2} %",
from, to, c, freq
);
}
}
}</lang>
 
fn main() {
compute_transitions(1000000);
println!();
compute_transitions(100000000);
}</syntaxhighlight>
 
=={{header|Scala}}==
===Imperative version (Ugly, side effects)===
Con: Has to unfair assume the one millionth prime.
<langsyntaxhighlight Scalalang="scala">import scala.annotation.tailrec
import scala.collection.mutable
 
Line 2,612 ⟶ 3,294:
 
println(s"Successfully completed without errors. [total ${scala.compat.Platform.currentTime - executionStart} ms]")
}</langsyntaxhighlight>
===Functional version, memoizatized===
<langsyntaxhighlight Scalalang="scala">object PrimeConspiracy1 extends App {
private val oddPrimes: Stream[Int] =
3 #:: Stream.from(5, 2)
Line 2,636 ⟶ 3,318:
 
println(s"Successfully completed without errors. [total ${scala.compat.Platform.currentTime - executionStart} ms]")
}</langsyntaxhighlight>
 
=={{header|Seed7}}==
Line 2,647 ⟶ 3,329:
Executing the [http://seed7.sourceforge.net/faq.htm#compile compiled] Seed7 program takes only 0.08 seconds.
 
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "float.s7i";
 
Line 2,696 ⟶ 3,378:
flt(count * 100)/flt(total) digits 2 lpad 4 <& " %");
end for;
end func;</langsyntaxhighlight>
 
{{out}}
Line 2,723 ⟶ 3,405:
=={{header|Sidef}}==
{{trans|zkl}}
<langsyntaxhighlight lang="ruby">var primes = (^Inf -> lazy.grep{.is_prime})
 
var upto = 1e6
Line 2,736 ⟶ 3,418:
for k,v in (conspiracy.sort_by{|k,_v| k }) {
printf("%s count: %6s\tfrequency: %2.2f %\n", k, v.commify, v / upto * 100)
}</langsyntaxhighlight>
{{out}}
<pre>
Line 2,761 ⟶ 3,443:
 
=={{header|VBA}}==
<syntaxhighlight lang="vb">
<lang vb>
Option Explicit
 
Line 2,843 ⟶ 3,525:
Debug.Print K & " " & Right(" " & Dict(K), 6) & " " & Dict(K) / Nb * 100 & "%"
Next
End Sub</langsyntaxhighlight>
{{out}}
<pre>1000000 primes, last prime considered: 15485867
Line 2,894 ⟶ 3,576:
----------------------------
Execution time : 35,816s.</pre>
 
=={{header|Wren}}==
{{trans|Go}}
{{libheader|Wren-fmt}}
{{libheader|Wren-math}}
{{libheader|Wren-sort}}
Limited to the first 10 million primes in order to finish in a reasonable time (around 11.4 seconds on my system).
<syntaxhighlight lang="wren">import "./fmt" for Fmt
import "./math" for Int
import "./sort" for Sort
 
var reportTransitions = Fn.new { |transMap, num|
var keys = transMap.keys.toList
Sort.quick(keys)
System.print("First %(Fmt.dc(0, num)) primes. Transitions prime \% 10 -> next-prime \% 10.")
for (key in keys) {
var count = transMap[key]
var freq = count / num * 100
System.write("%((key/10).floor) -> %(key%10) count: %(Fmt.dc(8, count))")
System.print(" frequency: %(Fmt.f(4, freq, 2))\%")
}
System.print()
}
 
// sieve up to the 10 millionth prime
var start = System.clock
var sieved = Int.primeSieve(179424673)
var transMap = {}
var i = 2 // last digit of first prime (2)
var n = 1 // index of next prime (3) in sieved
for (num in [1e4, 1e5, 1e6, 1e7]) {
while(n < num) {
var p = sieved[n]
// count transition of i -> j
var j = p % 10
var k = i*10 + j
var t = transMap[k]
if (!t) {
transMap[k] = 1
} else {
transMap[k] = t + 1
}
i = j
n = n + 1
}
reportTransitions.call(transMap, n)
}
System.print("Took %(System.clock - start) seconds.")</syntaxhighlight>
 
{{out}}
<pre>
First 10,000 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%
2 -> 3 count: 1 frequency: 0.01%
3 -> 1 count: 529 frequency: 5.29%
3 -> 3 count: 324 frequency: 3.24%
3 -> 5 count: 1 frequency: 0.01%
3 -> 7 count: 754 frequency: 7.54%
3 -> 9 count: 907 frequency: 9.07%
5 -> 7 count: 1 frequency: 0.01%
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: 635 frequency: 6.35%
9 -> 7 count: 541 frequency: 5.41%
9 -> 9 count: 379 frequency: 3.79%
 
First 100,000 primes. Transitions prime % 10 -> next-prime % 10.
1 -> 1 count: 4,104 frequency: 4.10%
1 -> 3 count: 7,961 frequency: 7.96%
1 -> 7 count: 8,297 frequency: 8.30%
1 -> 9 count: 4,605 frequency: 4.61%
2 -> 3 count: 1 frequency: 0.00%
3 -> 1 count: 5,596 frequency: 5.60%
3 -> 3 count: 3,604 frequency: 3.60%
3 -> 5 count: 1 frequency: 0.00%
3 -> 7 count: 7,419 frequency: 7.42%
3 -> 9 count: 8,387 frequency: 8.39%
5 -> 7 count: 1 frequency: 0.00%
7 -> 1 count: 6,438 frequency: 6.44%
7 -> 3 count: 6,928 frequency: 6.93%
7 -> 7 count: 3,627 frequency: 3.63%
7 -> 9 count: 8,022 frequency: 8.02%
9 -> 1 count: 8,829 frequency: 8.83%
9 -> 3 count: 6,513 frequency: 6.51%
9 -> 7 count: 5,671 frequency: 5.67%
9 -> 9 count: 3,995 frequency: 4.00%
 
First 1,000,000 primes. Transitions prime % 10 -> next-prime % 10.
1 -> 1 count: 42,853 frequency: 4.29%
1 -> 3 count: 77,475 frequency: 7.75%
1 -> 7 count: 79,453 frequency: 7.95%
1 -> 9 count: 50,153 frequency: 5.02%
2 -> 3 count: 1 frequency: 0.00%
3 -> 1 count: 58,255 frequency: 5.83%
3 -> 3 count: 39,668 frequency: 3.97%
3 -> 5 count: 1 frequency: 0.00%
3 -> 7 count: 72,827 frequency: 7.28%
3 -> 9 count: 79,358 frequency: 7.94%
5 -> 7 count: 1 frequency: 0.00%
7 -> 1 count: 64,230 frequency: 6.42%
7 -> 3 count: 68,595 frequency: 6.86%
7 -> 7 count: 39,603 frequency: 3.96%
7 -> 9 count: 77,586 frequency: 7.76%
9 -> 1 count: 84,596 frequency: 8.46%
9 -> 3 count: 64,371 frequency: 6.44%
9 -> 7 count: 58,130 frequency: 5.81%
9 -> 9 count: 42,843 frequency: 4.28%
 
First 10,000,000 primes. Transitions prime % 10 -> next-prime % 10.
1 -> 1 count: 446,808 frequency: 4.47%
1 -> 3 count: 756,071 frequency: 7.56%
1 -> 7 count: 769,923 frequency: 7.70%
1 -> 9 count: 526,953 frequency: 5.27%
2 -> 3 count: 1 frequency: 0.00%
3 -> 1 count: 593,195 frequency: 5.93%
3 -> 3 count: 422,302 frequency: 4.22%
3 -> 5 count: 1 frequency: 0.00%
3 -> 7 count: 714,795 frequency: 7.15%
3 -> 9 count: 769,915 frequency: 7.70%
5 -> 7 count: 1 frequency: 0.00%
7 -> 1 count: 639,384 frequency: 6.39%
7 -> 3 count: 681,759 frequency: 6.82%
7 -> 7 count: 422,289 frequency: 4.22%
7 -> 9 count: 756,851 frequency: 7.57%
9 -> 1 count: 820,368 frequency: 8.20%
9 -> 3 count: 640,076 frequency: 6.40%
9 -> 7 count: 593,275 frequency: 5.93%
9 -> 9 count: 446,032 frequency: 4.46%
 
Took 11.407733 seconds.
</pre>
 
=={{header|zkl}}==
{{trans|Raku}}
Using [[Extensible prime generator#zkl]].
<langsyntaxhighlight lang="zkl">const CNT =0d1_000_000;
sieve :=Import("sieve.zkl",False,False,False).postponed_sieve;
conspiracy:=Dictionary();
Line 2,908 ⟶ 3,727:
foreach key in (conspiracy.keys.sort()){ v:=conspiracy[key].toFloat();
println("%s%,6d\tfrequency: %2.2F%".fmt(key,v,v/CNT *100))
}</langsyntaxhighlight>
{{out}}
<pre>
2,294

edits