Happy prime numbers in Doctor Who
I’m currently watching the revived series of Doctor Who and in episode seven, called 42 in the third series, they find themselves in a difficult situation.
Jump to the bottom of the post to find download links for the episodes, which has uploaded to the Internet Archive.
Almost nine minutes into the episode, a particular event stood out for me. They had to find the next number in a sequence: 313, 331, 367, … ? to open a locked door in a spaceship:
The Doctor gives the answer right away and explains that the number sequence is Happy prime numbers. Is this a referance to the name of the episode, 42? As 42 is the answer to life, universe and everything, according to Douglas Adams.
He even adds a rhetorical question about why people are not learning recreational mathematics anymore, of which I agree, why is that?
What makes a number happy or unhappy?
The Doctor gives the following definition of the sequence:
Any number that reduces to one when you take the sum of the square of its digits and continue iterating until it yields one is a happy number. Any number that doesn’t, isn’t. A happy prime is a number that’s both happy and prime.
For example, iterating the number 79 this way look like this:
7² + 9² = 49 + 81 = 130
1² + 3² + 0² = 1 + 9 + 0 = 10
1² + 0² = 1 + 0 = 1
The number 79 yielded one after going through 130 and 10. All the numbers in the process are also happy numbers if it yields 1 in the end, meaning 10 and 130 are happy numbers.
On the contrary, an unhappy number will just keep looping through a sequence of numbers over and over and never reach one. Those numbers it loops over will also be unhappy numbers.
At this point, I can see why they are called happy I guess. They are not stuck in a loop.
I wrote a small program to run through all numbers below 10 000 and did a check to see who are both happy and prime and found 200 of them:
7, 13, 19, 23, 31, 79, 97, 103, 109, 139, 167, 193, 239, 263, 293, 313, 331, 367, 379, …
7, 13, 19, 23, 31, 79, 97, 103, 109, 139, 167, 193, 239, 263, 293, 313, 331, 367, 379, 383, 397, 409, 487, 563, 617, 653, 673, 683, 709, 739, 761, 863, 881, 907, 937, 1009, 1033, 1039, 1093, 1151, 1277, 1303, 1373, 1427, 1447, 1481, 1487, 1511, 1607, 1663, 1697, 1733, 1847, 1933, 2003, 2039, 2063, 2111, 2221, 2309, 2333, 2339, 2383, 2393, 2417, 2557, 2693, 2741, 2833, 2851, 2903, 2963, 3001, 3019, 3067, 3079, 3083, 3109, 3137, 3209, 3301, 3313, 3319, 3323, 3329, 3331, 3371, 3391, 3463, 3607, 3637, 3643, 3673, 3709, 3779, 3797, 3803, 3823, 3833, 3907, 3923, 3931, 4111, 4127, 4157, 4217, 4271, 4363, 4441, 4447, 4481, 4517, 4663, 4721, 4751, 4817, 4871, 5147, 5227, 5281, 5417, 5471, 5477, 5527, 5569, 5659, 5741, 5821, 5879, 5897, 5987, 6037, 6053, 6073, 6163, 6197, 6203, 6329, 6337, 6343, 6353, 6361, 6367, 6373, 6389, 6637, 6661, 6673, 6701, 6703, 6719, 6733, 6763, 6791, 6803, 6899, 6917, 6971, 6983, 7039, 7127, 7309, 7331, 7451, 7457, 7481, 7541, 7547, 7589, 7603, 7691, 7793, 7841, 7937, 8081, 8147, 8233, 8369, 8521, 8597, 8693, 8699, 8741, 8821, 8929, 8963, 8969, 9001, 9007, 9013, 9103, 9133, 9203, 9323, 9377, 9587, 9623, 9689, 9829, 9857
The sequence in the Doctor Who episode refers to can be spotted there. Notice that a select three are also palindrome in nature: 7, 313, 383, of which 313 stands out to me, as the first in the sequence used in the episode, but also as the plate number for the car Donald Duck drives in.
The Happy Primes have an entry in the OEIS: https://oeis.org/A035497 which defines them as: primes that eventually reach 1 under iteration of “x -> sum of squares of digits of x”.
Looking into this did make me happy inside.
Download the first few seasons at IA
- https://archive.org/details/doctor-who-2005-s01
- https://archive.org/details/doctor-who-2005-s02
- https://archive.org/details/doctor-who-2005-s03
- https://archive.org/details/doctor-who-2005-s04
Each of the links provide .torrent-files for the whole season.