A
Ali
1+3+5+7+9+11+13+15+17+19=100
Choose 5 numbers from these 10 figures so there sum is = 50
Choose 5 numbers from these 10 figures so there sum is = 50
Ali said:1+3+5+7+9+11+13+15+17+19=100
Choose 5 numbers from these 10 figures so there sum is = 50
The sum of 5 Odd numbers is Odd also, so I don't
believe there is a solution as stated that equals
an even number (ie 50)
That looks like 6 numbers to me.<g>
See Dana's post as to why the problem as asked can't be solved.
joeu2004 said:Why use well-founded reasoning when brute force will do the trick?
Just kidding. But the following might be a useful paradigm for
solving such problems when the answer is not so obvious.
Sub doit()
x = Array(1, 3, 5, 7, 9, 11, 13, 15, 17, 19)
For i1 = 0 To UBound(x) - 4
For i2 = i1 + 1 To UBound(x) - 3
For i3 = i2 + 1 To UBound(x) - 2
For i4 = i3 + 1 To UBound(x) - 1
For i5 = i4 + 1 To UBound(x)
Sum = x(i1) + x(i2) + x(i3) + x(i4) + x(i5)
If Sum = 50 Then Debug.Print Sum; x(i1); x(i2); x(i3); x(i4); x(i5)
Next i5: Next i4: Next i3: Next i2: Next i1
End Sub
PS: Lots of solutions when choosing 6. I wonder if the OP simply
mistyped.
Public Function doit(Test As Long) As Long
On Error GoTo ErrBreak
Dim x(41) As Long
Dim i1 As Long
Dim i2 As Long
Dim i3 As Long
Dim i4 As Long
Dim i5 As Long
Dim Sum As Long
Dim R As Long
' set up Fibonacci sequence
x(0) = 0
x(1) = 1
For i1 = 2 To 41
x(i1) = x(i1 - 2) + x(i1 - 1)
Next i1
For i1 = 0 To UBound(x) - 4
For i2 = i1 + 1 To UBound(x) - 3
For i3 = i2 + 1 To UBound(x) - 2
For i4 = i3 + 1 To UBound(x) - 1
For i5 = i4 + 1 To UBound(x)
Sum = x(i1) + x(i2) + x(i3) + x(i4) + x(i5)
If Sum = Test Then
R = R + 1
End If
Next i5: Next i4: Next i3: Next i2:
Debug.Print Test & "." & i1
Next i1
doit = R
Exit Function
ErrBreak: Stop
Resume Next
End Function
'
1+3+5+7+9+11+13+15+17+19=100
Choose 5 numbers from these 10 figures so there sum is = 50
On Saturday, November 22, 2008 3:51 AM Mike Middleton wrote:
Ali -
Tushar Mehta describes two methods with references to others:
http://www.tushar-mehta.com/excel/templates/match_values/index.html
- Mike Middleton
http://www.DecisionToolworks.com
Decision Analysis Add-ins for Excel
news:[email protected]...How cool!
Has anyone noticed that plotting x = Sum v. y = count of combinations
making Sum resembles a normal distribution? (Is it?)
Ok, perhaps that is not so fascinating, but try this:
Make x() an array of Fibonacci numbers and try the plot again. A
fractal-like pattern emerges. Evaluate the following for Test in
(0..4000) to appreciate.
'Code:Public Function doit(Test As Long) As Long On Error GoTo ErrBreak Dim x(41) As Long Dim i1 As Long Dim i2 As Long Dim i3 As Long Dim i4 As Long Dim i5 As Long Dim Sum As Long Dim R As Long ' set up Fibonacci sequence x(0) = 0 x(1) = 1 For i1 = 2 To 41 x(i1) = x(i1 - 2) + x(i1 - 1) Next i1 For i1 = 0 To UBound(x) - 4 For i2 = i1 + 1 To UBound(x) - 3 For i3 = i2 + 1 To UBound(x) - 2 For i4 = i3 + 1 To UBound(x) - 1 For i5 = i4 + 1 To UBound(x) Sum = x(i1) + x(i2) + x(i3) + x(i4) + x(i5) If Sum = Test Then R = R + 1 End If Next i5: Next i4: Next i3: Next i2: Debug.Print Test & "." & i1 Next i1 doit = R Exit Function ErrBreak: Stop Resume Next End Function '
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.