2022-09-18 14:50:20 +02:00
|
|
|
factorial := [n | if (n < 2) [1] [factorial (n-1) * n]];
|
2022-06-02 23:17:02 +02:00
|
|
|
|
2022-09-18 14:50:20 +02:00
|
|
|
for_all_permutations := [array fun |
|
|
|
|
iter := [start stop x | if (start >= stop) [x] [iter (start+1) stop (fun x)]];
|
2022-06-02 23:17:02 +02:00
|
|
|
iter 0 (factorial (len array)) array
|
|
|
|
];
|
|
|
|
|
|
|
|
for_all_permutations (flat 1 2 3 4 5) [array|
|
|
|
|
say array;
|
|
|
|
permute array
|
|
|
|
];
|