Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,15 @@
|
|||
permutationsort <- function(x)
|
||||
{
|
||||
if(!require(e1071) stop("the package e1071 is required")
|
||||
is.sorted <- function(x) all(diff(x) >= 0)
|
||||
|
||||
perms <- permutations(length(x))
|
||||
i <- 1
|
||||
while(!is.sorted(x))
|
||||
{
|
||||
x <- x[perms[i,]]
|
||||
i <- i + 1
|
||||
}
|
||||
x
|
||||
}
|
||||
permutationsort(c(1, 10, 9, 7, 3, 0))
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
library(RcppAlgos)
|
||||
permuSort <- function(list)
|
||||
{
|
||||
iter <- permuteIter(list)
|
||||
while(is.unsorted(iter$nextIter())){}#iter$nextIter advances iter to the next iteration and returns it.
|
||||
iter$currIter()
|
||||
}
|
||||
test <- sample(10)
|
||||
print(test)
|
||||
permuSort(test)
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
repeat
|
||||
{
|
||||
if(!is.unsorted(iter$nextIter())) break
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue