Prime conspiracy: Difference between revisions

→‎{{header|REXX}}: rewritten to be readable
(→‎{{header|REXX}}: rewritten to be readable)
 
(10 intermediate revisions by 8 users not shown)
Line 62:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">V limit = 1000000
V k = limit
V n = k * 17
Line 88:
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))</langsyntaxhighlight>
 
{{out}}
Line 117:
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 195:
FI
OD
OD</langsyntaxhighlight>
{{out}}
<pre>
Line 225:
This takes three and a half minutes on my machine. But it's not a script you'd need to use every day.
 
<langsyntaxhighlight 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
Line 284:
end conspiracy
 
conspiracy(1000000)</langsyntaxhighlight>
 
{{output}}
<langsyntaxhighlight 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%
Line 306:
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%"</langsyntaxhighlight>
 
=={{header|C}}==
{{trans|C++}}
<langsyntaxhighlight lang="c">#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
Line 430:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>1000000 primes, last prime considered: 15485863
Line 455:
=={{header|C sharp|C#}}==
{{trans|Java}}
<langsyntaxhighlight lang="csharp">using System;
 
namespace PrimeConspiracy {
Line 501:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>1 -> 1 count: 42853 frequency : 4.29%
Line 524:
 
=={{header|C++}}==
<langsyntaxhighlight Cpplang="cpp">#include <vector>
#include <iostream>
#include <cmath>
Line 578:
}
return 0 ;
}</langsyntaxhighlight>
{{out}}
<pre>1 -> 1 count: 42853 frequency: 4.29 %
Line 603:
===Alternative using primesieve library===
{{libheader|Primesieve}}
<langsyntaxhighlight lang="cpp">#include <cstdint>
#include <iomanip>
#include <iostream>
Line 633:
compute_transitions(100000000);
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 681:
=={{header|D}}==
{{trans|Kotlin}}
<langsyntaxhighlight Dlang="d">import std.algorithm;
import std.range;
import std.stdio;
Line 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 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 777 ⟶ 817:
(vector+= trans (+ (* (% p1 m) m) (% p2 m)) 1))
(print-trans trans m N))
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 800 ⟶ 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 826 ⟶ 866:
end
 
Prime.conspiracy(1000000)</langsyntaxhighlight>
 
{{out}}
Line 854 ⟶ 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 883 ⟶ 923:
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: assocs formatting grouping kernel math math.primes math.statistics
sequences sorting ;
IN: rosetta-code.prime-conspiracy
Line 902 ⟶ 942:
1,000,000 dup header transitions [ print-trans ] each ;
MAIN: main</langsyntaxhighlight>
{{out}}
<pre>
Line 928 ⟶ 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 971 ⟶ 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 1,192 ⟶ 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,249 ⟶ 1,289:
Sleep
End
</syntaxhighlight>
</lang>
{{out}}
Output is shown side by side
Line 1,278 ⟶ 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,349 ⟶ 1,389:
}
fmt.Println()
}</langsyntaxhighlight>
 
{{out}}
Line 1,418 ⟶ 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,430 ⟶ 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,458 ⟶ 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,477 ⟶ 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,501 ⟶ 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,520 ⟶ 1,560:
9->3 64371 6.43711%
9->7 58130 5.81301%
9->9 42843 4.2843%</langsyntaxhighlight>
 
'''Extra Credit:'''
Line 1,530 ⟶ 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,551 ⟶ 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,598 ⟶ 1,638:
return composite;
}
}</langsyntaxhighlight>
 
<pre>1 -> 1 : 4,285300
Line 1,619 ⟶ 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,642 ⟶ 1,784:
for ((i, j), fr) in trans
@printf("%i → %i: freq. %3.4f%%\n", i, j, 100fr / tot)
end</langsyntaxhighlight>
 
{{out}}
Line 1,667 ⟶ 1,809:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.1.2
// compiled with flag -Xcoroutines=enable to suppress 'experimental' warning
 
