Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
1
Task/Combinations/Sidef/combinations-1.sidef
Normal file
1
Task/Combinations/Sidef/combinations-1.sidef
Normal file
|
|
@ -0,0 +1 @@
|
|||
(@^5).combinations(3, {|c| say c })
|
||||
17
Task/Combinations/Sidef/combinations-2.sidef
Normal file
17
Task/Combinations/Sidef/combinations-2.sidef
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
func combine(n, set) {
|
||||
|
||||
set.len || return []
|
||||
n == 1 && return set.map{[_]}
|
||||
|
||||
var (head, result)
|
||||
head = set.shift
|
||||
result = combine(n-1, [set...])
|
||||
|
||||
for subarray in result {
|
||||
subarray.prepend(head)
|
||||
}
|
||||
|
||||
result + combine(n, set)
|
||||
}
|
||||
|
||||
combine(3, @^5).each {|c| say c }
|
||||
31
Task/Combinations/Sidef/combinations-3.sidef
Normal file
31
Task/Combinations/Sidef/combinations-3.sidef
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
func forcomb(callback, n, k) {
|
||||
|
||||
if (k == 0) {
|
||||
callback([])
|
||||
return()
|
||||
}
|
||||
|
||||
if (k<0 || k>n || n==0) {
|
||||
return()
|
||||
}
|
||||
|
||||
var c = @^k
|
||||
|
||||
loop {
|
||||
callback([c...])
|
||||
c[k-1]++ < n-1 && next
|
||||
var i = k-2
|
||||
while (i>=0 && c[i]>=(n-(k-i))) {
|
||||
--i
|
||||
}
|
||||
i < 0 && break
|
||||
c[i]++
|
||||
while (++i < k) {
|
||||
c[i] = c[i-1]+1
|
||||
}
|
||||
}
|
||||
|
||||
return()
|
||||
}
|
||||
|
||||
forcomb({|c| say c }, 5, 3)
|
||||
Loading…
Add table
Add a link
Reference in a new issue