RosettaCodeData/Task/Permutations/Sidef/permutations-3.sidef

12 lines
244 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
func permutations(callback, set, perm=[]) {
2023-12-16 21:33:55 -08:00
set || callback(perm)
2023-07-01 11:58:00 -04:00
for i in ^set {
__FUNC__(callback, [
2023-12-16 21:33:55 -08:00
set[^i, i+1 ..^ set.len]
2023-07-01 11:58:00 -04:00
], [perm..., set[i]])
}
return()
}
permutations({|p| say p }, [0,1,2])