3 ms·
I tried with the following function that produce the power set, the set of all possible subset, in the similar spirit of the function that create all the possib
by frankohn 3y ago
I tried with the following function that produce the power set, the set of all possible subset, in the similar spirit of the function that create all the possible permutations:
Explain simply what this function does:
```
def func(ls):
if len(ls) == 0:
return [ [] ]
elif len(ls) == 1:
return [ [], ls ]
else:
x = ls[-1]
prem = func(ls[:-1])
p = prem[:]
for e in prem:
p.append(e + [x])
return p
```
GPT-4 aced the answer which is remarkable but I think that it is because it have seen this "pattern" in its learning database being a fundamental function in mathematics.
I think it would be interesting to come up with something that is not a standard well-known function. I have to think to something else.