|
-
Apr 9th, 2008, 09:04 PM
#1
Thread Starter
pathfinder
Here's something to develop
Lets say you have a group of numbers, all distinct.
They are represented by an equation, lets say G = C1+C2+C3...+Cn
Such that G is a group of N integer elements such that there sum is mTargVal.
The N elements are distinct, ie... each one of them is not equal to any other of them.
Lets say that the smallest element in the group G = mCellLow,
and the largest element is mCellHigh.
For Example, lets say that N = 6
and mCellLow = 0
and mCellHigh = 18
and mTargVal = 16
- Determine a fucntion that tightens the limits...mCellLow and mCellHigh
- Determine a function that returns what values MUST BE USED in this range.
In the example that I gave to you, you will see that:
If 5 of the numbers are 0 1 2 3 4, {The smallest set of N-1 numbers available} that the maximal mCellHigh really could be is 6.
This is because if you add the N-1 lowest possible values together, you have created the most minimal sum that N-1 of those elements can add to.
Which, if you then subtract from the targvl, you see that the most maximal value of a c could be only 6.
So the real range that mCellLow and mCellHigh could be is 0 and 6.
Using this as an example, and any others that you can think of, I am certain you can acheive #1.
Now, Number 2 is a bit more complex, however, when all is said and done, it is a very simple function.
Try by hand the following example:
Using 5 distinct numbers, 3 <= Cn <= 18
and those 5 numbers add to 27
What numbers MUST be used?
{BTW, this examples solution has tightened the C Limits}
{I will provide more examples in the morning, but the answer to this is:
You Are Required to use numbers in the range : 3 <= C <= 9
3 Numbers Ascending {Inclusive} from 3 { 3 -> 5 }
To Add To 27
When you must use 5 Numbers GTE 3 and LTE 9
Once and only once
}
Last edited by NotLKH; Apr 9th, 2008 at 09:12 PM.
-
Apr 9th, 2008, 09:33 PM
#2
Re: Here's something to develop
Are you really asking for someone to develop this or just trying to show off your math?
As for point number 1, you can logically deduce that mCellLow must always be 0, which makes mCellHigh ridiculously easy to calculate.
Last edited by MaximilianMayrhofer; Apr 9th, 2008 at 09:40 PM.
-
Apr 11th, 2008, 07:50 PM
#3
Thread Starter
pathfinder
Re: Here's something to develop
No interest expressed.
Alright then.
Code:
Public Function DETERMINE_TARGVALS_CELL_MIN_MAX(ByRef mCellLow As Integer, ByRef mCellHigh As Integer, ByVal mTargVal As Integer, ByVal mBaseCellCount As Integer) As Boolean
Dim mBaseCellCount_m1 As Integer = mBaseCellCount - 1
Dim mBaseCellCount_m2 As Integer = mBaseCellCount - 2
Dim mBaseCellCount_PackedSum As Integer = (mBaseCellCount_m1 * mBaseCellCount_m2) / 2
Dim mTemp As Integer = mTargVal - mCellLow * mBaseCellCount_m1 - mBaseCellCount_PackedSum
If mCellHigh > mTemp Then
mCellHigh = mTemp
End If
mTemp = mTargVal - mCellHigh * mBaseCellCount_m1 + mBaseCellCount_PackedSum
If mCellLow < mTemp Then
mCellLow = mTemp
End If
If mCellLow > mCellHigh Then
Return False
End If
Return True
End Function
Public Function DETERMINE_MUST_USE_RANGES(ByRef mCellLow As Integer, ByRef mCellHigh As Integer, ByVal mTargVal As Integer, ByVal mBaseCellCount As Integer, _
ByRef mMustUseLowCount As Integer, ByRef mMustUseHighCount As Integer, ByRef mFreeCells As Integer) As Boolean
Dim mAdjustedTargVal As Integer = mTargVal - mBaseCellCount * mCellLow
Dim mAdjustedLowCell As Integer = 0
Dim mAdjustedHighCell As Integer = mCellHigh - mCellLow
Dim mAbsoluteMinVal As Integer = (mBaseCellCount * (mBaseCellCount - 1)) / 2
Dim mAbsoluteMaxVal As Integer = mBaseCellCount * mAdjustedHighCell - mAbsoluteMinVal
Dim mLowDifference As Integer = madjustedTargVal - mAbsoluteMinVal
Dim mHighDifference As Integer = mAbsoluteMaxVal - mAdjustedTargVal
mMustUseLowCount = mBaseCellCount - mLowDifference
mMustUseHighCount = mBaseCellCount - mHighDifference
If mMustUseLowCount < 0 Then
mMustUseLowCount = 0
End If
If mMustUseHighCount < 0 Then
mMustUseHighCount = 0
End If
'mFreeCells = mBaseCellCount - mMustUseLowCount - mMustUseHighCount
'If mFreeCells < 0 Then
' mFreeCells = 0
'End If
'error conditions?
If mMustUseLowCount > mBaseCellCount Then
Return False
End If
If mMustUseHighCount > mBaseCellCount Then
Return False
End If
'IS there any way that, if either of the MustUseCounts equals mbasecellcount, the other doesn't?
Return True
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|