Trying to tackle the generation of subsets inside of python for my Discrete Mathematics class. I have a set to split up into subsets which are ordered based on a specific condition and with a certain size.
As an example: Subset = {x1, x2, x3} ⊆ {5, 10, 15, 20, 25} and x1 < x2 < x3.
I would like to generate all possible subsets from the larger set, sized 3, and with the condition that they are ordered in ascension. There's a very good chance I'm overthinking the implementation of this. I currently have a working permutation generator but it basically generates all possible combinations. The code:
def perm(elements):
if len(elements) <= 1:
yield elements
else:
for i in range(len(elements)):
for p in perm(elements[:i] + elements[i+1:]):
yield [elements[i]] + p
I'd like to be able to modify this so that I can use this function to generate what I am looking for. I tried modifying the initial for loop's range but it ends up removing certain permutations which would be possible otherwise, and it's fair to say I am more stuck than making progress. Any help or advice would be appreciated.