Exactly three adjacent 3 in lists: Difference between revisions

→‎{{header|Factor}}: Add a simpler solution
(Initial FutureBasic task solution added)
(→‎{{header|Factor}}: Add a simpler solution)
Line 1,013:
 
[ dup adjacent? "%u -> %u\n" printf ] 5 napply</syntaxhighlight>
{{out}}
<pre>
{ 9 3 3 3 2 1 7 8 5 } -> t
{ 5 2 9 3 3 7 8 4 1 } -> f
{ 1 4 3 6 7 3 8 3 2 } -> f
{ 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: formatting 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 }
} [ dup { 3 3 3 } subseq-of? "%u -> %u\n" printf ] each</syntaxhighlight>
{{out}}
<pre>
8

edits