S.H.A.D.O.
Well-known Member
- Joined
- Sep 6, 2005
- Messages
- 1,915
Good afternoon,
I have the following code which cycles through combinations and sums the totals for all the Odd & Even numbers within each combination. This runs and outputs the data into the WorkSheet. This work great.
What I am trying to do now is to work out the Root, and the assocciated sum totals.
By that I mean, if the Even sum was 68, then the 68 would become 14, i.e. 6+8=14, and the assocciated sum total. This will be the same for all the others.
Something along the lines if we used a formula of...
...where n is the sum total to be converted to the Root total.
I hope I have explained this clearly enough.
Adapting the above code should produce the following results.
Thanks in advance.
I have the following code which cycles through combinations and sums the totals for all the Odd & Even numbers within each combination. This runs and outputs the data into the WorkSheet. This work great.
Code:
Option Explicit
Option Base 1
Const Drawn As Long = 6
Const MaxF As Long = 19
Dim nEven() As Long
Dim nOdd() As Long
Dim m_recLvl As Long
Sub Odd_And_Even()
Dim vEven As Variant, vOdd As Variant
Dim i As Long
Dim CountEven As Long, CountOdd As Long
Dim lRow As Long
Dim MyDist As Variant
With Application
.ScreenUpdating = False: .Calculation = xlCalculationManual: .DisplayAlerts = False
End With
Columns("A:F").ClearContents
Cells(1, 1).Select
ReDim nEven(0 To Drawn * MaxF)
ReDim nOdd(0 To Drawn * MaxF)
doRecurse 1, 0, 0
With ActiveCell
ReDim vEven(1 To UBound(nEven), 1 To 2)
ReDim vOdd(1 To UBound(nOdd), 1 To 2)
For i = 0 To UBound(nEven)
If nEven(i) > 0 Then
CountEven = CountEven + 1
vEven(CountEven, 1) = i
vEven(CountEven, 2) = nEven(i)
End If
If nOdd(i) > 0 Then
CountOdd = CountOdd + 1
vOdd(CountOdd, 1) = i
vOdd(CountOdd, 2) = nOdd(i)
End If
Next i
lRow = ActiveCell.Row
MyDist = Array("Even Sum", "Total Combinations", "Odd Sum", "Total Combinations")
ActiveCell.Offset(0, 0).Resize(UBound(MyDist), 4) = MyDist
ActiveCell.Offset(1, 0).Resize(CountEven, 2) = vEven
ActiveCell.Offset(1, 2).Resize(CountOdd, 2) = vOdd
ActiveCell.Offset(CountEven + 1, 1).FormulaR1C1 = "=Sum(R" & lRow + 1 & "C:R[-1]C)"
ActiveCell.Offset(CountOdd + 1, 3).FormulaR1C1 = "=Sum(R" & lRow + 1 & "C:R[-1]C)"
End With
With Application
.DisplayAlerts = True: .Calculation = xlCalculationAutomatic: .ScreenUpdating = True
End With
End Sub
Function doRecurse(stInd As Long, EvenSum As Long, OddSum As Long)
Dim i As Long
Dim EvenAdd As Long, OddAdd As Long
m_recLvl = m_recLvl + 1
For i = stInd To MaxF - Drawn + m_recLvl
If m_recLvl < Drawn Then
If i Mod 2 = 0 Then
doRecurse i + 1, EvenSum + i, OddSum
Else
doRecurse i + 1, EvenSum, OddSum + i
End If
Else
If i Mod 2 = 0 Then
EvenAdd = i: OddAdd = 0
Else
OddAdd = i: EvenAdd = 0
End If
nEven(EvenSum + EvenAdd) = nEven(EvenSum + EvenAdd) + 1
nOdd(OddSum + OddAdd) = nOdd(OddSum + OddAdd) + 1
End If
Next i
m_recLvl = m_recLvl - 1
End Function
What I am trying to do now is to work out the Root, and the assocciated sum totals.
By that I mean, if the Even sum was 68, then the 68 would become 14, i.e. 6+8=14, and the assocciated sum total. This will be the same for all the others.
Something along the lines if we used a formula of...
Code:
=SUMPRODUCT(INT(n/10)+MOD(n,10))
...where n is the sum total to be converted to the Root total.
I hope I have explained this clearly enough.
Adapting the above code should produce the following results.
Code:
[TABLE="width: 312"]
<TBODY>[TR]
[TD]Even Root</SPAN>
[/TD]
[TD]Total</SPAN>
[/TD]
[TD]Odd Root</SPAN>
[/TD]
[TD]Total</SPAN>
[/TD]
[/TR]
[TR]
[TD="align: right"]0</SPAN>
[/TD]
[TD="align: right"]210</SPAN>
[/TD]
[TD="align: right"]0</SPAN>
[/TD]
[TD="align: right"]84</SPAN>
[/TD]
[/TR]
[TR]
[TD="align: right"]1</SPAN>
[/TD]
[TD="align: right"]672</SPAN>
[/TD]
[TD="align: right"]1</SPAN>
[/TD]
[TD="align: right"]378</SPAN>
[/TD]
[/TR]
[TR]
[TD="align: right"]2</SPAN>
[/TD]
[TD="align: right"]1617</SPAN>
[/TD]
[TD="align: right"]2</SPAN>
[/TD]
[TD="align: right"]912</SPAN>
[/TD]
[/TR]
[TR]
[TD="align: right"]3</SPAN>
[/TD]
[TD="align: right"]2452</SPAN>
[/TD]
[TD="align: right"]3</SPAN>
[/TD]
[TD="align: right"]1704</SPAN>
[/TD]
[/TR]
[TR]
[TD="align: right"]4</SPAN>
[/TD]
[TD="align: right"]2817</SPAN>
[/TD]
[TD="align: right"]4</SPAN>
[/TD]
[TD="align: right"]2549</SPAN>
[/TD]
[/TR]
[TR]
[TD="align: right"]5</SPAN>
[/TD]
[TD="align: right"]2936</SPAN>
[/TD]
[TD="align: right"]5</SPAN>
[/TD]
[TD="align: right"]2812</SPAN>
[/TD]
[/TR]
[TR]
[TD="align: right"]6</SPAN>
[/TD]
[TD="align: right"]3071</SPAN>
[/TD]
[TD="align: right"]6</SPAN>
[/TD]
[TD="align: right"]3006</SPAN>
[/TD]
[/TR]
[TR]
[TD="align: right"]7</SPAN>
[/TD]
[TD="align: right"]2951</SPAN>
[/TD]
[TD="align: right"]7</SPAN>
[/TD]
[TD="align: right"]2987</SPAN>
[/TD]
[/TR]
[TR]
[TD="align: right"]8</SPAN>
[/TD]
[TD="align: right"]2951</SPAN>
[/TD]
[TD="align: right"]8</SPAN>
[/TD]
[TD="align: right"]2951</SPAN>
[/TD]
[/TR]
[TR]
[TD="align: right"]9</SPAN>
[/TD]
[TD="align: right"]3072</SPAN>
[/TD]
[TD="align: right"]9</SPAN>
[/TD]
[TD="align: right"]3036</SPAN>
[/TD]
[/TR]
[TR]
[TD="align: right"]10</SPAN>
[/TD]
[TD="align: right"]2279</SPAN>
[/TD]
[TD="align: right"]10</SPAN>
[/TD]
[TD="align: right"]2735</SPAN>
[/TD]
[/TR]
[TR]
[TD="align: right"]11</SPAN>
[/TD]
[TD="align: right"]1334</SPAN>
[/TD]
[TD="align: right"]11</SPAN>
[/TD]
[TD="align: right"]2039</SPAN>
[/TD]
[/TR]
[TR]
[TD="align: right"]12</SPAN>
[/TD]
[TD="align: right"]620</SPAN>
[/TD]
[TD="align: right"]12</SPAN>
[/TD]
[TD="align: right"]1332</SPAN>
[/TD]
[/TR]
[TR]
[TD="align: right"]13</SPAN>
[/TD]
[TD="align: right"]134</SPAN>
[/TD]
[TD="align: right"]13</SPAN>
[/TD]
[TD="align: right"]438</SPAN>
[/TD]
[/TR]
[TR]
[TD="align: right"]14</SPAN>
[/TD]
[TD="align: right"]15</SPAN>
[/TD]
[TD="align: right"]14</SPAN>
[/TD]
[TD="align: right"]139</SPAN>
[/TD]
[/TR]
[TR]
[TD="align: right"]15</SPAN>
[/TD]
[TD="align: right"]1</SPAN>
[/TD]
[TD="align: right"]15</SPAN>
[/TD]
[TD="align: right"]30</SPAN>
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][B]27132[/B]</SPAN>
[/TD]
[TD][/TD]
[TD="align: right"][B]27132</SPAN>[/B]
[/TD]
[/TR]
</TBODY>[/TABLE]
Thanks in advance.