Print Page | Close Window

Coverage Calculation Speed in VBA, VB, C# and C++

Printed From: LottoPoster.com
Category: LOTTO PROBABILITY, COVERAGE AND PROGRAMMING
Forum Name: Calculating the Coverage of Combs by your Lotto Number Set
Forum Discription: Discuss here the methodology of Coverage which is the number of Combinations from all the possibilities containing a nominated subset from a play set.
URL: http://www.lottoposter.com/forum_posts.asp?TID=593
Printed Date: January 16 2018 at 9:06pm


Topic: Coverage Calculation Speed in VBA, VB, C# and C++
Posted By: Colin F
Subject: Coverage Calculation Speed in VBA, VB, C# and C++
Date Posted: May 03 2009 at 10:02pm
The objective is to achieve a sub 1 sec time in a visual environment to calculate the coverage of say 44 45 46 47 48 49 by testing all the 13,983,816 possiblities and establishing a count of match Threes in a Pool 49, Pick 6 Lotto game. The combinations would then be flagged as covered in an array or whatever so it would be bypasses for the next combination to calculate. The algorithm you use should give an accurate count whatever the combination entered ie 260624 for the first block. 
 
If iteration is not used then there must be a way of keeping track of what is covered for further block processing and counting the Coverage. The iteration algorithm I used to obtain these Coverage Calculation times is basically the same in all the four languages allowing for syntax differences and was supplied by Michael Harrington mentored by John Rawson in a thread I started called Coverage Calculation in VBA, VB, C# and C++ and can be viewed http://groups.google.com/group/rec.gambling.lottery/browse_thread/thread/396c92e7bf9a0242# - here . The initial times shown in the thread were based on older slower code than what I was currently using to attract more attention which it did; I had got it down to 70 sec in VBA and 7 sec in VB 2008 on a 1.8 GHz computer. Michael's times were impressively better at 6.5 sec and 0.44 sec respectively. 
 
From the code supplied at the message board you may want to add a couple of improvements for the first two loops, as I do, to opt out when it is greater than the max integer in the block. Obviously, this will not have any effect on our test block of 44 45 46 47 48 49.
 
I should mention that Michael's code simply counts the extent to which a subset Three in the Play Set is in the 13,983,816 possibilities. When you are generating sets and in my case making sure a Three is not repeated the code is not as simple nor as fast. 
 
Michael came up with a faster algorithm better than the 0.44 sec by breaking the 49c6 into 4 groups: -
  •  4c1 x 6c6   =          1    
  • 43c1 x 6c5   =        258
  • 43c2 x 6c4   =     13,545
  • 43c3 x 6c4   =    246,820
  •        Total      260,624

This is OK for calculating 1 block - the problem still remains to keep track of what is covered for calculation on multiple blocks as the flow through the lexicographic order has been lost - so, it is still a work in progress. Maybe combinadics can be used?

 The times below are adequate for my use using the iteration method.
 
What is your real processor speed? I downloaded this free program http://www.cpuspeedpro.com/download.php - CPUSpeedPro and had to adjust my speed from what I thought was 2.4 GHz as shown by XP to 1.8 GHz as tested. You can access tested speeds of current and old CPU's from around the world.
 
Coverage Calculation Times Compared for Different Languages

                          1.8 GHz             Est 3 GHz (x.6)

VBA                       6.52 sec               3.91 sec
(Access or Excel)

VB 2008                   0.44 sec               0.26 sec

 
C#                        0.64 sec               0.38 sec
 
C++                       4.00 sec               2.40 sec
without Boolean Vector  < 0.5 sec               < .5 sec
 
Why does C++ give such a relatively high time? If I remove the 13983816 Vector Boolean which is taking up a lot of contiguous memory it gives the fastest time. But how then does one keep track of what is covered? If you would like to give a time for the code in C++ go ahead - just let us know how fast your processor is and how large the RAM and how you are going to keep track of what is covered.
 
C# is managed memory and does not have to be contiguous for its arrays .
 
VB rules! You can get a free copy of Visual Basic Express here:
http://www.microsoft.com/Express/VB/ - http://www.microsoft.com/Express/VB/  
 
I use Visual Studio Standard which includes VB, C# and C++ with intellisense in the IDE. Study what you need and what you get before forking out for the considerably more expensive Professional edition.
 
nb If by the time you read this the thread at the newsgroup has gone stale you are welcome to make comments here. If you have not registered you can still comment in this forum as a guest.
 
Colin Fairbrother
 
ps
 


-------------
Lotto Draws have no relationship to one another; the integers serve just as identifiers. Any prediction calculation on one history of draws for a same type game is just as irrelevant as another.



Replies:
Posted By: thornc
Date Posted: August 11 2010 at 6:07pm
Here's an interesting article related to this ->  http://www.codeproject.com/KB/recipes/combinations_cpp_2.aspx - http://www.codeproject.com/KB/recipes/combinations_cpp_2.aspx .



-------------
Just me here!



Print Page | Close Window