RobinHankin / partitions

R package for integer partitions
9 stars 5 forks source link

List all the ways of choosing 2 items from a set of 5 #18

Closed RobinHankin closed 3 years ago

RobinHankin commented 3 years ago

This question is surprisingly difficult to answer with the package. The best I can do is:

 noquote(t(apply(blockparts(rep(1,5),2)>0,2,function(x){letters[which(x)]})))
 noquote(t(apply(setparts(c(2,3))>1,2,function(x){letters[which(x)]})))

and this should be in the documentation somewhere. Note that there is no easy way to generalize to "list all the ways of choosing a chair, two deputies, and three workers from a pool of six" [apply(setparts(1:3)==1,2,function(x){letters[which(x)]}) lists only the workers]..

RobinHankin commented 3 years ago

noquote(apply(setparts(1:3),2,function(o){letters[o]})) is close, but no cigar

RobinHankin commented 3 years ago

This works: noquote(apply(setparts(1:3),2,function(x){letters[order(-x)]}))

RobinHankin commented 3 years ago

Commit b7ebb5e documents the gotcha.