Non-continuous subsequences: Difference between revisions

Content added Content deleted
(Actually does the modification.)
Line 1,689: Line 1,689:
</pre >
</pre >


=={{header|Mathematica}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
We make all the subsets then filter out the continuous ones:
We make all the subsets then filter out the continuous ones:

<lang Mathematica>GoodBad[i_List]:=Not[MatchQ[Differences[i],{1..}|{}]]
<lang Mathematica>GoodBad[i_List]:=Not[MatchQ[Differences[i],{1..}|{}]]
n=5
n=5
Select[Subsets[Range[n]],GoodBad]</lang>
Select[Subsets[Range[n]],GoodBad]</lang>
{{out}}

<pre>{{1,3},{1,4},{1,5},{2,4},{2,5},{3,5},{1,2,4},{1,2,5},{1,3,4},{1,3,5},{1,4,5},{2,3,5},{2,4,5},{1,2,3,5},{1,2,4,5},{1,3,4,5}}</pre>
gives back:

<lang Mathematica> {{1,3},{1,4},{1,5},{2,4},{2,5},{3,5},{1,2,4},{1,2,5},{1,3,4},{1,3,5},{1,4,5},{2,3,5},{2,4,5},{1,2,3,5},{1,2,4,5},{1,3,4,5}}</lang>


=={{header|Nim}}==
=={{header|Nim}}==