Line 1,714 ⟶ 1,856:
println(" frequency: ${"%4.2f".format(transMap[trans]!! / 10000.0)}%")
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,742 ⟶ 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,792 ⟶ 1,934:
end
end
end</langsyntaxhighlight>
{{out}}
<pre>1 -> 1 count: 42853 frequency: 4.2853 %
Line 1,816 ⟶ 1,958:
=={{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">
<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>
</lang>
 
 
Line 1,848 ⟶ 1,990:
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.
<lang Nim>
# Prime conspiracy.
 
fromimport std/[algorithm, importmath, sequtils, strformat, sortedtables]
from math import sqrt
from sequtils import toSeq
from strformat import fmt
import tables
 
const N = 1_020_000_000.int # Size of sieve of Eratosthenes.
 
proc newSieve(): seq[bool] =
Line 1,895 ⟶ 2,032:
# Check if sieve was big enough.
if count < nprimes:
echo fmt&"Found only {count} primes; expected {nprimes} primes. Increase value of N."
quit(QuitFailure)
 
# Print result.
echo fmt&"{nprimes} first primes. Transitions prime %(mod 10) → next-prime %(mod 10)."
for key in sorted(toSeq(counts.keys).toSeq):
let count = counts[key]
let freq = count.toFloat * 100 / nprimes.toFloat
echo fmt&"{key[0]} -> {key[1]}: count Count: {count:7d} frequency Frequency: {freq:4.2f}%"
echo ""
 
Line 1,909 ⟶ 2,046:
isPrime.countTransitions(1_000_000)
isPrime.countTransitions(100_000_000)
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,978 ⟶ 2,115:
=={{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 2,038 ⟶ 2,187:
 
'''Extra credit:''' is included PrimeLimit = 2038074743-> 100'000'000 Primes
<langsyntaxhighlight lang="pascal">
program primCons;
{$IFNDEF FPC}
Line 2,166 ⟶ 2,315:
OutputTransitions(CntTransitions);
end.
</syntaxhighlight>
</lang>
{{Out}}
<pre>PrimCnt 10000 100000 1000000 10000000 100000000
Line 2,200 ⟶ 2,349:
{{libheader|ntheory}}
 
<langsyntaxhighlight lang="perl">use ntheory qw/forprimes nth_prime/;
 
my $upto = 1_000_000;
Line 2,214 ⟶ 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 2,260 ⟶ 2,409:
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
<lang Phix>sequence p10k = get_primes(-10000)
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
sequence transitions = repeat(repeat(0,9),9)
<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>
integer last = p10k[1], this
<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>
for i=2 to length(p10k) do
<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>
this = remainder(p10k[i],10)
<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>
transitions[last][this] += 1
<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>
last = this
<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>
end for
<span style="color: #000000;">last</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">curr</span>
for i=1 to 9 do
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
for j=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>
if transitions[i][j]!=0 then
<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>
printf(1,"%d->%d:%3.2f%%\n",{i,j,transitions[i][j]*100/length(p10k)})
<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>
end if
<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 for
<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</lang>
<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>
<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 2,297 ⟶ 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 2,349 ⟶ 2,583:
(T
(cons (car Tally) (bump-trans Trans (cdr Tally))))))
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 2,377 ⟶ 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,437 ⟶ 2,671:
plus(M, N, M2),
remove_multiples(N, M2, L, R).
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 2,465 ⟶ 2,699:
=={{header|Python}}==
{{trans|D}}
<langsyntaxhighlight lang="python">def isPrime(n):
if n < 2:
return False
Line 2,513 ⟶ 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,537 ⟶ 2,771:
 
=={{header|R}}==
<langsyntaxhighlight lang="rsplus">
suppressMessages(library(gmp))
 
Line 2,563 ⟶ 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,589 ⟶ 2,823:
=={{header|Racket}}==
 
<langsyntaxhighlight lang="racket">#lang racket
 
(require math/number-theory)
Line 2,607 ⟶ 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,637 ⟶ 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,650 ⟶ 2,884:
}
 
say "$_ \tfrequency: {($_.value/$upto*100).round(.01)} %" for %conspiracy.sort;</langsyntaxhighlight>
{{out}}
<pre>1 → 1 count: 42853 frequency: 4.29 %
Line 2,674 ⟶ 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=Parse N*Arg (2**max(4,n (w%2+1). ) ) /*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=1000000 1 /* 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. */
h=n*(2**max(4,(w%2+1))) do m=j/*j used toas Ha rough bylimit j+j;for the sieve @.m= /*strike odd multiples as composite. */
h=h*1.2 end /*m make sure it is large enough */
prime.=1 if #==Np then leave /* assume all numbers are prime /*Enough primes? Then done with gen. */
nn=1 end /*j*/ /* primes found so far {2 is the firt /* [↑] gen using Eratosthenes' sieve. prime)*/
Do j=3 By 2 while nn<n
!.= 0 /*initialize all the frequency counters*/
If prime.j Then Do
say 'For ' N " primes used in this study:" /*show hdr information about this run. */
r= 2 nn=nn+1 /* bump the prime number counter. /*the last digit of the very 1st prime.*/
Do m=j*j To h By j+j
#= 1 /*the number of primes looked at so far*/
do iprime.m=30 by 2; if @.i=='' then iterate /*This numberstrike odd multiples as composite? Then ignore it */
End
#= # + 1; parse var i '' -1 x /*bump prime counter; get its last dig.*/
End
!.r.x= !.r.x +1; r= x /*bump the last digit counter for prev.*/
End
if #==Np then leave /*Done? Then leave this DO loop. */
Say 'Sieve of Eratosthenes finished' time('E') 'seconds'
end /*i*/ /* [↑] examine almost all odd numbers.*/
Call time 'R'
say /* [↓] display the results to the term*/
frequency.=0 do d=1 for 9; if d//2 | d==2 then say /*display ainitialize all the frequency counts blank line (if appropriate)*/
Say 'For' n 'primes used in this study:'
do f=1 for 9; if !.d.f==0 then iterate /*don't show if the count is zero. */
/*show hdr information about this run. */
say 'digit ' d "──►" f ' has a count of: ',
r=2 /* the last digit of the very 1st prime (2) */
right(!.d.f, w)", frequency of:" right(format(!.d.f / N*100, , 4)'%.', 10)
nn=1 /* the number of primes looked at */
end /*f*/
cnt.=0
end /*d*/ /*stick a fork in it, we're all done. */</lang>
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
<pre>
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 12 ──►--> 13 has a count of: 42853 1, frequency of: 40.28530001%.
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 23 ──►--> 31 has a count of: 158255, frequency of: 05.00018255%.
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 35 ──►--> 17 has a count of: 58255 1, frequency of: 50.82550001%.
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 57 ──►--> 71 has a count of: 164230, frequency of: 06.00014230%.
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 79 ──►--> 1 has a count of: 6423084596, frequency of: 68.42304596%.
digit 79 ──►--> 3 has a count of: 6859564371, frequency of: 6.85954371%.
digit 79 ──►--> 7 has a count of: 3960358130, frequency of: 35.96038130%.
digit 79 ──►--> 9 has a count of: 7758642843, frequency of: 74.75862843%.
Frequency analysis: 5.640000 seconds
 
last digit Number of occurrences
digit 9 ──► 1 has a count of: 84596, frequency of: 8.4596%.
1 249934
digit 9 ──► 3 has a count of: 64371, frequency of: 6.4371%.
digit 9 ──► 7 has a count of:2 58130, frequency of: 5.8130%.1
3 250110
digit 9 ──► 9 has a count of: 42843, frequency of: 4.2843%.
5 1
</pre>
7 250015
9 249940
1000001</pre>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">require "prime"
 
def prime_conspiracy(m)
Line 2,746 ⟶ 3,020:
end
 
prime_conspiracy(1_000_000)</langsyntaxhighlight>
{{out}}
<pre>1000000 first primes. Transitions prime % 10 → next-prime % 10.
Line 2,771 ⟶ 3,045:
=={{header|Rust}}==
Execution time is about 13 seconds on my system (macOS 10.15.4, 3.2GHz Quad-Core Intel Core i5).
<langsyntaxhighlight lang="rust">// main.rs
mod bit_array;
mod prime_sieve;
Line 2,818 ⟶ 3,092:
println!();
compute_transitions(100000000);
}</langsyntaxhighlight>
 
