Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Combination Determination?

Hi, I was wondering if anyone had written, or can think of an easy
algorithm which can determine what combinations of units will fall in a
certain range. For instance, if I gave it sections of flooring that were 1m,
2.5m, 4m, and asked for all combinations which would fall between 4.5m & 5m,
it would return an array with 5x1m,1x2.5m + 2x1m, 1x4m + 1x1m.
Thanks, Jeff


  #2   Report Post  
Posted to microsoft.public.excel.programming
jb jb is offline
external usenet poster
 
Posts: 15
Default Combination Determination?

Jeffrey

Interesting problem. Here's a formula that uses an iterative algorithm to determine the combinations. It's seems efficient but perhaps could still be improved on. The coding isn't really best practice, and should at least have some validation of arguments and some comments. Also, the string it produces will show '1+1+1+1+1' rather than '5x1' - it could be changed with a little more effort

JB

Public Function UnitCombo(ByRef sgMin As Single,
ByRef sgMax As Single,
ByRef varUnits As Variant,
ByRef stCombos As String,
Optional ByRef stCurrentCombo As String,
Optional ByVal iCurrentPlace As Integer) As Strin

Dim i As Intege
Dim sgUnit As Singl

For i = iCurrentPlace To UBound(varUnits
sgUnit = varUnits(i
If sgUnit < sgMin The
Call UnitCombo(sgMin - sgUnit, sgMax - sgUnit, varUnits, stCombos, stCurrentCombo & sgUnit & "+", i
ElseIf sgUnit <= sgMax The
If stCombos = "" The
stCombos = stCurrentCombo & sgUni
Els
stCombos = stCombos & "," & stCurrentCombo & sgUni
End I
Call UnitCombo(sgMin - sgUnit, sgMax - sgUnit, varUnits, stCombos, stCurrentCombo & sgUnit & "+", i
End I
Next

End Functio

Sub Test(

Dim stCombos As Strin

Call UnitCombo(4.5, 5, Array(1, 2.5, 4), stCombos

'the list of possible units can be as long as you like but must be passed as
'0-based, 1-Dimensional Variant Array, so 'Array(a,b,c,d,e,...)' works well

'stCombos is passed ByRef & it's value is changed by the Function to return the result
'In this example, stCombos = "1+1+1+1+1,1+1+2.5,1+4,2.5+2.5" afte
'the function has been called
Sto

End Su



----- Jeffrey Marcellus wrote: ----

Hi, I was wondering if anyone had written, or can think of an eas
algorithm which can determine what combinations of units will fall in
certain range. For instance, if I gave it sections of flooring that were 1m
2.5m, 4m, and asked for all combinations which would fall between 4.5m & 5m
it would return an array with 5x1m,1x2.5m + 2x1m, 1x4m + 1x1m
Thanks, Jef



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
coefficient of determination Jene Excel Worksheet Functions 2 August 27th 09 02:39 AM
Date determination and sums UnderCoverGuy Excel Worksheet Functions 0 October 31st 06 08:16 PM
Earned Value Determination Paul Excel Discussion (Misc queries) 0 March 25th 05 09:27 AM
Average determination Debra Excel Worksheet Functions 4 November 1st 04 01:22 PM
excluding a value in a max determination Dr. Schwartz[_3_] Excel Programming 3 February 5th 04 10:17 AM


All times are GMT +1. The time now is 09:48 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"