RosettaCodeData/Task/Permutations/Sidef/permutations-3.sidef
2023-07-01 13:44:08 -04: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])