Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array Question

Status
Not open for further replies.

kiddjr

Programmer
Sep 17, 2004
5
US
I have a project I am working on where I am measuring the width of 25 wooden boards and loading them into an array. Now what needs to be done at this point is lets say I need to pick out of the array the boards whose measurements would make a panel 18 inches wide.

I've got some ideas where I would take an average of the boards in the array then sum all the boards in the array. At that point calculate the difference between the sum and the 18 inches. Then take the difference divide it by the average and throw the result(boards) out of the array. Re-sum the array and see if it is at 18.

I was wondering if anyone had a better way to do this or if C++ Builder might have something that I don't know about to help me out.

Thanks,
kiddjr
 
That sounds like the type of algorithm that probably has a slick solution published somewhere like in "Numerical Recipes".

The simplest solution of course is the brute-force approach, cycling through every combination of widths, keeping a record of the previous best combination as you go, but that's also the slowest.

C++ Builder offers nothing more than the standard C++ libraries, which are unlikely to be of much use here.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top