How would you solve this?
情報
この質問は閉じられています。 編集または回答するには再度開いてください。
古いコメントを表示
Assuming you have a vector x=[16,18,23,24,39,40], create a function that when called at the command window, will display the count of random numbers(elements in vector X) needed to make a sum of 100. One should also display the combination of those random numbers.
Any help is highly appreciated.
-----------------------
The Dark Warrior
3 件のコメント
Matt Kindig
2013 年 5 月 8 日
編集済み: Matt Kindig
2013 年 5 月 8 日
Are you sure that there exists a set of elements in your x vector that sum to 100? I tried your problem and could not find one.
By the way, my method involves using perms() and cumsum()--maybe that will help you.
Dr. Seis
2013 年 5 月 8 日
I am wondering if by "count" we can use one of the numbers from the list more than once (e.g., 4*16 + 2*18 = 100).
回答 (1 件)
Matt J
2013 年 5 月 8 日
Here's the start of a method that will work for length(x) not too large,
N=length(x);
B=bsxfun(@times, x(:).', dec2bin(1:2^N-1,N)-'0');
map=(sum(B,2)==100),
0 件のコメント
この質問は閉じられています。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!