September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
11
Task/Pascals-triangle/Jq/pascals-triangle-1.jq
Normal file
11
Task/Pascals-triangle/Jq/pascals-triangle-1.jq
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# pascal(n) for n>=0; pascal(0) emits an empty stream.
|
||||
def pascal(n):
|
||||
def _pascal: # input: the previous row
|
||||
. as $in
|
||||
| .,
|
||||
if length >= n then empty
|
||||
else
|
||||
reduce range(0;length-1) as $i
|
||||
([1]; . + [ $in[$i] + $in[$i + 1] ]) + [1] | _pascal
|
||||
end;
|
||||
if n <= 0 then empty else [1] | _pascal end ;
|
||||
6
Task/Pascals-triangle/Jq/pascals-triangle-2.jq
Normal file
6
Task/Pascals-triangle/Jq/pascals-triangle-2.jq
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
$ jq -c -n -f pascal_triangle.jq
|
||||
[1]
|
||||
[1,1]
|
||||
[1,2,1]
|
||||
[1,3,3,1]
|
||||
[1,4,6,4,1]
|
||||
9
Task/Pascals-triangle/Jq/pascals-triangle-3.jq
Normal file
9
Task/Pascals-triangle/Jq/pascals-triangle-3.jq
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
def pascal(n):
|
||||
if n <= 0 then empty
|
||||
else [1]
|
||||
| recurse( if length >= n then empty
|
||||
else . as $in
|
||||
| reduce range(0;length-1) as $i
|
||||
([1]; . + [ $in[$i] + $in[$i + 1] ]) + [1]
|
||||
end)
|
||||
end;
|
||||
Loading…
Add table
Add a link
Reference in a new issue