tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
13
Task/Ordered-Partitions/Groovy/ordered-partitions-1.groovy
Normal file
13
Task/Ordered-Partitions/Groovy/ordered-partitions-1.groovy
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
def partitions = { int... sizes ->
|
||||
int n = (sizes as List).sum()
|
||||
def perms = n == 0 ? [[]] : (1..n).permutations()
|
||||
Set parts = perms.collect { p -> sizes.collect { s -> (0..<s).collect { p.pop() } as Set } }
|
||||
parts.sort{ a, b ->
|
||||
if (!a) return 0
|
||||
def comp = [a,b].transpose().find { it[0] != it[1] }
|
||||
if (!comp) return 0
|
||||
def recomp = comp.collect{ it as List }.transpose().find { it[0] != it[1] }
|
||||
if (!recomp) return 0
|
||||
return recomp[0] <=> recomp[1]
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
partitions(2, 0, 2).each {
|
||||
println it
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue