Consulting

Results 1 to 6 of 6

Thread: Generate 3 sets combinations, which 3 sets sum match: to request target sum

  1. #1

    Generate 3 sets combinations, which 3 sets sum match: to request target sum

    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

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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
    Last edited by SamT; 06-06-2016 at 09:55 PM.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    Quote Originally Posted by SamT View Post
    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

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    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 ?
    Last edited by snb; 06-07-2016 at 07:21 AM.

  5. #5
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  6. #6
    Quote Originally Posted by SamT View Post
    That is beyond my skills.
    Thank you very much SamT, I appreciate your efforts

    Quote Originally Posted by SamT View Post
    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

    Quote Originally Posted by SamT View Post
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •