Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 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 { aa, bb -> aa != bb }
|
||||
if (!comp) return 0
|
||||
def recomp = comp.collect{ it as List }.transpose().find { aa, bb -> aa != bb }
|
||||
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