<langsyntaxhighlight lang="rust">// prime_sieve.rs
use crate::bit_array;
 
Line 2,855 ⟶ 3,129:
!self.composite.get(n / 2 - 1)
}
}</langsyntaxhighlight>
 
<langsyntaxhighlight lang="rust">// bit_array.rs
pub struct BitArray {
array: Vec<u32>,
Line 2,880 ⟶ 3,154:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 2,930 ⟶ 3,204:
Execution time is about 3 seconds on my system (macOS 10.15.4, 3.2GHz Quad-Core Intel Core i5).
Same output as above.
<langsyntaxhighlight lang="rust">// [dependencies]
// primal = "0.2"
 
Line 2,963 ⟶ 3,237:
println!();
compute_transitions(100000000);
}</langsyntaxhighlight>
 
=={{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 3,020 ⟶ 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 3,044 ⟶ 3,318:
 
println(s"Successfully completed without errors. [total ${scala.compat.Platform.currentTime - executionStart} ms]")
}</langsyntaxhighlight>
 
=={{header|Seed7}}==
Line 3,055 ⟶ 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 3,104 ⟶ 3,378:
flt(count * 100)/flt(total) digits 2 lpad 4 <& " %");
end for;
end func;</langsyntaxhighlight>
 
{{out}}
Line 3,131 ⟶ 3,405:
=={{header|Sidef}}==
{{trans|zkl}}
<langsyntaxhighlight lang="ruby">var primes = (^Inf -> lazy.grep{.is_prime})
 
var upto = 1e6
Line 3,144 ⟶ 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 3,169 ⟶ 3,443:
 
=={{header|VBA}}==
<syntaxhighlight lang="vb">
<lang vb>
Option Explicit
 
Line 3,251 ⟶ 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 3,308 ⟶ 3,582:
{{libheader|Wren-math}}
{{libheader|Wren-sort}}
Limited to the first 10 million primes in order to finish in a reasonable time (around 2811.4 seconds on my system).
<langsyntaxhighlight ecmascriptlang="wren">import "./fmt" for Fmt
import "./math" for Int
import "./sort" for Sort
 
var reportTransitions = Fn.new { |transMap, num|
Line 3,349 ⟶ 3,623:
reportTransitions.call(transMap, n)
}
System.print("Took %(System.clock - start) seconds.")</langsyntaxhighlight>
 
{{out}}
Line 3,393 ⟶ 3,667:
9 -> 3 count: 6,513 frequency: 6.51%
9 -> 7 count: 5,671 frequency: 5.67%
9 -> 9 count: 3,995 frequency: 34.1000%
 
First 1,000,000 primes. Transitions prime % 10 -> next-prime % 10.
Line 3,437 ⟶ 3,711:
9 -> 9 count: 446,032 frequency: 4.46%
 
Took 2711.90441407733 seconds.
</pre>
 
Line 3,443 ⟶ 3,717:
{{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 3,453 ⟶ 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,290

edits