Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,16 @@
# jq optimizes the recursive call of _gcd in the following:
def gcd(a;b):
def _gcd:
if .[1] != 0 then [.[1], .[0] % .[1]] | _gcd else .[0] end;
[a,b] | _gcd ;
def count(s): reduce s as $x (0; .+1);
def totient:
. as $n
| count( range(0; .) | select( gcd($n; .) == 1) );
# input: determines the maximum via range(0; .)
# and so may be `infinite`
def primes_via_totient:
range(0; .) | select(totient == . - 1);

View file

@ -0,0 +1,19 @@
def task:
def task1($n):
range(1;$n)
| totient as $totient
| {i: ., $totient, isprime: ($totient == ( . - 1 ))};
task1(26);
def onepass:
reduce (10000 | primes_via_totient) as $p ({};
if $p < 10000
then .["10^4"] += 1
| if $p < 1000
then .["10^3"] += 1
| if $p < 100
then .["10^2"] += 1
else . end else . end else . end) ;
task, "\nCounts of primes up to the given limits:", onepass