To generate all the combinations you’ll need nested loops, e.g. for combinations of two you’d have a loop to choose the first number and a loop to choose the second number. Just start the inner loop two later than the outer value rather than one later, and it’ll skip the consecutive ones.

Hi,

I want to generate all possible combinations from a set of n numbers and

want to exclude the combinations with hold two consecutive numbers.

For example,

S={1,2,3}

I just want to generate

1;

2;

3;

1,3;

Is there any smart way of doing this other than generating all combinations first and

removing the unwanted ones?

Thanks in advance