Introducing pyeuromillions

September 21, 2011

I have been working in a set of tools to play euromillions math way using combinations, high level filters and so on. As I written it in Python I called it pyeuromillions

You can find the code in github.

At this time the code there can do next things:
* Generate combinations with the numbers and stars provided
* Filter them with the registered filters
* It has a filter system flexible enough to be able to include more filters
* It has some examples filters such as evens, odds, tens, highs, lows.
* This is currently for developers only (no gui, etc.)

Next step is provide a check method that, given a combination and a winner, calculates how much money the combination would earn

Using itertools (2)

July 9, 2011

In the first article of this row I introduced to make combinations smartly using itertools. This time I’ll focus in filtering them. Again itertools is the key.

Let’s see it

for filter in self.filters:
            f = filter['function']
            args = filter['args']
            kwargs = filter['kwargs']
            valid_combs = itertools.ifilter(lambda x: f(x, *args, **kwargs), valid_combs)

In this code self.filters hold a list of dicts. This is part of the pluggable filtering system in pyeuromillions, but the key line is last. ifilter method return all items in seq that pass a test (in this case the lambda function). You can use ifilterfalse in a similar way but it’d return all items failing a test.

It performance really good. In less than 10 seconds it generates all combinations of 5 numbers between 1 and 50 having 3 even numbers in my actual computer (which is not a supercomputer).

Next time I spent some time writing pyeuromillions code I’ll focus in create a set of filtering functions.