Permutations: Difference between revisions

m
m (→‎{{header|Sidef}}: updated code)
Line 9,322:
=={{header|Sidef}}==
===Built-in===
<syntaxhighlight lang="ruby">[0,1,2].permutations { |p*a|
say pa
}</syntaxhighlight>
 
Line 9,331:
 
loop {
callback([idx...])
 
var p = n-1
Line 9,347:
}
 
forperm({|*p| say p }, 3)</syntaxhighlight>
 
===Recursive===
<syntaxhighlight lang="ruby">func permutations(callback, set, perm=[]) {
set.is_empty &&|| callback(perm)
for i in ^set {
__FUNC__(callback, [
set[(0 ..^ i)..., (i+1 ..^ set.len)...]
], [perm..., set[i]])
}
2,747

edits