Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
26
Task/Sisyphus-sequence/Jq/sisyphus-sequence-1.jq
Normal file
26
Task/Sisyphus-sequence/Jq/sisyphus-sequence-1.jq
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# The def of _nwise can be omitted if using the C implementation of jq.
|
||||
def _nwise($n):
|
||||
def n: if length <= $n then . else .[0:$n] , (.[$n:] | n) end;
|
||||
n;
|
||||
|
||||
def lpad($len): tostring | ($len - length) as $l | (" " * $l) + .;
|
||||
|
||||
# tabular print
|
||||
def tprint(columns; wide):
|
||||
reduce _nwise(columns) as $row ("";
|
||||
. + ($row|map(lpad(wide)) | join(" ")) + "\n" );
|
||||
|
||||
# Input: a positive integer
|
||||
# Output: an array, $a, of length .+1 such that
|
||||
# $a[$i] is $i if $i is prime, and false otherwise.
|
||||
def primeSieve:
|
||||
# erase(i) sets .[i*j] to false for integral j > 1
|
||||
def erase($i):
|
||||
if .[$i] then
|
||||
reduce (range(2*$i; length; $i)) as $j (.; .[$j] = false)
|
||||
else .
|
||||
end;
|
||||
(. + 1) as $n
|
||||
| (($n|sqrt) / 2) as $s
|
||||
| [null, null, range(2; $n)]
|
||||
| reduce (2, 1 + (2 * range(1; $s))) as $i (.; erase($i)) ;
|
||||
42
Task/Sisyphus-sequence/Jq/sisyphus-sequence-2.jq
Normal file
42
Task/Sisyphus-sequence/Jq/sisyphus-sequence-2.jq
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# $limit is the target number of Sisyphus numbers to find and should be at least 100
|
||||
def task($limit):
|
||||
((7 * $limit) | primeSieve | map(select(.))) as $primes
|
||||
| { under250: [0, 1],
|
||||
sisyphus: [1],
|
||||
prev: 1,
|
||||
nextPrimeIndex: 0,
|
||||
specific: 1000,
|
||||
count:1 }
|
||||
| while(.count <= $limit;
|
||||
.emit = null
|
||||
| if .prev % 2 == 0 then .next = .prev/2
|
||||
else .next = .prev + $primes[.nextPrimeIndex]
|
||||
| .nextPrimeIndex += 1
|
||||
end
|
||||
| .count += 1
|
||||
| if .count <= 100 then .sisyphus += [.next] else . end
|
||||
| if .next < 250 then .under250[.next] += 1 else . end
|
||||
| if .count == 100
|
||||
then .emit = "The first 100 members of the Sisyphus sequence are:\n" + (.sisyphus | tprint(10;3))
|
||||
elif .count == .specific
|
||||
then $primes[.nextPrimeIndex-1] as $prime
|
||||
| .emit = "\(.count|lpad(8))th member is: \(.next|lpad(10)) and highest prime needed: \($prime|lpad(10))"
|
||||
| .specific *= 10
|
||||
else .
|
||||
end
|
||||
| .prev = .next )
|
||||
# The results:
|
||||
| select(.emit).emit,
|
||||
if .count == $limit
|
||||
then .under250 as $u
|
||||
| [range(1;250) | select( $u[.] == null)] as $notFound
|
||||
| ($u|max) as $max
|
||||
| [range(1;250) | select($u[.] == $max)] as $maxFound
|
||||
| "\nThese numbers under 250 do not occur in the first \(.count) terms:",
|
||||
" \($notFound)",
|
||||
"\nThese numbers under 250 occur the most in the first \(.count) terms:",
|
||||
" \($maxFound) all occur \($max) times."
|
||||
else empty
|
||||
end;
|
||||
|
||||
task(1e7)
|
||||
Loading…
Add table
Add a link
Reference in a new issue