Calculator Fun and Games 3: Over and Out
This visit to Calculator Fun and Games is one of my favourites, and features a
game that I’ve played more than any of the others in the book (even the ‘spell
words with your calculator’ game). It’s
called Over and Out, and has a loose cricket theme.
The rules are simple: you start with a six-digit number (no zeroes allowed, no duplicated digits), and the aim is to get it down to zero in as few steps as possible, and the target is six (the number of balls in an over in a game of cricket). The steps are addition, subtraction, multiplication and division, and you can add, subtract, multiply or divide by any one-digit or two-digit numbers.
The example in the book goes like this:
583621
1)
583621
+ 19 = 583640
2)
583640
/ 40 = 14591
3)
14591
– 11 = 14580
4)
14580
/ 45 = 324
5)
324
/ 12 = 27
6)
27-27
= 0
Mission
accomplished, game over! 583621 is reduced to zero in six steps.
The hints in the book include generally working on subtracting and dividing,
but adding or multiplying where necessary to give you a change to divide by a
larger number – as we saw in the example here, the first step of adding 19
enables us to divide by 40 in the second step.
The largest
six-digit number that has no zeroes or duplicates is 987654 and it presents a
challenge! Here’s how I would have
approached it as a young child – the ‘adult’ mathematician will appear later.
987654
1) It’s
even, so I can divide by 2. And why not?
987654 / 2 = 493827 which is odd, so I can’t divide by 2 again.
2)
493827
– 27 = 493800 which I can divide by 50, or even 80. I’ll go with 50 for now (because I’m thinking as a child, and I'm not sure
how old I would have been when I realized I could divide by 80).
3)
493800
/ 50 = 9876 Now we’re talking! Getting our number down to four digits so
quickly puts us in a really good place.
I can see that we can divide this number by four, so that’s my next
step.
4)
493800
/ 4 = 2469 isn’t divisible by 2, 3 or 5,
so I’m struggling to find an easy way down.
I’ll subtract the 69 and it should be easier from there.
5)
2469
– 69 = 2400. Still quite high, but
divisible by 80.
6)
2400
/ 80 = 30
7)
30-30
= 0
So it took
me seven steps, although I was starting from the highest six-digit number
allowed in the game.
Over the
years, I’ve played this game quite often when I have a spare minute and a
calculator. In fact, I got so advanced
with it, that I started using a spreadsheet to keep track of my results
(although I’ve since lost it). Then,
just for good measure, I wrote a macro that would work out the optimal route
down from any digit to zero. It works on
one simple principle: the fastest way
down is to divide. Find the largest factor
for any number, and divide by it. If it’s
prime (or its lowest factor is higher than 99) then calculate the highest
multiple of 99 below it, and subtract down to it.
Let’s take 987654 as our example, and go through how the macro worked:
1)
987654
– highest factor below 99 is 97. Divide
by 97.
(to determine this, the macro divides 987654 by every number between 2 and 99
and checks if there is a remainder after the division. If there’s no remainder, then store the
number in a variable. The largest value
for that variable after checking all the numbers is the one to use. In other words, check if (987654/x) = INT(
987654/x).
987654 / 97 = 10182
2)
10182
– highest factor is 6. Divide by 6.
10182 / 6 = 1697
3)
1697
is prime. Highest multiple of 99 below 1697
is 17 * 99 = 1683, so we will subtract 14.
(to calculate this: round down the value of (1697/99) to the nearest integer).
1697 – 14 = 1683
4)
1683
is divisible by 99, we set it up that way.
1683 / 99 = 17
5)
17
– 17 = 0
The macro
is brutally strong, and took the highest possible value for the game (987654) to zero in
five steps.
So let’s change the rules of the game, and look at seven-digit numbers. Can the macro crunch a seven-digit number
down to zero in six steps? I’ll go
first, as an adult mathematician, using every trick I can think of (without
using a spreadsheet!).
9876543
1)
9876543
+ 57 = 9876600
I prefer this instead of subtracting 43, because I know I can divide the answer
by 60, whereas dividing 987500 will only divide by 50. I’ll do a quick check on my calculator to see
if I can divide by 80 (I can’t, fractions aren’t allowed), and hence divide by 60
for my next step.
2)
9876600
/ 60 = 164610
So I have a six-digit number, but at least it’s low and it’s divisible by
10. Easy next step (for the human,
anyway)
3)
164610
/ 10 = 16461
Now what? I can add 39 and then divide by 50, or subtract the 61 and divide by
80. I’ll take the second option.
4)
16461
– 61 = 16400
5)
16400
/ 80 = 205
6)
205
is visibly divisible by 5, so I’ll do that, get down to less than 100 and
subtract what’s left.
205 / 5 = 41
7)
41
– 41 = 0
Seven steps
for a seven-digit number seems good to me!
Let’s see what the macro would do:
9876543
1)
Largest
factor below 100 is 3.
9876543 / 3 = 3292181 which is prime.
2)
Since
3292181 is prime, find the multiple of 99 which is below it: 33254 * 99 = 3292146. Second step is to subtract down to this
number:
3292181 – 35 = 3292146
3)
This
is now divisible by 99:
3292146 / 99 = 33254 (at this stage, the macro is at around twice the value I was
at; I had 16461 after my third step).
4)
33254
is divisible by 26:
33254 / 26 = 1279
5)
1279
is prime, so find a multiple of 99 nearby. 12 * 99 = 1188, so I need to
subtract down to 1188.
1279 – 91 = 1188
6)
1188
/ 99 = 12
7)
12
– 12 = 0
So even my
macro needs to take seven steps with this seven-digit number.
Looking further, and with some assistance, I can see that I could improve the human
answer. I reached 164610 after two steps,
and some mathematical assistance shows that this is actually divisible by 90
and by 93. Dividing by 90 gives me 1829,
while dividing by 93 gives me 1770. Let’s
follow this path – I’ll recap first:
1)
9876543
+ 57 = 9876600
2)
9876600
/ 60 = 164610
3)
164610
/ 93 = 1770
4)
I
can see by eye that 1770 is divisible by 10, but it’s also divisible by
59.
1770 / 59 = 30
5)
30
– 30 = 0
So my
brute-force macro (which I programmed, I’ll take the blame/credit for it) took
seven steps by trying to divide by 99 each time, whereas another path can reach
the end in five steps. The macro has a
short-sighted strategy – what’s the best ‘next step’ - compared to trying to
find a number like 9876600 which can be divided by 60, 93 and 59 to get down to
less than 100 in three further steps (in fact 9876600 has 192 factors and 30 of
them are below 100, including 1). I will hold my hands up and confess that this
was a fluke, I didn’t plan to find such a ‘good’ number with so many factors.
A follow-up to the macro coding (which I have not pursued) is to take the initial
number and work out how to operate on it to get the most factors below
100. 9876600 has 192 factors; 9876500
has only 24, the best next step would be to divide by 50:
1)
9876543
– 43 = 9876500
2)
9876500
/ 50 = 197530
3)
197530
/ 10 = 19753 which is prime. Need to
find another number within +- 99 of 19753 which has the best sequence of
factors (and I need a new algorithm to do that). For now, let’s use the ‘divide by 99’ even
though we know it’s sub-optimal.
19753 / 99 = 199.5 so let’s find 200 * 99 = 19800. Let’s add up to 19800
4)
197530
+ 79 = 19800
5)
19800
/ 99 = 200
6)
200
/ 50 = 4
7)
4
– 4 = 0
Still stuck
on seven steps!
And so you
can see why I have whiled away many hours on this particular problem. It just takes one person and a calculator
(and I was playing this when calculators were a feature on watches, not portable
phones) and like all good maths puzzles, can be expanded indefinitely. I could get a spreadsheet and a macro to
throw nine-digit or ten-digit numbers around, getting down to zero in minimal steps;
or I could use my calculator and take the human approach, and then compare the
difference!
Follow-ups are
to work out the best way to treat prime numbers. Anything else can be divided down to
something smaller, but the main challenge is what to do when there’s no more dividing
available. At the moment, it follows the
“divide by 99 next time”, but it might be worthwhile finding larger factors so
that a series of divisions is possible instead of just 99. That’s a challenge for another day – I’m still
happy playing with my calculator and my macro!
Previous Calculator Fun and Games articles:
Snakes and Ladders (Collatz Conjecture)
Crafty Calculator Calculations (numerical anagrams, five digits)
More Multiplications (numerical anagrams, four digits)
No comments:
Post a Comment