Countdown!The beloved daytime TV program that generations of (university) students can remember from when waking up late in the afternoon (and perhaps missing the odd lecture or two after a heavy night out on the town). The official website can be seen here and Wikipedia has the history and rules of the show (but let me just recap the rules for you on this Blog post and there are two YouTube clips later down on this page to show you the numbers game in action) This website also give an excellent run down of some of the maths involved in the game (and an obvious extension would be to write an algorithm that can generate the best answer!) |

**RULES - Countdown Numbers Game**

One contestant selects six of twenty-four shuffled tiles.

The tiles are arranged into two groups: four "large numbers" (25, 50, 75 and 100) (12, 37, 62, 87 in some special episodes) and the remainder "small numbers", which comprise two each of the numbers 1 to 10.

The contestant chooses how many large numbers are in the selection; anywhere from none to all four.

A random three-digit target is generated by an electronic machine, affectionately known as "CECIL" (

which stands for Countdown Electronic Computer In Leeds).

The contestants then have thirty seconds to get as near to the target as possible by combining the six numbers

selected using addition, subtraction, multiplication and division.

Not all numbers need to be used.

A number can be used as many times as it appears. Fractions are not allowed—only positive integers may be used at any stage of the calculation

| |

The first thing we need to be able to do is to break the task down into its different steps so that each can be accomplished in turn.

I find a top-down design works well for this and let's me plan each step (and the order of the steps) so that I can focus on each one at a time. My top-down design is shown below:

I find a top-down design works well for this and let's me plan each step (and the order of the steps) so that I can focus on each one at a time. My top-down design is shown below:

Choosing the Easy of Difficult Version would be that last think I did however (as an extension task) as I would coded the program with easy numbers first and then went back and added the choice later in an indefinite

I decided that the best approach will be to create 2 lists (from which the random numbers will be decided - one list for small numbers and one list for large numbers)

I will also have a list that stores the large numbers chosen randomly AND the small numbers chosen randomly will be stored in their own list.

You can see that I have used some

**Loop**to force the user to make a choice between the Easy and Difficult version.**LISTS**I decided that the best approach will be to create 2 lists (from which the random numbers will be decided - one list for small numbers and one list for large numbers)

I will also have a list that stores the large numbers chosen randomly AND the small numbers chosen randomly will be stored in their own list.

You can see that I have used some

**CONSTANTS**that feed into the 2 lists**Variables**

Next we know that we have 6 numbers in total and that 0-4 of those numbers will be chosen randomly from the Large Number List and the remaining numbers will be chosen from the Small Number List. Number that have been chosen from each respective list will also be removed so that they cannot be chosen more time that they appear in each list.

**Output**!

The next step is to decide the Target Number that needs to be calculated using he six numbers the program has already chosen.

Just to make the final program look nicer, I have converted each List; the Large Number List and the Small Number Lists to strings and used the Strip function to remove the square brackets!

**Countdown**

Now the final part is to simulate the 30 Second Countdown and tell the user when the time is up!

This an ideal opportunity to use a FOR Loop but we cannot just use the iteration variable to print out as a user reminder of time passing (as this would be CountUp and not CountDown!).

Adding a variable that decreases by one each time with a final "Time Up!" should be enough and just for good measure, let's print out the numbers that were available and the Target Number one last time!

And that's it! An idea that had its stimulus in a meeting at school on improving Numeracy skills for students in secondary actually yields a really useful coding exercise with many different computational functions that can be used and a program that could be used by a classroom teacher to set quick numeracy challenges for their students!

For other coding and teaching ideas click here

For other coding and teaching ideas click here

countdown_v2.py |