September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
11
Task/Permutations/R/permutations-2.r
Normal file
11
Task/Permutations/R/permutations-2.r
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# list of the vectors by inserting x in s at position 0...end.
|
||||
linsert <- function(x,s) lapply(0:length(s), function(k) append(s,x,k))
|
||||
|
||||
# list of all permutations of 1:n
|
||||
perm <- function(n){
|
||||
if (n == 1) list(1)
|
||||
else unlist(lapply(perm(n-1), function(s) linsert(n,s)),
|
||||
recursive = F)}
|
||||
|
||||
# permutations of a vector s
|
||||
permutation <- function(s) unique(lapply(perm(length(s)), function(i) s[i]))
|
||||
18
Task/Permutations/R/permutations-3.r
Normal file
18
Task/Permutations/R/permutations-3.r
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
> permutation(letters[1:3])
|
||||
[[1]]
|
||||
[1] "c" "b" "a"
|
||||
|
||||
[[2]]
|
||||
[1] "b" "c" "a"
|
||||
|
||||
[[3]]
|
||||
[1] "b" "a" "c"
|
||||
|
||||
[[4]]
|
||||
[1] "c" "a" "b"
|
||||
|
||||
[[5]]
|
||||
[1] "a" "c" "b"
|
||||
|
||||
[[6]]
|
||||
[1] "a" "b" "c"
|
||||
Loading…
Add table
Add a link
Reference in a new issue