我正试图这样做,它正在吞噬我.我知道这不复杂.我有很多项目,这个数字可以等于或大于3.然后我需要确定完成总计的项目组的可能组合.唯一的限制是团体应该有三件或更多件,不超过(但包括)七件.
例如:
如果我有7个项目,那么我可以拥有这些可能的组:
如果我有12个项目,我可以拥有这些可能的组:
我考虑了递归并开始实现算法.这显然不起作用.我吮吸递归.很多.
//Instance Fields
public List<ArrayList<String>> options;
//Method that will generate the options. The different options are
//stored in a list of "option". An individual option will store a list of
//strings with the individual groups.
public void generateOptions(int items, ArrayList<String> currentOption){
//If the current option is null, then create a new option.
if(currentOption == null){
currentOption = new ArrayList<String>();
}
if(items < 3){
//If the number …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用公共密钥加入ruby中的多个哈希数组.例如:
country_info = [
{country_id: "US", country_desc: "United States"},
{country_id: "AU", country_desc: "Australia"}
]
country_stats = [
{country_id:"US", pageviews: 150},
{country_id:"AU", pageviews: 200}
]
i_want = [
{country_id: "US", country_desc: "United States", pageviews:150},
{country_id: "AU", country_desc: "Australia", pageviews:200}
]
Run Code Online (Sandbox Code Playgroud)
这类似于Javascript中protovis的pv.nest功能.请参阅:http://protovis-js.googlecode.com/svn/trunk/jsdoc/symbols/pv.Nest.html
我怎么能在Ruby中做到这一点?