View Full Version : Generate 3 sets combinations, which 3 sets sum match: to request target sum
motilulla
06-06-2016, 01:58 PM
Hello,
I am looking a unique VBA solution for 5/50 lotteries. Which can generate 3 sets combinations, which 3 sets sum match: to request target sum
For example if First 3 set of 5/50 summed together it gives total sum of 3 set = 48
For example if Last 3 set of 5/50 summed together it gives total sum of 3 set = 717
Conclusion minimum sum range is = 48 and maximum sum range = 717
My request is I need typical VBA that can generate request target sum from 48 to 717 in set of 3 combinations
Continuation I have attached the example of minimum & maximum sum
n1
n2
n3
n4
n5
Total Row Sum
Total Sum Of 3 Rows
1
2
3
4
5
15
1
2
3
4
6
16
1
2
3
4
7
17
48
44
47
48
49
50
238
45
47
48
49
50
239
46
47
48
49
50
240
717
Thanks In Advance
Using Excel 2000
Regards,
Moti
I don't think there are enough cells on the worksheet to hold all the values. (46^4?)(50^4?)
Sub MakeCombos()
Dim n1 As Single
Dim n2 As Single
Dim n3 As Single
Dim n4 As Single
Dim n5 As Single
Dim rw As Long
Dim Combos As Variant
ReDim Combos(1 To Rows.Count - 2, 1 To 5)
rw = 1
n1 = 1
Do While n1 <= 46
n2 = n1 + 1
Do While n2 <= 47
n3 = n2 + 1
Do While n3 <= 48
n4 = n3 + 1
Do While n4 <= 49
n5 = n4 + 1
Do While n5 <= 50
Combos(rw, 1) = n1
Combos(rw, 2) = n2
Combos(rw, 3) = n3
Combos(rw, 4) = n4
Combos(rw, 5) = n5
rw = rw + 1
If rw = UBound(Combos) Then GoTo ThatsAlltheRows
n5 = n5 + 1
Loop
n4 = n4 + 1
Loop
n3 = n3 + 1
Loop
n2 = n2 + 1
Loop
n1 = n1 + 1
Loop
msgbox "SamT was wrong. There are enough rows to handle all the values."
ThatsAlltheRows:
Sheets("Sheet1").Range("A2").Resize(UBound(Combos), 5) = Combos
End Sub
motilulla
06-07-2016, 03:53 AM
I don't think there are enough cells on the worksheet to hold all the values. (46^4?)(50^4?)
Thank you SamT, for the reply
I need to explain in detail to clarify my question what I am after.
I want each time VBA run generate only 3 set and sum of 3 set matches with input sum target.
For example I want VBA to generate 3 set, and sum of 3 sets I want to be = to 278 once VBA run it must generate 3 set which sums = 278 here are few example
Example1.
n1
n2
n3
n4
n5
Tota Sum Of 3 Rows
2
7
8
45
48
278
5
9
17
32
34
5
8
10
11
37
Example2.
n1
n2
n3
n4
n5
Tota Sum Of 3 Rows
7
15
16
17
45
278
3
18
25
34
41
1
9
12
17
18
Example3.
n1
n2
n3
n4
n5
Tota Sum Of 3 Rows
6
7
32
37
47
278
4
8
10
18
21
6
8
14
15
45
So it generate each time 3 set any the sum of 3 set must match with VBA input sum
Above example is given with sum = 278 but can be chosen among, minimum sum = 48 & maximum sum = 717
Hope I have made clear my question
Thank you
Regards,
Moti
Apparently there's a growing interest in designing lotteries to get more people addicted (with all the negative consequences involved).
Do we support those tendencies ?
I want each time VBA run generate only 3 set and sum of 3 set matches with input sum target.
That is beyond my skills.
There are ~50^4 possible combinations and I can't calculate how many of each set of three combinations sum to any given number. My best guess is that it peaks at about ~10^5 combinations that sum each value in the middle of the curve.
You want only 3 of those 100000 sets of three for only one arbitrary sum.
The Lottery Commission will only use the Sums that fall in the middle of the curve. They must keep the odds high.
motilulla
06-07-2016, 07:42 AM
That is beyond my skills.
Thank you very much SamT, I appreciate your efforts
There are ~50^4 possible combinations and I can't calculate how many of each set of three combinations sum to any given number. My best guess is that it peaks at about ~10^5 combinations that sum each value in the middle of the curve.
Really I also don’t know how to work out how many combinations could be generated by each sum through 48 to 717 i can see only with sum 48 = 1 and 1 with sum 717
You want only 3 of those 100000 sets of three for only one arbitrary sum.
I want one set of 3 because I think all cannot be possible
Thank you once again
Regards,
Moti
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.