Non-continuous subsequences: Difference between revisions

no edit summary
m (→‎{{header|Perl}}: style tweak)
No edit summary
Line 1,406:
a c d e
</pre>
=={{header|M2000 Interpreter}}==
<lang M2000 Interpreter>
Module Non_continuous_subsequences (item$(), display){
Function positions(n) {
function onebit {
=lambda b=false (&c)-> {
=b :if c then b~:c=not b
}
}
dim k(n), p(n),res()
for i=0 to n-1:k(i)=onebit():next
m=true
flush
for i=1 to 2^n {
for j=0 to n-1 :p(j)= k(j)(&m) :next
m1=p(0)
m2=0
for j=1 to n-1
if m2 then if m1>p(j) then m2=2:exit for
if m1 < p(j) then m2++
m1=p(j)
next
if m2=2 then data cons(p())' push a copy of p() to end of stack
m=true
}
=array([])
}
 
a=positions(len(item$()))
if display then
For i=0 to len(a)-1
b=array(a,i)
line$=format$("{0::-5})",i+1,)
for j=0 to len(b)-1
if array(b,j) then line$+=" "+item$(j)
next
print line$
doc$<=line$+{
}
next
end if
line$="Non continuous subsequences:"+str$(len(a))
Print line$
doc$<=line$+{
}
}
global doc$
document doc$ ' change string to document object
Non_continuous_subsequences ("1","2","3","4"), true
Non_continuous_subsequences ("a","e","i","o","u"), true
Non_continuous_subsequences ("1","2","3","4","5","6","7","8","9","0"), false
clipboard doc$
</lang>
 
{{out}}
<pre style="height:30ex;overflow:scroll">
1) 1 3
2) 1 4
3) 2 4
4) 1 2 4
5) 1 3 4
Non continuous subsequences: 5
1) a i
2) a o
3) e o
4) a e o
5) a i o
6) a u
7) e u
8) a e u
9) i u
10) a i u
11) e i u
12) a e i u
13) a o u
14) e o u
15) a e o u
16) a i o u
Non continuous subsequences: 16
Non continuous subsequences: 968
</pre >
=={{header|Mathematica}}==
We make all the subsets then filter out the continuous ones:
Anonymous user