Jump to content

Exactly three adjacent 3 in lists: Difference between revisions

add RPL
No edit summary
(add RPL)
Line 1,308:
[4,6,8,7,2,3,3,3,1] > true
done...
</pre>
 
=={{header|RPL}}==
The program below creates a list of the positions of the number 3, then calculates the list of first differences, which must be equal to { 1 1 } if there are exactly 3 adjacent 3 in the input list.
≪ → list
≪ { } 1 list SIZE '''FOR''' j
'''IF''' list j GET 3 == '''THEN''' j + '''END NEXT'''
'''IFERR''' ΔLIST { 1 1 } == '''THEN''' DROP 0 '''END'''
≫ ≫ '<span style="color:blue">ADJ3?</span>' STO
≪ {{9,3,3,3,2,1,7,8,5}
{5,2,9,3,3,7,8,4,1}
{1,4,3,6,7,3,8,3,2}
{1,2,3,4,5,6,7,8,9}
{4,6,8,7,2,3,3,3,1}
{3,3,3,1,2,4,5,1,3}
{0,3,3,3,3,7,2,2,6}
{3,3,3,3,3,4,4,4,4}} → cases
≪ { } 1 cases SIZE FOR j cases j GET <span style="color:blue">ADJ3?’</span> + NEXT ≫ ≫ ‘<span style="color:blue">TASK</span>’ STO
{{out}}
<pre>
1: { 1 0 0 0 1 0 0 0 }
</pre>
 
Line 1,365 ⟶ 1,387:
[3, 3, 3, 3, 3, 4, 4, 4, 4] : true
</pre>
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">func contains_n_consecutive_objs(arr, n, obj) {
1,151

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.