11 lines
268 B
Text
11 lines
268 B
Text
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]])
|
|
}
|
|
return()
|
|
}
|
|
|
|
permutations({|p| say p }, [0,1,2])
|