This post continues the series on Generating Functions. The first installment was discussing the problem about changing dollar into coins. The second post was about degeneracy of energy levels in central field in quantum mechanics. The connection between previous and current problems is not too difficult to see yet the method of generating functions applied to counting “lucky numbers” has its own interesting twist.

# Generating Functions: Part 3. Lucky Tickets.

Here we discuss another elementary problem about counting, which can be solved with a clever choice of generating function.

## Lucky Tickets

Section 9 in [1] contains a series of problems on generating functions. The example 9.2 problem is worth discussion in connection to the previous post. It is related to so called “lucky tickets” in a roll of all tickets numbered with digits so for example their numbers are running from 000000 to 999999. Obviously, there are tickets in the roll.

**Definition.** Ticket in a -digits tickets roll is called *lucky* if the sum of first digits equals the sum of last digits.

**Problem 2.** Find number of lucky tickets in complete -digits roll for .

First step would be to find how many ways there are to have sum of first 3 digits equal . This can be achieved with the aid of generating function:

(1)

Its coefficients in the expansion

(2)

would give number of combinations we are interested for each possible sum value . However we are not interested in the individual values of but rather in the cases when two sums of digits are equal regardless of the particular value of the sum.

For that end, we consider different generating function for the last three digits:

(3)

which achieves the same as (1) except it does it with negative powers of . Now observe what happens in the product:

(4)

It is easy to see that only the terms with opposite powers of will contribute to the term in expansion

(5)

The key is that the terms corresponding to the opposite powers of are exactly corresponding to the number of ways we can get sum on either first or last three digits. Hence the solution to the problem 2 can be found by calculating in (2).

That can be achieved by applying formulas for binomial expansion

(6)

and:

(7)

which comes from general formula for negative exponents (see (2) in the previous post on generating functions).

From (6) and (7) we are interested in terms that have combined power 27, which would cancel with in denominator of (5). It is easy to find such combinations:

(8)

That gives probability of getting lucky ticket about 5.5%. A funny detail is that in Russia you are supposed to eat lucky ticket to make it bring luck to you

## References

[1] A.A.Sveshnikov “*Problems in Probability Theory, Mathematical Statistics and Theory of Random Functions*“, Dover, 1979, 481 pages.