* C O U N T D O W N *
Info
Cursors Scroll Up and Down
If you've ever watched Countdown on
C4 - which seems to have been on since
before Noah had even heard of an Ark -
you'll be familiar with the "Numbers
Game". For those who have managed to
miss it all these years, what happens
is:
Six random numbers - five of them
usually between 1 and 10, and the
sixth usually 25, 50, 75, or 100 - are
chosen, and then a "target" number
from 100 to 999 is chosen. Two
contestants have thirty seconds to
manipulate the six numbers to hit, or
get close to, the target, using +,-,*,
and / freely, separating and combining
the numbers in any way. They don't
have to use all the numbers.
The solutions can always be written
as a single expression. For example,
given the numbers 100 2 5 9 8 4 and
the target 710, a solution is
(100*8)-(2*5*9). A more obscure
solution is (9*4+100+8-2)*5.
If you want to try a really tough one,
which even the near-infallible Carol
Vorderman didn't get on the day, try:
numbers: 5 7 9 5 3 10 - target: 821.
Answer at the bottom.
Naturally, we of the 8BS persuasion
want to know (don't we?) whether a
computer can tackle this sort of
problem. That's what this program
does. It could churn methodically
through every possibility, of which
there are several zillion, with a lot
of duplication, but it seemed more fun
to write a program that would produce
totally random expressions, evaluate
them, and carry on relentlessly until
it hit the target. It works, usually,
eventually...
You'll notice from the examples that
brackets are necessary for this sort
of thing. It's difficult to create a
random expression with random
brackets, and not much fun trying to
evaluate it either, since it would be
a string. It was much easier to invent
an odd form of algebraic notation
which didn't use brackets, but had the
same effect. So here, in addition to
+,-,*, and /, there is p, m, t, and d
- standing for plus, minus etc. Terms
connected by these symbols are treated
as though in brackets and are
evaluated first.
All symbols, first the letters, and
then the signs, are evaluated in
sequence from left to right. None have
precedence.
So, to hit a target of 711 with
numbers 25 8 4 2 5 9, the program
could come up with 8t4m5t2+25*9. This
is the same as ((8*4-5)*2+25)*9, which
becomes 79*9=711.
The numbers and symbols are held in
arrays. A string is created just for
the display.
About a third of the expressions
produced randomly by the program give
a negative answer. Positive answers
are shown in red, and negative in
magenta. The negative answers are, in
effect, valid solutions. They can
always be transformed into positive
solutions by adjusting the signs and
components.
It's very rare that a solution uses
only three of the numbers, and four is
unusual, so the program uses four 20%
of the time, five 40%, and six 40%.
Division has to produce a whole
number result, presumably, and is not
very helpful. It is used occasionally,
just to show willing, but only in the
"d" form, never /.
The program creates and tests random
expressions at a rate of about seven
per second on the Beeb. It usually
comes up with a solution within a few
minutes, but can sometimes take ages.
The solutions it finds can be neat, or
simple, or clever, or obscure, or just
plain silly.
When running the program, you can
either enter six numbers and the
target - perhaps from the TV program,
or it will generate random numbers and
a target to aim at.
The scrolling display is a sample of
what's happening. It's set initially
at 1 in 5. You can change this during
"Pause". This does not affect what
appears in the box display.
It tings when the "closest so far"
is within 10 of the target. It also
displays alternatives it comes across
to the current "closest".
When it finds a solution, it stops.
You can Continue, to look for another
solution, or start a new run.
The answer to 821: 5t9+3*7p10+5.
As a test for the program, I invented
a tough problem for it, by working
backwards from six numbers in a
complex sequence to give a target,
which I fondly imagined would be
tricky and probably unique. It found
two alternative solutions...
Given 3 5 6 7 7 10 and a target of
759, can you find one, or two, or
three (or more) solutions?
Press SPACE to return to Options.