Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
50
Task/Prime-conspiracy/Seed7/prime-conspiracy.seed7
Normal file
50
Task/Prime-conspiracy/Seed7/prime-conspiracy.seed7
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
$ include "seed7_05.s7i";
|
||||
include "float.s7i";
|
||||
|
||||
const func set of integer: eratosthenes (in integer: n) is func
|
||||
result
|
||||
var set of integer: sieve is EMPTY_SET;
|
||||
local
|
||||
var integer: i is 0;
|
||||
var integer: j is 0;
|
||||
begin
|
||||
sieve := {2 .. n};
|
||||
for i range 2 to sqrt(n) do
|
||||
if i in sieve then
|
||||
for j range i ** 2 to n step i do
|
||||
excl(sieve, j);
|
||||
end for;
|
||||
end if;
|
||||
end for;
|
||||
end func;
|
||||
|
||||
const type: countHashType is hash [string] integer;
|
||||
|
||||
const proc: main is func
|
||||
local
|
||||
const set of integer: primes is eratosthenes(15485863);
|
||||
var integer: lastPrime is 0;
|
||||
var integer: currentPrime is 0;
|
||||
var string: aKey is "";
|
||||
var countHashType: countHash is countHashType.value;
|
||||
var integer: count is 0;
|
||||
var integer: total is 0;
|
||||
begin
|
||||
for currentPrime range primes do
|
||||
if lastPrime <> 0 then
|
||||
incr(total);
|
||||
aKey := str(lastPrime rem 10) <& " -> " <& str(currentPrime rem 10);
|
||||
if aKey in countHash then
|
||||
incr(countHash[aKey]);
|
||||
else
|
||||
countHash @:= [aKey] 1;
|
||||
end if;
|
||||
end if;
|
||||
lastPrime := currentPrime;
|
||||
end for;
|
||||
for aKey range sort(keys(countHash)) do
|
||||
count := countHash[aKey];
|
||||
writeln(aKey <& " count: " <& count lpad 5 <& " frequency: " <&
|
||||
flt(count * 100)/flt(total) digits 2 lpad 4 <& " %");
|
||||
end for;
|
||||
end func;
|
||||
Loading…
Add table
Add a link
Reference in a new issue