基于 2 个变量的组合
我想要完成的是为以下内容创建一个函数:
想象一下我有 1-9 个正方形。这些方块有一个全局编号,而不是单独编号。它们就像一个集合,而那个集合有这个数字。
例如:| _ | _ | _ | 19
我想做的是一个函数,它根据方块的数量和与它们相关的数字给出可能的组合。对于上面的示例:9、8、2 是可能的组合之一。然而,我只想要这些组合中的数字,而不是组合本身。另外,它们必须是唯一的(不应该是 9, 9, 1)。哦,这些数字范围仅为 1-9。
我怎样才能在C中实现这一点?如果您想知道这是一款益智游戏。
提前致谢!
What I'm trying to accomplish is making a function to the following:
Imagine that I have between 1-9 squares. Those squares have a number assigned to them globally, not individually. They are like a set, and that set has this number.
E.g.: | _ | _ | _ | 19
What I'm trying to do is a function that gives me the possible combinations depending on number of squares and the number associated with them. For the example above: 9, 8, 2 is one of the possible combinations. However I just want the numbers that are in those combinations, not the combinations themselves. Plus they have to be unique (shouldn't be 9, 9, 1). Oh and those numbers range from 1-9 only.
How can I achieve this in C? If you are wondering this is for a puzzle game.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来您正在尝试查找右侧整数的受限分区。该链接应该为您提供一个良好的起点,并且您应该能够找到一些将整数分区生成任意数量部分的算法。
Looks like you are trying to find a restricted Partition of the integer on the right. The link should give you a good starting place, and you should be able to find some algorithms that generate partitions of an integer into an arbitrary number of parts.
为了将来的参考,在组合学中,我们说“顺序无关紧要”,意思是“我只想要一组数字,而不是特定的顺序”
For future reference, in combinatorics we say "order doesn't matter" to mean "I only want the set of numbers, not a specific ordering"
听起来你正在做的事情与kakuro非常相似,也称为交叉求和:http:// en.wikipedia.org/wiki/Cross_Sums
有一些用于此类谜题的生成器,例如: http://www.perlmonks.org/?node_id=550884
我怀疑大多数 kakuro 生成器都必须解决您的确切问题,因此您可能会查看一些以获取灵感。
It sounds like what you're working on is very similar to kakuro, also know as Cross Sums: http://en.wikipedia.org/wiki/Cross_Sums
There are generators out there for these kinds of puzzles, for example: http://www.perlmonks.org/?node_id=550884
I suspect that most kakuro generators would have to solve your exact problem, so you might look at some for inspiration.