Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
28
Task/Smith-numbers/Jq/smith-numbers-1.jq
Normal file
28
Task/Smith-numbers/Jq/smith-numbers-1.jq
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
def is_prime:
|
||||
. as $n
|
||||
| if ($n < 2) then false
|
||||
elif ($n % 2 == 0) then $n == 2
|
||||
elif ($n % 3 == 0) then $n == 3
|
||||
elif ($n % 5 == 0) then $n == 5
|
||||
elif ($n % 7 == 0) then $n == 7
|
||||
elif ($n % 11 == 0) then $n == 11
|
||||
elif ($n % 13 == 0) then $n == 13
|
||||
elif ($n % 17 == 0) then $n == 17
|
||||
elif ($n % 19 == 0) then $n == 19
|
||||
else {i:23}
|
||||
| until( (.i * .i) > $n or ($n % .i == 0); .i += 2)
|
||||
| .i * .i > $n
|
||||
end;
|
||||
|
||||
def sum(s): reduce s as $x (null; . + $x);
|
||||
|
||||
# emit a stream of the prime factors as per prime factorization
|
||||
def prime_factors:
|
||||
. as $num
|
||||
| def m($p): # emit $p with appropriate multiplicity
|
||||
$num | while( . % $p == 0; . / $p )
|
||||
| $p ;
|
||||
if (. % 2) == 0 then m(2) else empty end,
|
||||
(range(3; 1 + (./2); 2)
|
||||
| select(($num % .) == 0 and is_prime)
|
||||
| m(.));
|
||||
9
Task/Smith-numbers/Jq/smith-numbers-2.jq
Normal file
9
Task/Smith-numbers/Jq/smith-numbers-2.jq
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# input should be an integer
|
||||
def is_smith:
|
||||
def sumdigits:
|
||||
tostring|explode|map([.]|implode|tonumber)| add;
|
||||
(is_prime|not) and
|
||||
(sumdigits == sum(prime_factors|sumdigits));
|
||||
|
||||
"Smith numbers up to 10000:\n",
|
||||
(range(1; 10000) | select(is_smith))
|
||||
Loading…
Add table
Add a link
Reference in a new issue