Exactly three adjacent 3 in lists: Difference between revisions

Added Easylang
(→‎{{header|Factor}}: Add a simpler solution)
(Added Easylang)
 
(4 intermediate revisions by 2 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
{ 9 3 3 3 2 1 7 8 5if }cnt ->= t3
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,022 ⟶ 1,047:
</pre>
A somewhat simpler implementation without the fancy statistics and generalizations vocabs.
<syntaxhighlight lang=factor>USING: formattingio kernel sequences ;
{
{ 9 3 3 3 2 1 7 8 5 }
Line 1,029 ⟶ 1,054:
{ 1 2 3 4 5 6 7 8 9 }
{ 4 6 8 7 2 3 3 3 1 }
}
} [ dup { 3 3 3 } subseq-of? "%u -> %u\n" printf ] each</syntaxhighlight>
[
{ 1 4 3 6[ 7[ 3 8= 3] 2count }3 ->= f]
{ 4 6 8 7[ 2{ 3 3 3 1 } subseq->of? t]
bi and "true" "false" ? print
] each</syntaxhighlight>
{{out}}
<pre>
true
{ 9 3 3 3 2 1 7 8 5 } -> t
false
{ 5 2 9 3 3 7 8 4 1 } -> f
false
{ 1 4 3 6 7 3 8 3 2 } -> f
false
{ 1 2 3 4 5 6 7 8 9 } -> f
true
{ 4 6 8 7 2 3 3 3 1 } -> t
</pre>
 
Line 1,904 ⟶ 1,934:
=={{header|Wren}}==
{{libheader|Wren-seq}}
<syntaxhighlight lang="ecmascriptwren">import "./seq" for Lst
 
var lists = [
Line 1,935 ⟶ 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,063

edits