Operation Manual
Experiments in Python
79
Notes:
Maths homework
What a nightmare. Only just getting started and already there is homework.
Computers and computer science share a great deal with mathematics. We’ve
drawn a colourful circle or two, but now it is time to look at some number crunching.
To start with, let’s go through a simple maths problem that you have probably been
set at school at some time:
What are the factors of all the numbers from 1 to 50? That is, what are the positive
divisors of the numbers from 1 to 50?
Without a Raspberry Pi
The first few are easy because you can divide the number by those numbers
smaller than it in your head and see if there is a remainder.
1 -> 1
2 -> 1 and 2 divide into 2
3 -> 1 and 3
4 -> 1, 2 and 4. 3 doesn’t divide into 4
5 -> 1 and 5 only. 2, 3 and 4 don’t divide into 5 leaving no remainder
6 -> 1, 2, 3 and 6
7 -> 1 and 7 only
8 -> 1, 2, 4 and 8
Jumping ahead, let’s try 26. We have to divide 26 by all the numbers smaller than
it to be sure we have them all.
26/1 = 26
26/2 = 13
26/3 = 8 2/3
26/4 = 6 1/2
26/5 = 5 1/5
26/6 = 4 1/3
…
26/13 = 2
…
26/26 = 1
To work out larger numbers, you need to see which of those numbers smaller than
it will have no remainder when they divide into it. In the case of 26: 1, 2, 13 and 26
leave no remainder.
Imagine that the question was just finding the factors of 12,407? You would have
to start at 1 and work your way through more than 6,000 numbers to discover all
of those that divide into 12,407 with no remainder.