Largest five adjacent number: Difference between revisions

Line 356:
 
=={{header|jq}}==
{{works with|jq}}
 
'''Also works with gojq, the Go implementation of jq.'''
 
First, a direct solution using only jq's standard library and a line for generating the PRN:
<syntaxhighlight lang="bash">
< /dev/random tr -cd '0-9' | head -c 1000 | jq -R '
Line 374 ⟶ 379:
"max": 99772
}
</pre>
Next, a "one-line solution" apart from generic helper functions and the line for generating the PRN:
<syntaxhighlight lang="bash">
< /dev/random tr -cd '0-9' | head -c 1000 | jq -R '
# Input: an array
# Output: a stream of the width-long subarrays
def windows(width):
range(0; 1 + length - width) as $i | .[$i:$i+width];
 
def minmax(s):
reduce s as $x ( {};
if .min == null then {min: $x, max: $x}
elif $x < .min then .min = $x
elif $x > .max then .max = $x else . end);
 
explode | minmax(windows(5) | implode | tonumber)
</syntaxhighlight>
 
=={{header|Julia}}==
2,460

edits