在列表中查找总和 [英] Find sum in a list

查看:83
本文介绍了在列表中查找总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在excel中使用VB,并且我在A列中有一个数字列表,我正在尝试查找哪些数字匹配来计算另一个数字的总和。数字列表非常冗长,可能有多个组合。


Ex。


List = 1 2 3 4 5 6

Sum = 10

输出= 1,2,3,4和1,3,6和1,4,5和2,3,5和4,6


任何想法?

I am using VB in excel and I have a list of numbers in column A and I am trying to find which numbers match up to make a sum of another number. The list of numbers is quite lengthy, and there may be more then one combination.

Ex.

List = 1 2 3 4 5 6
Sum = 10
output = 1,2,3,4 and 1,3,6 and 1,4,5 and 2,3,5 and 4,6

Any ideas?

推荐答案


我在excel中使用VB,我在A列中有一个数字列表,我试图找到哪些数字匹配得到另一个数字的总和。数字列表非常冗长,可能有多个组合。


Ex。


List = 1 2 3 4 5 6

Sum = 10

输出= 1,2,3,4和1,3,6和1,4,5和2,3,5和4,6


有什么想法吗?
I am using VB in excel and I have a list of numbers in column A and I am trying to find which numbers match up to make a sum of another number. The list of numbers is quite lengthy, and there may be more then one combination.

Ex.

List = 1 2 3 4 5 6
Sum = 10
output = 1,2,3,4 and 1,3,6 and 1,4,5 and 2,3,5 and 4,6

Any ideas?



它不像你想象的那么容易。一个不太难的方法(但不是非常有效)将创建所有posibles组合:2 ^ n,并检查满足总和的那些。

我将制作2 ^的矩阵nx 2,对于每个组合,我们将得到组合及其总和,然后如果它与您的数字匹配则按总和检查总和。

例如

列表: 1,2,3

sum = 3

矩阵将是2 ^ 3 = 8 x 2(实际上是7x2,因为我们不会考虑空的)

矩阵看起来像他的:

Its not as easy as you think. A not very hard way (but not very efficient) will be creating all the posibles combinations: 2^n, and check the ones that satisfy the sum.
i''d make a matrix of 2^n x 2, where for each combination, we''ll have the combination and its sum, then check sum by sum if it matches with your number.
e.g.
list: 1, 2, 3
sum = 3

the matrix will be of 2^3 = 8 x 2 (actually 7x2, because we''ll not consider the empty one)
the matrix will look like his:

展开 | 选择 | Wrap | Line Numbe rs


这是一个非常有趣的问题,我觉得应该针对任何数学家。这不是一个特定于VB的问题,而是一个导出算法来处理这种情况的问题。鉴于算法,我们可以轻松(可能)转换为VB。


Kadghar,我认为如果有的话,你已经低估了可能组合的数量。



编辑:我已经在软件开发论坛上发帖,要求有兴趣的人在这里查看。
It''s a very interesting problem, and one which I feel should be directed toward any mathematicians present. It''s really not a VB-specific question, but one of deriving an algorithm to handle the situation. Given the algorithm we can easily (probably) translate to VB.

Kadghar, I think that if anything, you''ve underestimated the number of possible combinations.


I''ve dropped a post into the Software Development forum asking anyone interested to have a look here.



...

Kadghar,我想如果有的话,你已经低估了可能组合的数量。

...
...
Kadghar, I think that if anything, you''ve underestimated the number of possible combinations.
...



听起来像是对我的挑战!!

^。^


好​​吧,因为它已经晚了晚上,我不会制作最好的算法,但如果列表少于170个数字(因为双重不允许任何因子超过170,并且我使用组合),这个将工作


这是为Excel的VBA制作的,它将从A列读取列表(不应该有空格)并从单元格B1中读取总和。


如果重复列表的任何值,它将无法工作,并且它不会显示明显的解决方案(即不会显示只有一个数字的解决方案,只有2个或更多成员的组合列表)

Sounds like a challenge to me!!
^.^

Well, since its late at night, i wont make the best algorithm, but this one will work if the list has less than 170 numbers (because a double wont allow any factorial over 170, and im using combinations)

This is made for Excel''s VBA, it''ll read the list from column A (there shouldnt be blank spaces) and reads the sum from cell B1.

It wont work if any value of the list is repeated, and it wont show the obvious solution (i.e.it wont show the solutions of only one number, only combinations of 2 or more members of the list)

展开 | 选择 | Wrap | 行号


这篇关于在列表中查找总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