【问题标题】:Find all combinations 6 numbers using only 0,1 and 2仅使用 0,1 和 2 查找所有组合 6 个数字
【发布时间】:2014-10-21 12:18:34
【问题描述】:

有没有一种简单的方法可以仅使用 0、1 和 2 找到所有 6 位数字的组合?

所以它以000000 开始并以222222 结束

我在网上查过,但我能找到的只是找到有多少的公式,但我需要一份所有这些的列表

如果有 R 中的代码会更好

这不是完全必要的,但如果有办法创建一个列表,其中 1st and 4th digit sum to a maximum of 22nd and 5th digit sum to a maximum of 23rd and 6th digit sum to a maximum of 2

谢谢

【问题讨论】:

标签: r combinations


【解决方案1】:

你可以这样做:

do.call(paste0, expand.grid(rep(list(0:2), 6)))

在其中添加rev 会给出不同的顺序,可能感觉更自然:

do.call(paste0, rev(expand.grid(rep(list(0:2), 6))))

我只会提示您的新(添加)问题,因为我现在担心我可能正在做您的作业。 expand.grid 返回一个 data.frame。只需稍加处理,您就可以提取出只对您重要的行的subset

【讨论】:

  • 哈哈这不是家庭作业,它是我工作的一部分,而且我对 r 还不是很好。但是还是谢谢你:)
猜你喜欢
  • 2015-09-20
  • 1970-01-01
  • 1970-01-01
  • 2023-04-06
  • 1970-01-01
  • 1970-01-01
  • 2011-07-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多