I am trying to get a powerset (all subsets) of a set.
I couldn’t find a code in Ruby, but I found a code in Python.
I’m trying to convert it to Ruby but it’s not done easily.
head, tail = seq[:1], seq[1:]
for smaller in powset(tail):
yield head + smaller
Can somebody translate the Python code into Ruby?
(I have difficulty in understanding the yield part)
Actually I want to add a method to Set class.
How can I change the function into a method which won’t take any
(Can a method be recursive if it doesn’t take a parameter?
Do I need a helper private method?)
s = Set[1,2,3]
ps = s.powerset #returns a set of powerset of s