Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
10
Task/Combinations/Groovy/combinations-1.groovy
Normal file
10
Task/Combinations/Groovy/combinations-1.groovy
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
def comb
|
||||
comb = { m, 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 }
|
||||
}
|
||||
}
|
||||
3
Task/Combinations/Groovy/combinations-2.groovy
Normal file
3
Task/Combinations/Groovy/combinations-2.groovy
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
def csny = [ "Crosby", "Stills", "Nash", "Young" ]
|
||||
println "Choose from ${csny}"
|
||||
(0..(csny.size())).each { i -> println "Choose ${i}:"; comb(i, csny).each { println it }; println() }
|
||||
1
Task/Combinations/Groovy/combinations-3.groovy
Normal file
1
Task/Combinations/Groovy/combinations-3.groovy
Normal file
|
|
@ -0,0 +1 @@
|
|||
def comb0 = { m, n -> comb(m, (0..<n)) }
|
||||
2
Task/Combinations/Groovy/combinations-4.groovy
Normal file
2
Task/Combinations/Groovy/combinations-4.groovy
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
println "Choose out of 5 (zero-based):"
|
||||
(0..3).each { i -> println "Choose ${i}:"; comb0(i, 5).each { println it }; println() }
|
||||
1
Task/Combinations/Groovy/combinations-5.groovy
Normal file
1
Task/Combinations/Groovy/combinations-5.groovy
Normal file
|
|
@ -0,0 +1 @@
|
|||
def comb1 = { m, n -> comb(m, (1..n)) }
|
||||
2
Task/Combinations/Groovy/combinations-6.groovy
Normal file
2
Task/Combinations/Groovy/combinations-6.groovy
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
println "Choose out of 5 (one-based):"
|
||||
(0..3).each { i -> println "Choose ${i}:"; comb1(i, 5).each { println it }; println() }
|
||||
Loading…
Add table
Add a link
Reference in a new issue