Countdown number game solver

mellen profile image Matt Ellen ・1 min read

In the UK there is a game show called Countdown. It has two main components, rearranging letters and doing arithmetic.

This challenge is concerned with the arithmetic, or number game, part.

In the number game the contestants are given six numbers between (and including) 1 and 100. No number repeats. A target number less than 1000 is then generated. The contestants have to use the numbers they are given to create a sum that equals the target. They can use addition, subtraction, multiplication and division. Each number can be used up to once, unless you make that number out of the other numbers.

For example, say the numbers are 1, 2, 6, 12, 14 and 5 and the target is 144. 12 × 12 is not a solution because 12 can only be used once. However 6 × 2 × 12 is a solution. (14 - 2) × 12 is also a solution.

The challenge is to create a programme or function that takes a list of numbers and a target and then generates solutions that use those numbers to create that target.


numberGame([7, 12, 4, 5, 25, 50], 615)
# possible output
# (((((7*12)+4)+25)*5)+50) = 615

numberGame([7 11 1 2 25 75], 367)
# possible output
# (((((1+75)-7)*11)-25)/2) = 367

It's not necessary to show all possible solutions, just at least one that works.

Posted on May 26 by:

mellen profile

Matt Ellen


Ultra-fullstack software developer. Python, JavaScript, C#, C. He/him/his


markdown guide