Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
16
Task/Totient-function/Jq/totient-function-1.jq
Normal file
16
Task/Totient-function/Jq/totient-function-1.jq
Normal 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);
|
||||
19
Task/Totient-function/Jq/totient-function-2.jq
Normal file
19
Task/Totient-function/Jq/totient-function-2.jq
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue