Since I posed the problem in the first place, here’s my solution.

As a bit of background: after submitting the first draft of the quiz to

James, I made it an explicit requirement that numbers had to be placed

in a

column in increasing order downwards, e.g.

±—+ ±—+

| 85 | | 86 |

±—+ ±—+

| | is OK, but | | is not.

±—+ ±—+

| 86 | | 85 |

±—+ ±—+

A little thought shows that it’s always possible to transform a “bad”

solution like the RHS into a “good” solution like the LHS, just by

swapping

the values around, keeping any blanks in the same position.

This in turn led me to realise that the only thing which matters is the

position of blanks and non-blanks, and this can be represented in a

bitmap.

The attached solution enumerates all possible tickets grids up-front,

which

is remarkably quick when using a Fixnum to represent each bitmap.

Then, assembling together 6 grids to form a book is a case of picking 6

grids which have a total of 9 non-blanks across the first column, 10

non-blanks across the second…eighth columns, and 11 non-blanks across

the

last column. I couldn’t think of a deterministic way of doing this, so

it

just picks 5 grids at random and looks in an index to find if there is

any

6th grid which could be used to complete the book.

After implementing the solution, I realised that the three rows in a

ticket

can be shuffled around in any order without breaking the structure of

either

the ticket or the book. This could be used to reduce the number of

stored

grid patterns by a factor of 6; then when you generate a book, as a last

step you can randomly shuffle the rows in each ticket.

Regards,

Brian.

P.S. Note to James: I just discovered a silly bug in

Bookpattern.make_random

which has been fixed in the attached version