RobinHankin / permutations

https://robinhankin.github.io/permutations/
5 stars 3 forks source link

nice check of plainperms() #17

Open RobinHankin opened 5 years ago

RobinHankin commented 5 years ago

Knuth points out that the plain permutation algorithm produces alternating odd and even permutations and verifying this has nice R idiom:

> apply(plainperms(5),2,function(x){is.even(as.cycle(as.word(x)))})
  [1]  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
 [13]  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
 [25]  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
 [37]  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
 [49]  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
 [61]  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
 [73]  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
 [85]  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
 [97]  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
[109]  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
RobinHankin commented 5 years ago

but including this in the tests would require the partitions package to be added to the Depends list

RobinHankin commented 1 year ago

Observing here that we are using partitions::plainperms(); also there is no need to coerce to cycle form:

apply(plainperms(5),2,function(x){is.even(as.word(x))})