Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
17
Task/Jacobsthal-numbers/Jq/jacobsthal-numbers-1.jq
Normal file
17
Task/Jacobsthal-numbers/Jq/jacobsthal-numbers-1.jq
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# Split the input array into a stream of arrays
|
||||
def chunks(n):
|
||||
def c: .[0:n], (if length > n then .[n:]|c else empty end);
|
||||
c;
|
||||
|
||||
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
|
||||
|
||||
# If $j is 0, then an error condition is raised;
|
||||
# otherwise, assuming infinite-precision integer arithmetic,
|
||||
# if the input and $j are integers, then the result will be a pair of integers.
|
||||
def divmod($j):
|
||||
. as $i
|
||||
| ($i % $j) as $mod
|
||||
| [($i - $mod) / $j, $mod] ;
|
||||
|
||||
# To take advantage of gojq's arbitrary-precision integer arithmetic:
|
||||
def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in);
|
||||
26
Task/Jacobsthal-numbers/Jq/jacobsthal-numbers-2.jq
Normal file
26
Task/Jacobsthal-numbers/Jq/jacobsthal-numbers-2.jq
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
def jacobsthal:
|
||||
. as $n
|
||||
| ( (2|power($n)) - (if ($n%2 == 0) then 1 else -1 end)) | divmod(3)[0];
|
||||
|
||||
def jacobsthalLucas:
|
||||
. as $n
|
||||
| (2|power($n)) + (if ($n%2 == 0) then 1 else -1 end);
|
||||
|
||||
def tasks:
|
||||
def pp($width): chunks(5) | map(lpad($width)) | join("");
|
||||
|
||||
[range(0;30) | jacobsthal] as $js
|
||||
| "First 30 Jacobsthal numbers:",
|
||||
( $js | pp(12)),
|
||||
|
||||
"\nFirst 30 Jacobsthal-Lucas numbers:",
|
||||
( [range(0;30) | jacobsthalLucas] | pp(12)),
|
||||
|
||||
"\nFirst 20 Jacobsthal oblong numbers:",
|
||||
( [range(0;20) | $js[.] * $js[1+.]] | pp(14)),
|
||||
|
||||
"\nFirst 11 Jacobsthal primes:",
|
||||
limit(11; range(0; infinite) | jacobsthal | select(is_prime))
|
||||
;
|
||||
|
||||
tasks
|
||||
Loading…
Add table
Add a link
Reference in a new issue