# Just for fun: Countdown numbers game solver

Mel mwilson at the-wire.com
Mon Jan 21 00:00:42 CET 2008

```dg.google.groups at thesamovar.net wrote:
> Ever since I learnt to program I've always loved writing solvers for
> the Countdown numbers game problem in different languages, and so now
> I'm wondering what the most elegant solution in Python is.
>
> If you don't know the game, it's simple: you're given six randomly
> chosen positive integers, and a target (another randomly chosen
> positive integer), and you have to make the target using only the
> numbers you're given, and +,-,* and / (and any number of brackets you
> like). You're not allowed fractions as intermediate values. So, given
> 2, 3 and 5 say, and a target of 21, you could do (2+5)*3 = 21.
>
> So what's the best algorithm? And, what's the most elegant way to code
> it in Python? I've posted my most elegant version below (I have a
> faster version which is slightly less elegant). Can anyone do better?

I found that postfix notation made it easy to run up all the possible
expressions based on permutations of the available numbers.  Don't
know where my source code is ... have to look.

Mel.

```

More information about the Python-list mailing list