tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
14
Task/Power-set/Groovy/power-set-1.groovy
Normal file
14
Task/Power-set/Groovy/power-set-1.groovy
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
def comb
|
||||
comb = { m, List list ->
|
||||
def n = list.size()
|
||||
m == 0 ?
|
||||
[[]] :
|
||||
(0..(n-m)).inject([]) { newlist, k ->
|
||||
def sublist = (k+1 == n) ? [] : list[(k+1)..<n]
|
||||
newlist += comb(m-1, sublist).collect { [list[k]] + it }
|
||||
}
|
||||
}
|
||||
|
||||
def powerSet = { set ->
|
||||
(0..(set.size())).inject([]){ list, i -> list + comb(i,set as List)}.collect { it as LinkedHashSet } as LinkedHashSet
|
||||
}
|
||||
3
Task/Power-set/Groovy/power-set-2.groovy
Normal file
3
Task/Power-set/Groovy/power-set-2.groovy
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
def vocalists = [ "C", "S", "N", "Y" ] as LinkedHashSet
|
||||
println "${vocalists}"
|
||||
println powerSet(vocalists)
|
||||
Loading…
Add table
Add a link
Reference in a new issue