ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 29 Jan 2018 09:19:21 -0600Rekursive Generator which fetches a subset of elements on demandhttps://ask.sagemath.org/question/40850/rekursive-generator-which-fetches-a-subset-of-elements-on-demand/i have following Task to solve; write a generator which outputs a Set (M) of Sets(S) with subsets of M from S \ {s] and M and {s} .. sounds weird.
what i wrote is:
def getSubsets(S):
if(sage.sets.set.is_Set(S)):
s=Set(S.subsets())
for sub in s:
yield [sub]
else:
if(S.is_empty() == false):
yield [S]
else:
yield []
with following test, i can mySet.next() fetch a Set from the Pool of Sets.
var('a','b','c','d')
a=Set([3,4])
b=Set([a,c,d])
d=Set([])
mySet = Set([a,b,1,2])
print(mySet)
myGen = getSubsets(mySet)
Now i have a Problem, rewriting that as recursive function. Is that even possible?
Please dont send in "perfect solutions", i want to learn how to solve that puzzle by myself.
Thank you!
SageIsABummerMon, 29 Jan 2018 09:19:21 -0600https://ask.sagemath.org/question/40850/