RosettaCodeData/Task/Power-set/Groovy/power-set-1.groovy

7 lines
203 B
Groovy
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
def powerSetRec(head, tail) {
if (!tail) return [head]
powerSetRec(head, tail.tail()) + powerSetRec(head + [tail.head()], tail.tail())
}
def powerSet(set) { powerSetRec([], set as List) as Set}