Boustrophedon transform: Difference between revisions
→{{header|jq}}: two stretch tasks
(→{{header|jq}}: two stretch tasks) |
|||
Line 480:
=={{header|jq}}==
'''Works with gojq, the Go implementation of jq'''
'''Works with jq, the C implementation of jq, within the limits of IEEE 764 arithmetic'''
'''Adapted from [[#Wren|Wren]]'''
The results for the "stretch" tasks are based on the use of gojq.
<syntaxhighlight lang="jq">
### Generic functions
Line 500 ⟶ 502:
# An array of length specified by .
def array($value): [range(0; .) | $value];
# Give a glimpse of the (very large) input number
def glimpse:
tostring
| "\(.[:20]) ... \(.[-20:]) \(length) digits";
### The Boustrophedon transform
Line 506 ⟶ 513:
| ($k | array(0)) as $list
| {b: $list,
cache: [
| .b[0] = $a[0]▼
# input: {
| def T($k; $n):
if $n == 0 then .result = $a[k]
|
| T($
| .
| .
end
end;
| reduce range(1; $k) as $n (.;
| .b;
### Exercises
Line 541 ⟶ 549:
"\nFactorials:",
boustrophedon([limit(15; factorials)]),
## Stretch tasks require gojq
"\nGlimpse of 1000th element for the Fibonaccis",
(boustrophedon([limit(1000; fibs)]) | .[999] | glimpse),
"\nGlimpse of 1000th element for the factorials:",
(boustrophedon([limit(1000; factorials)]) | .[999] | glimpse)
</syntaxhighlight>
{{output}}
Line 562 ⟶ 577:
Factorials:
[1,2,5,17,73,381,2347,16701,134993,1222873,12279251,135425553,1627809401,21183890469,296773827547]
</pre>▼
Glimpse of the 1000th element for the Fibonaccis:
56757474139659741321 ... 66135597559209657242 2370 digits
Glimpse of 1000th element for the factorials:
13714256926920345740 ... 19230014799151339821 2566 digits
▲</pre>
=={{header|Julia}}==
|