Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
5
Task/Generator-Exponential/Jq/generator-exponential-1.jq
Normal file
5
Task/Generator-Exponential/Jq/generator-exponential-1.jq
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# Compute self^m where m is a non-negative integer:
|
||||
def pow(m): . as $in | reduce range(0;m) as $i (1; .*$in);
|
||||
|
||||
# state: [i, i^m]
|
||||
def next_power(m): .[0] + 1 | [., pow(m) ];
|
||||
7
Task/Generator-Exponential/Jq/generator-exponential-2.jq
Normal file
7
Task/Generator-Exponential/Jq/generator-exponential-2.jq
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# skip m states, and return the next state
|
||||
def skip(m; next):
|
||||
if m <= 0 then . else next | skip(m-1; next) end;
|
||||
|
||||
# emit m states including the initial state
|
||||
def emit(m; next):
|
||||
if m <= 0 then empty else ., (next | emit(m-1; next)) end;
|
||||
5
Task/Generator-Exponential/Jq/generator-exponential-3.jq
Normal file
5
Task/Generator-Exponential/Jq/generator-exponential-3.jq
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# Generate the first 4 values in the sequence i^2:
|
||||
[0,0] | emit(4; next_power(2)) | .[1]
|
||||
|
||||
# Generate all the values in the sequence i^3 less than 100:
|
||||
[0,0] | recurse(next_power(3) | if .[1] < 100 then . else empty end) | .[1]
|
||||
27
Task/Generator-Exponential/Jq/generator-exponential-4.jq
Normal file
27
Task/Generator-Exponential/Jq/generator-exponential-4.jq
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# Infrastructure:
|
||||
def last(f): reduce f as $i (null; $i);
|
||||
|
||||
# emit the last value that satisfies condition, or null
|
||||
def while(condition; next):
|
||||
def w: if condition then ., (next|w) else empty end;
|
||||
last(w);
|
||||
|
||||
# Powers of m1 that are not also powers of m2.
|
||||
# filtered_next_power(m1;m2) produces [[i, i^m1], [j, j^m1]] where i^m1
|
||||
# is not a power of m2 and j^m2 < i^m1
|
||||
#
|
||||
def filtered_next_power(m1; m2):
|
||||
if . then . else [[0,0],[0,0]] end
|
||||
| (.[0] | next_power(m1)) as $next1
|
||||
| (.[1] | while( .[1] <= $next1[1]; next_power(m2))) as $next2
|
||||
| if $next1[1] == $next2[1]
|
||||
then [$next1, $next2] | filtered_next_power(m1;m2)
|
||||
else [$next1, $next2]
|
||||
end ;
|
||||
|
||||
# Emit ten powers of 2 that are NOT powers of 3,
|
||||
# skipping the first 20 integers satisfying the condition, including 0.
|
||||
filtered_next_power(2;3)
|
||||
| skip(20; filtered_next_power(2;3))
|
||||
| emit(10; filtered_next_power(2;3))
|
||||
| .[0][1]
|
||||
11
Task/Generator-Exponential/Jq/generator-exponential-5.jq
Normal file
11
Task/Generator-Exponential/Jq/generator-exponential-5.jq
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
$ jq -n -f generators.jq
|
||||
529
|
||||
576
|
||||
625
|
||||
676
|
||||
784
|
||||
841
|
||||
900
|
||||
961
|
||||
1024
|
||||
1089
|
||||
Loading…
Add table
Add a link
Reference in a new issue