September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
11
Task/Permutations/Mathematica/permutations-1.math
Normal file
11
Task/Permutations/Mathematica/permutations-1.math
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
(***Standard list functions:*)
|
||||
fold[f_, x_, {}] := x
|
||||
fold[f_, x_, {h_, t___}] := fold[f, f[x, h], {t}]
|
||||
insert[L_, x_, n_] := Join[L[[;; n - 1]], {x}, L[[n ;;]]]
|
||||
|
||||
(***Generate all permutations of a list S:*)
|
||||
|
||||
permutations[S_] :=
|
||||
fold[Join @@ (Function[{L},
|
||||
Table[insert[L, #2, k + 1], {k, 0, Length[L]}]] /@ #1) &, {{}},
|
||||
S]
|
||||
Loading…
Add table
Add a link
Reference in a new issue