Exactly three adjacent 3 in lists: Difference between revisions

Content added Content deleted
(Added Applesoft BASIC, BASIC256, Chipmunk Basic, GW-BASIC, Minimal BASIC, MSX Basic, PureBasic, QBasic, Quite BASIC, True BASIC and XBasic)
(Created Nim solution.)
Line 1,324: Line 1,324:
{1,2,3,4,5,6,7,8,9}->False
{1,2,3,4,5,6,7,8,9}->False
{4,6,8,7,2,3,3,3,1}->True
{4,6,8,7,2,3,3,3,1}->True
</pre>

=={{header|Nim}}==
<syntaxhighlight lang="Nim">const Lists = [[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]]

func contains3Adjacent3(s: openArray[int]): bool =
if s.len < 3: return false
var count = 0
for i in 0..s.high:
if s[i] == 3:
inc count
if count == 3: return true
else:
count = 0


for list in Lists:
echo list, ": ", list.contains3Adjacent3()
</syntaxhighlight>

{{out}}
<pre>[9, 3, 3, 3, 2, 1, 7, 8, 5]: true
[5, 2, 9, 3, 3, 7, 8, 4, 1]: false
[1, 4, 3, 6, 7, 3, 8, 3, 2]: false
[1, 2, 3, 4, 5, 6, 7, 8, 9]: false
[4, 6, 8, 7, 2, 3, 3, 3, 1]: true
</pre>
</pre>