RosettaCodeData/Task/Permutations/Sidef/permutations-3.sidef
2016-12-05 23:44:36 +01:00

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])