Home » 2014 » January

# Monthly Archives: January 2014

## The number of possible bingo cards

During a recent holiday I was sitting through the bingo session that some younger relatives were playing.  My mind wandered onto the question of how many possible cards exist.

A bingo card (as played in the UK, maybe elsewhere too?) has 27 boxes arranged as 3 rows by 9 columns.  Each row has 5 numbers and 4 blanks.  No column may be all blank.  The first column contains numbers between 1-9, the second contains numbers between 10-19, and so on.  The last 2 columns contain numbers between 70-79 and 80-90 respectively.  Note the uneven distribution of possible numbers in the columns.  Numbers are in increasing order downwards if more than one appears in a column.  I don’t believe it’s a requirement for there to be (or not to be) a column with 3 numbers in, but both cases are computed below for completeness.

So moving straight to the answer: 3,669,688,706,217,187,500

If exactly one column must have 3 numbers: 1,957,437,874,940,625,000

If at least one column must have 3 numbers: 2,494,937,545,340,625,000

The numbers were computed with the Python script below:

```#!/usr/bin/python3

# Look up table of how many ways there are to fill the nth column with numbers
# from the appropriate range, based on how many non-blank v blank entries there
# are
perms_per_col =      [( 9,  9* 8//2,  9* 8*7//6)] # 1-9, 9 numbers
perms_per_col += 7 * [(10, 10* 9//2, 10* 9*8//6)] # 2nd-8th cols, 10 numbers
perms_per_col +=     [(11, 11*10//2, 11*10*9//6)] # 80-90, 11 numbers

# Build list of 4-tuples containing the possible indices (0...8) of 4 blanks
# within a row of 9 cells
patterns = []
for x0 in range(0,9):
for x1 in range(x0+1,9):
for x2 in range(x1+1,9):
for x3 in range(x2+1,9):
patterns += [(x0, x1, x2, x3)]

total = 0
total_one_three = 0
total_any_threes = 0

# 3 nested loops, over the 3 rows in the card
for i0, p0 in enumerate(patterns):
# 'comfort' message to show progress
print ("%d" % (i0,))
for p1 in patterns:
for p2 in patterns:
# How many blank boxes there are in each column?
blanks =  * 9
for i in p0: blanks[i] += 1
for i in p1: blanks[i] += 1
for i in p2: blanks[i] += 1
threes = 0 # Number of columns with 3 non-blank cells
cards_with_this_layout = 1
for col in range(0,9):
# No column is allowed to have 3 blanks.  If one does, bail out of this pattern
if blanks[col] == 3:
cards_with_this_layout = 0
break
if blanks[col] == 0:
threes += 1
table_index = 2 - blanks[col]
cards_with_this_layout *= perms_per_col[col][table_index]
total += cards_with_this_layout
if threes == 1:
total_one_three += cards_with_this_layout
if threes > 0:
total_any_threes += cards_with_this_layout

print ("There are {:,d} cards possible".format(total))
print ("There are {:,d} cards possible with exactly one column having three numbers".format(total_one_three))
print ("There are {:,d} cards possible with at least one column having three numbers".format(total_any_threes))

```