Exactly three adjacent 3 in lists: Difference between revisions

Content added Content deleted
(→‎{{header|jq}}: use index/1)
Line 352: Line 352:


The test cases, and the output, are exactly as for entry at [[#Wren]].
The test cases, and the output, are exactly as for entry at [[#Wren]].
'''Preliminaries'''
<lang jq>def count(s): reduce s as $x (0; .+1);


'''Preliminaries'''
# Output: a stream of arrays of length $w
<lang jq>def count(s): reduce s as $x (0; .+1);</lang>
def moving_window($w):
select(length >= $w)
| recurse( .[1:]; length >= $w) | .[:$w];</lang>
'''The task'''
'''The task'''
<lang jq>def lists : [
<lang jq>def lists : [
Line 373: Line 369:
def threeConsecutiveThrees:
def threeConsecutiveThrees:
count(.[] == 3 // empty) == 3
count(.[] == 3 // empty) == 3
and any( moving_window(3); all(.[]; . == 3));
and index([3,3,3]);


"Exactly three adjacent 3's:",
"Exactly three adjacent 3's:",
Line 381: Line 377:
{{out}}
{{out}}
As for [[#Wren]].
As for [[#Wren]].



=={{header|Julia}}==
=={{header|Julia}}==