<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/">
	<channel>
		<title>Combination Index, VB</title>
		<link>https://blogs.lotterypost.com/jadelottery/2009/2/combination-index-vb.htm</link>
		<atom:link href="https://www.lotterypost.com/rss/blogcomments/27683" rel="self" type="application/rss+xml" />
		<description>JADELottery's Blog: Combination Index, VB</description>
		<dc:language>en-us</dc:language>
		<generator>Lottery Post RSS Generator</generator>
		<item>
			<title>Original Blog Entry: Combination Index, VB</title>
			<link>https://blogs.lotterypost.com/jadelottery/2009/2/combination-index-vb.htm</link>
			<guid isPermaLink="true">https://blogs.lotterypost.com/jadelottery/2009/2/combination-index-vb.htm</guid>
			<pubDate>Sun, 22 Feb 2009 17:58:25 GMT</pubDate>
			<dc:creator>JADELottery</dc:creator>
			<description><![CDATA[<p>Back on 2003-10-04 I posted a reply that helped find an Index position within a list of ascending order combinations.<br /><br />As an example in a Pick 6 of 49 Numbers lottery, the first (Index of 1) combination would be (1, 2, 3, 4, 5, 6) and the last (Index of 13,983,816) combination would be (44, 45, 46, 47, 48, 49).<br /><br />The original reply is linked here - Lottery Combo Question.<br /><br />We ve reworked this a little bit, but would like to post the original here for reference.<br /><br />Also, now that we have learned C/C++, we have converted it to that language.<br /><br />Here&#x27;s the Visual Basic algorithm I&#x27;ve come up with for finding the combinatorial index of a combination for N items taken R at a time.<br /><br />Those of you who know VB, know what to do.<br /><br />Those of you who know another programming language and VB should know what to do.<br /><br />Global Counter(1 To R) As Integer<br /><br />&#x27;R must be assigned some value before program run.<br /><br />&#x27;The program can handle anything R or less when when assigned.<br /><br />&#x27;note: This global array must be put in the declarations part of the function module or some other module.<br /><br />Function Fact(N) As Double<br /><br />&#x27;The factorial function, Fact(N)= N!<br /><br />&#x27;This is a recursive calling function, means it calls itself multiple times.<br /><br />&#x27;If your BASIC language dose not support recursive calling, then this function needs to be changed to meet the function of:<br /><br />&#x27;N! = N * (N - 1) * (N - 2) * (N - 3) * ... * 3 * 2 * 1, where 0! = 1 and N 0 is undefined.<br /><br />If (N 1) Then<br /><br />Fact = 1<br /><br />Else<br /><br />Fact = N * Fact(N - 1)<br /><br />End If<br /><br />End Function<br /><br />Function Perm(N, R) As Double<br /><br />&#x27;This is the permutational function of N items taken R at a time.<br /><br />If (N R) Then<br /><br />Perm = 0<br /><br />Else<br /><br />Perm = Fact(N) / Fact(N - R)<br /><br />End If<br /><br />End Function<br /><br />Function Comb(N, R) As Double<br /><br />&#x27;This is the combinatorial function of N items taken R at a time.<br /><br />If (N R) Then<br /><br />Comb = 0<br /><br />Else<br /><br />Comb = Perm(N, R) / Fact(R)<br /><br />End If<br /><br />End Function<br /><br />Function Cdist(N, R, C, Z) As Double<br /><br />&#x27;This is the column distribution function of N items taken R at a time in column C for item Z.<br /><br />If (Z C) Or (Z (N - R + C)) Or (Z N) Or (C R) Or (N 1) Or (R 1) Or (C 1) Or (Z 1) Then<br /><br />Cdist = 0<br /><br />Else<br /><br />Cdist = Comb(Z - 1, C - 1) * Comb(N - Z, R - C)<br /><br />End If<br /><br />End Function<br /><br />Function fColumnSum(N, R, Z) As Double<br /><br />&#x27;This function performs a column count for N items taken R at a time for item Z.<br /><br />If Z 1 Then<br /><br />fColumnSum = 0<br /><br />ElseIf (Z = 1) And (Z N - R + 1) Then<br /><br />col_sum = 0<br /><br />For a = 1 To Z<br /><br />col_sum = col_sum + Cdist(N, R, 1, a)<br /><br />Next a<br /><br />fColumnSum = col_sum<br /><br />ElseIf Z = N - R + 1 Then<br /><br />fColumnSum = Comb(N, R)<br /><br />End If<br /><br />End Function<br /><br />Function Comb_Count(N, R) As Double<br /><br />&#x27;This is the combinatorial index for a combination in N items taken R at a time and R must not be larger than the Counter() array size R.<br /><br />&#x27;Counter() is an array containing the combination.<br /><br />&#x27;The Counter() array must be globally dimensioned outside the function and must be the size of R.<br /><br />&#x27;Also, numbers (item index) must be assigned in ascending order; Counter(1)is the minimum number through Counter(R) is the maximum number.<br /><br />fsum = fColumnSum(N, R, Counter(1) - 1) + 1<br /><br />For a = 2 To R<br /><br />fsum = fsum + fColumnSum(N - Counter(a - 1), R - a + 1, Counter(a) - Counter(a - 1) - 1)<br /><br />Next a<br /><br />Comb_Count = fsum<br /><br />End Function<br /><br />After putting the functions in the appropriate module and putting the Counter array in the declarations section of the main program module, all that needs to be done is assign the combination to the Counter array and call the Comb_Count function.<br /><br />It would look something like this: (i.e. for a 6/49 lottery with a combination of (06, 10, 17, 37, 40, 49))<br /><br />Sub Some_subroutine_of_the_main_program()<br /><br />Counter(1) = 6<br /><br />Counter(2) = 10<br /><br />Counter(3) = 17<br /><br />Counter(4) = 37<br /><br />Counter(5) = 40<br /><br />Counter(6) = 49<br /><br />CombinIndex = Comb_Count(49, 6)<br /><br />&#x27;CombinIndex now contains the combinatorial index of that combination.<br /><br />End Sub<br /><br />The combinatorial index of (06, 10, 17, 37, 40, 49) in 49 numbers taken 6 at a time is 7,275,389.<br /><br />How you want to assign the combination values is up to you.<br /><br />The way I shown here is just an example.<br /><br />Also, this only works with single combinations like a 6/49 or 5/35.<br /><br />Powerball or Mega Millions are not single combos.<br /><br />They are a multiple combos, a pick 5 part and a pick 1 part.<br /><br />This algorithm only works on the pick 5 part or the pick 1 part.<br /><br />You may need to text format some of the code here, however, it will work.<br /><br />... &#x5b;&#xa0;<a href="https://blogs.lotterypost.com/jadelottery/2009/2/combination-index-vb.htm">More</a>&#xa0;&#x5d;</p>]]></description>
			<category>Blog Entry</category>
			<category>JADELottery</category>
			<wfw:comment>https://www.lotterypost.com/blogentry/27683</wfw:comment>
		</item>
	</channel>
</rss>

