Lotto Playset Coverage Calculation Speed in VBA, VB6, VB 2008, C# and C++

175 views
Skip to first unread message

colin.fa...@gmail.com

unread,
May 15, 2009, 12:12:08 AM5/15/09
to lotto
This topic was first started by me in an unmoderated usenet group
http://groups.google.com/group/rec.gambling.lottery/browse_thread/thread/396c92e7bf9a0242#
and continued in another topic
http://groups.google.com/group/rec.gambling.lottery/browse_thread/thread/0c60afe7b167d2d2#.
The topic is a serious one that deserves more prominence than that
usenet group can provide with its proliferation of spurious posts.

Here is the wording of the original challenge:
"The basic test is to calculate the coverage of say 44 45 46 47 48 49
by iterating through all the 13,983,816 possiblities and counting a
match Three. The combination should then be flagged as covered in an
array or whatever so it will not be counted for the next combination
to calculate. The algorithm you use should give an accurate count
whatever the combination entered ie 260624."

Happy coding
Colin Fairbrother
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

colin.fa...@gmail.com

unread,
May 18, 2009, 8:51:06 AM5/18/09
to lotto
On May 17th Michael Harrington published what is pretty well the final
version of the Coverage Calculation code after some mentoring by John
Rawson. The objective of an under 1 second calculation time was
achieved for not only 1 line but also 163.

Here are the times for the various languages as tested for a 1.8 GHz
processor (except C++ where a calculation is made from John Rawson's
accepted time of 0.2 sec on a 3 GHz processor and the assumption is
made that the code for this task is pretty similar) : -

1,8 GHz 3.0 GHz
Processor Processor

VBA 3.00 sec 1.65 sec
(Access or Excel)

C# 0.45 sec 0.25 sec

VB 2008 0.42 sec 0.25 sec

C++ 0.36 sec 0.20 sec

Congratulations to Michael Harrington. I for one will find some of the
tricks and techniques used to be useful in speeding up some internal
programs I use.

Colin Fairbrother
www.lottotowin.com

Draco Merest

unread,
Jun 20, 2009, 1:33:27 PM6/20/09
to lotto
Hello Colin, thanks for the invite.

When a new idea is presented or a challenge set, I usually try for
something totally different in the most difficult of manner. If
successful I have something which can be optimized a thousand fold in
VB6 or a combination VB6 and Assembly.

So too with this challenge, I thought for hours on a different
approach and began coding in Javascript.

The initial idea was to simplify the entire process and deduce some
results based on mathematical calculation alone – trying to suggest
that there are 20 subsets of 3 in every set of 6 and since there are
18,424 sets of three from for 6 numbers from 49, any given set of 6
listed as a cover would help eliminate x amount of the total
13,983,816. But it just would not fit together.

But I had progressed 90% of the way to a solution without knowing it.
In essence, the logic resembles the following:

List all 20 combinations of 3 from each set in a given list.
Map all of these onto an array of 18,242 elements.
Extract all 20 subsets of 3 from all 6/49 sets.
Search the mapped array for an instance of any subsets and count one
cover if found.

Sounds simple enough. But I found myself going in circles trying to
implement this in Javascript. I could see so many different methods to
use simply in VB6 and a straight forward approach in Assembly.

The resulting Javascript correctly counts all the covered 3 if 6 from
49 sets of that much talked about 163 set ‘world best’ wheel.

Trials:

3.00ghz Intel Win XP

FireFox: 411 seconds (6 min 51 secs)
IE 7: 1536 seconds (25 min 36 secs)

The usefulness of this is absolutely zero except to show off that I
used Javascript in the most complicated manner possible and still have
a semi-respectable processing time. It is available online at
http://www.iinet.net.au/~htjs/lottery/triplecover.htm

Draco Merest.
Reply all
Reply to author
Forward
0 new messages