Generating combinations

M

mrajanikrishna

Hi friends,

I am generating combinations from a set with different sub sets.
Here is my code. For this example, actually I need to get 56
combinations but I am getting 35 only. Can anybody suggest where I was
wrong?

<script language="javascript">
var st=Array("1","2","3","4","5","6");
var n=0;
n=parseInt(st.length);
for(k=2;k<=parseInt(st.length);++k)
{
document.write("<br>Subset is " + k + "<br>");
for(i=0;i<parseInt(st.length);++i)
{
for(j=i+1;j<parseInt(st.length);++j)
{
if(j<=(n-(k-1)))
{
document.write("(" + st + ",");
for(l=1;l<k;++l)
{
document.write(st[j+(l-1)] + ",");
}
document.write(")<br>");
}
}
}
}
</script>
 
M

mark carew

var st=Array("1","2","3","4","5","6");

Wild guess
var st=Array("1","2","3","4","5","6");
gives (6 * 6) -1 --- 35
would
var st=Array("1","2","3","4","5","6","7","8");
give (8 * 8) - 1 --- 63
just throw away 7 results gives --- 56
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,017
Latest member
GreenAcreCBDGummiesReview

Latest Threads

Top