Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Combinations/CoffeeScript/combinations.coffee
Normal file
25
Task/Combinations/CoffeeScript/combinations.coffee
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
combinations = (n, p) ->
|
||||
return [ [] ] if p == 0
|
||||
i = 0
|
||||
combos = []
|
||||
combo = []
|
||||
while combo.length < p
|
||||
if i < n
|
||||
combo.push i
|
||||
i += 1
|
||||
else
|
||||
break if combo.length == 0
|
||||
i = combo.pop() + 1
|
||||
|
||||
if combo.length == p
|
||||
combos.push clone combo
|
||||
i = combo.pop() + 1
|
||||
combos
|
||||
|
||||
clone = (arr) -> (n for n in arr)
|
||||
|
||||
N = 5
|
||||
for i in [0..N]
|
||||
console.log "------ #{N} #{i}"
|
||||
for combo in combinations N, i
|
||||
console.log combo
|
||||
Loading…
Add table
Add a link
Reference in a new issue