LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 394
Default Calculating Gaps Between Numbers

Hi everyone,

I am trying to create a "Gaps" program that cycles through ALL
13,983,816 combinations in a 6 from 49 Lotto and produces the
following data.
I would like it to work out the Gaps between each of the balls for
EACH combination in a 6 from 49 Lotto with no replacement.
For example, the combination 02 08 18 28 36 45 will have the Gaps
of ...

Ball 1 numbered 02 & Ball 2 numbered 08 = 05 Gaps ( 03 04
05 06 07 )
Ball 2 numbered 08 & Ball 3 numbered 18 = 09 Gaps ( 19 10
11 12 13 14 15 16 17 )
Ball 3 numbered 18 & Ball 4 numbered 28 = 08 Gaps ( 20 21
22 23 24 25 26 27 )
Ball 4 numbered 28 & Ball 5 numbered 36 = 07 Gaps ( 29 30
31 32 33 34 35 )
Ball 5 numbered 36 & Ball 6 numbered 45 = 08 Gaps ( 37 38
39 40 41 42 43 44 )

.... so the Gaps description for this particular combination will be 05
09 08 07 08.

The Gaps difference between ball 1 and ball 2 is really ball 2 minus
ball 1 - 1 and so on.
I would like to have a Gaps description for each category and the
Total combinations for each category associated with that list.
So extracting three combinations from the Loop as an example ...

Combination - 02 09 16 25 38 45
Combination - 04 15 19 36 37 49
Combination - 09 15 28 39 46 47

.... will give the answer ...

Gaps 06 06 08 12 06 = x combinations ( x could be 925,365 combinations
with the exact same Gaps between the balls 1-2, 2-3 ,3-4 ,4-5 & 5-6 )
Gaps 10 03 16 00 11 = x combinations ( x could be 236,258 combinations
with the exact same Gaps between the balls 1-2, 2-3, 3-4, 4-5 & 5-6 )
Gaps 05 12 10 06 00 = x combinations ( x could be 756,258 combinations
with the exact same Gaps between the balls 1-2, 2-3, 3-4, 4-5 & 5-6 )

.... etc.

It would also be nice to have a Total at the bottom of the
combinations list, which of course, should equal 13,983,816
combinations.

I have written the following which has nothing to do with what I am
trying to achieve above, but for some reason it does not work.
It is supposed to give me a list of Gaps from 00 to 43 from ALL
13,983,816 combinations.
The list of Gaps should be in cells B3:B45 and the total combinatios
for each gap should be in cells C3:C45.
Could somebody please have a glance at it.

Option Explicit
Option Base 1

Private Sub Gaps()

Dim A As Integer
Dim B As Integer
Dim C As Integer
Dim D As Integer
Dim E As Integer
Dim F As Integer
Dim i As Integer
Dim GapsTotal(43) As Long

Application.ScreenUpdating = False

For i = 1 To 43
GapsTotal(i) = 0
Next i

For A = 1 To 44
For B = A + 1 To 45
For C = B + 1 To 46
For D = C + 1 To 47
For E = D + 1 To 48
For F = E + 1 To 49

If B - A - 1 = 0 Then GapsTotal(0) = GapsTotal(0) + 1
If C - B - 1 = 0 Then GapsTotal(0) = GapsTotal(0) + 1
If D - C - 1 = 0 Then GapsTotal(0) = GapsTotal(0) + 1
If E - D - 1 = 0 Then GapsTotal(0) = GapsTotal(0) + 1
If F - E - 1 = 0 Then GapsTotal(0) = GapsTotal(0) + 1

If B - A - 1 = 1 Then GapsTotal(1) = GapsTotal(1) + 1
If C - B - 1 = 1 Then GapsTotal(1) = GapsTotal(1) + 1
If D - C - 1 = 1 Then GapsTotal(1) = GapsTotal(1) + 1
If E - D - 1 = 1 Then GapsTotal(1) = GapsTotal(1) + 1
If F - E - 1 = 1 Then GapsTotal(1) = GapsTotal(1) + 1

.... continued all the way down to ...

If B - A - 1 = 42 Then GapsTotal(42) = GapsTotal(42) + 1
If C - B - 1 = 42 Then GapsTotal(42) = GapsTotal(42) + 1
If D - C - 1 = 42 Then GapsTotal(42) = GapsTotal(42) + 1
If E - D - 1 = 42 Then GapsTotal(42) = GapsTotal(42) + 1
If F - E - 1 = 42 Then GapsTotal(42) = GapsTotal(42) + 1

If B - A - 1 = 43 Then GapsTotal(43) = GapsTotal(43) + 1
If C - B - 1 = 43 Then GapsTotal(43) = GapsTotal(43) + 1
If D - C - 1 = 43 Then GapsTotal(43) = GapsTotal(43) + 1
If E - D - 1 = 43 Then GapsTotal(43) = GapsTotal(43) + 1
If F - E - 1 = 43 Then GapsTotal(43) = GapsTotal(43) + 1

Next F
Next E
Next D
Next C
Next B
Next A

Sheets("Gaps Data").Select

Range("B2").Value = "Gaps"
Range("B3").Value = "Gaps of 00"
Range("B4").Value = "Gaps of 01"

.... continued all the way down to ...

Range("B44").Value = "Gaps of 42"
Range("B45").Value = "Gaps of 43"

Range("C2").Value = "Total"
Range("C3").Select

For i = 1 To 43
ActiveCell.Offset(i, 0).Value = GapsTotal(i)
Next i

Application.ScreenUpdating = True
End Sub

Any help will be greatly appreciated.
Thanks in Advance.
All the Best.
Paul

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Possible to auto-fill in gaps between numbers on straight line bas sticky Excel Worksheet Functions 1 January 30th 09 05:52 AM
Transpose Column With Gaps to Column With no gaps Vincent Excel Discussion (Misc queries) 9 October 1st 07 01:50 PM
VBA: Calculating Complex Numbers LenS Excel Discussion (Misc queries) 0 January 8th 07 05:24 PM
serial numbers how to find gaps DoronT New Users to Excel 5 November 2nd 06 04:29 AM
Transpose Column With Gaps to Row With No Gaps? SteveC Excel Discussion (Misc queries) 5 June 18th 05 01:01 AM


All times are GMT +1. The time now is 05:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"