Exactly three adjacent 3 in lists: Difference between revisions

Added Easylang
(Created Nim solution.)
(Added Easylang)
 
(6 intermediate revisions by 3 users not shown)
Line 977:
1 2 3 4 5 6 7 8 9 -> false
4 6 8 7 2 3 3 3 1 -> true</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
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 has3adj3 l[] .
for v in l[]
if v = 3
cnt += 1
else
if cnt = 3
break 1
.
cnt = 0
.
.
return if cnt = 3
.
for i to len lists[][]
write has3adj3 lists[i][] & " "
.
</syntaxhighlight>
{{out}}
<pre>
1 0 0 0 1
</pre>
 
=={{header|F_Sharp|F#}}==
Line 1,020 ⟶ 1,045:
{ 1 2 3 4 5 6 7 8 9 } -> f
{ 4 6 8 7 2 3 3 3 1 } -> t
</pre>
A somewhat simpler implementation without the fancy statistics and generalizations vocabs.
<syntaxhighlight lang=factor>USING: io kernel sequences ;
{
{ 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 = ] count 3 = ]
[ { 3 3 3 } subseq-of? ]
bi and "true" "false" ? print
] each</syntaxhighlight>
{{out}}
<pre>
true
false
false
false
true
</pre>
 
Line 1,054 ⟶ 1,101:
5 true
</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
local fn ThreeAdjacentThrees
NSUInteger i, j
CFMutableArrayRef lists = fn MutableArrayNew
MutableArrayInsertObjectAtIndex( lists, @"9,3,3,3,2,1,7,8,5", 0 )
MutableArrayInsertObjectAtIndex( lists, @"5,2,9,3,3,7,8,4,1", 1 )
MutableArrayInsertObjectAtIndex( lists, @"1,4,3,6,7,3,8,3,2", 2 )
MutableArrayInsertObjectAtIndex( lists, @"1,2,3,4,5,6,7,8,9", 3 )
MutableArrayInsertObjectAtIndex( lists, @"4,6,8,7,2,3,3,3,1", 4 )
for i = 0 to len(lists) -1
CFArrayRef tempArr = fn StringComponentsSeparatedByString( lists[i], @"," )
NSUInteger counter = 0, elements = len(tempArr) -1
for j = 0 to elements
if ( counter == 3 ) then NSLog( @"%@: TRUE — contains 3 adjacent 3s.", lists[i] )
if ( counter != 3 ) and ( j == elements )
NSLog( @"%@: FALSE — doesn't contain 3 adjacent 3s.", lists[i] )
end if
if fn StringIsEqual( tempArr[j], @"3" ) == NO then counter = 0 : continue
if fn StringIsEqual( tempArr[j], @"3" ) == YES then counter++ : continue
next
next
end fn
 
fn ThreeAdjacentThrees
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
9,3,3,3,2,1,7,8,5: TRUE — contains 3 adjacent 3s.
9,3,3,3,2,1,7,8,5: FALSE — doesn't contain 3 adjacent 3s.
5,2,9,3,3,7,8,4,1: FALSE — doesn't contain 3 adjacent 3s.
1,4,3,6,7,3,8,3,2: FALSE — doesn't contain 3 adjacent 3s.
1,2,3,4,5,6,7,8,9: FALSE — doesn't contain 3 adjacent 3s.
4,6,8,7,2,3,3,3,1: TRUE — contains 3 adjacent 3s.
</pre>
 
 
=={{header|Go}}==
Line 1,844 ⟶ 1,934:
=={{header|Wren}}==
{{libheader|Wren-seq}}
<syntaxhighlight lang="ecmascriptwren">import "./seq" for Lst
 
var lists = [
Line 1,875 ⟶ 1,965:
</pre>
Or, more generally, replacing everything after 'lists' with the following:
<syntaxhighlight lang="ecmascriptwren">for (d in 1..4) {
System.print("Exactly %(d) adjacent %(d)'s:")
for (list in lists) {
2,060

edits