From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
10-01-2017 07:12 PM
I must create a program that generates 10 random numbers between 195 and 205, then add the 5 that together approach 1000 the closest. I already made a program that generates the numbers in an array, but I have no idea how to evaluate the numbers. Can anyone please help me?
Solved! Go to Solution.
10-01-2017 08:25 PM - edited 10-01-2017 08:29 PM
First, get rid of that local variable. It will get read before the indicator terminal receives data and the sum is thus meaningless. Just wire to the array coming from the FOR loop.
To pick five that that have a sum closest to 1000, you need quite a bit more code. The brute force method would be to generate all possible ways to pick five out of 10 and pick the combination with the closest sum (there might be duplicate solutions, of course).
(You also have a mathematical problem that the edge values in the selected range only have half the probability of the other values. Try to find a solution for that too)
10-01-2017 08:30 PM
@Yerry21 wrote:
I must create a program that generates 10 random numbers between 195 and 205, then add the 5 that together approach 1000 the closest. I already made a program that generates the numbers in an array, but I have no idea how to evaluate the numbers. Can anyone please help me?
Well, I can't open your VI because I don't have a (working) PC with LabVIEW 2017 installed (I had two with LabVIEW 2017 installed, including this one, but they became "no-longer-working" and had to be rebuilt). So here are some things:
Bob Schor
10-01-2017 08:39 PM
@Bob_Schor wrote:
- Can you think of a quick way to answer the question "Which number is closest to 1000?"?
The question is which combination of 5 of the 10 numbers form a sum that is closest to 1000.
10-01-2017 08:53 PM
Hmm. I just saw the earlier response, and my understanding of the Problem may be flawed. I thought the task was to add together the five numbers that were closest to 1000, but (as I was hinting) this is so simple that it is probably the "wrong question", namely find the five numbers in the set whose sum was closest to 1000. That's an interesting (and much more challenging) problem.
Do you know about Permutations and Combinations? There are "10 Choose 5" or (by my back-of-the-envelope) 252 combinations to check. But the number doesn't really matter. What you need to do is something like this:
Bob Schor