BlogJacob deGroot-Maggetti

Explorations among Happy Numbers

I’ve recently been watching through a bunch of old Numberphile videos. Several of them feature sequences generated by manipulating the digits of a numbers. Invariably, these numbers are represented in decimal, leaving me curious about about how such sequences behave in other bases. My first question: what about happy numbers? Here’s a quick rundown of what happy numbers are:

I wrote a few Python functions to quickly check different numbers in different bases. As a nod to the Babylonians, I considered every base up to 60, checking every number less than 10,000 and counting how many of them were happy. Here are the results:

0: 0
1: 0
2: 9999
3: 1988
4: 9999
5: 2571
6: 645
7: 162
8: 549
9: 627
10: 1441
11: 196
12: 24
13: 582
14: 93
15: 164
16: 2585
17: 253
18: 4154
19: 3647
20: 1616
21: 45
22: 17
23: 19
24: 9
25: 519
26: 377
27: 279
28: 6
29: 1730
30: 5265
31: 11
32: 11
33: 84
34: 192
35: 77
36: 50
37: 58
38: 18
39: 26
40: 139
41: 850
42: 66
43: 10
44: 5
45: 58
46: 59
47: 5
48: 4
49: 9
50: 42
51: 48
52: 31
53: 62
54: 10
55: 106
56: 5
57: 5
58: 61
59: 33
60: 27
Graph showing the number of happy numbers found in various bases
Happy Numbers in Various Bases

A few things that jump out:

This investigation has only scratched the surface, and I hope to keep exploring the topic. Some questions that I’m curious about:

If you’re interested in looking at this in more detail, here’s a full list of all happy numbers up to 9,999 in bases up to 16 along with their representation in those bases, happy numbers up to 99,999 in several happy-number-poor bases, and happy numbers up to 999,999 in base 48. The code, including general functions for converting numbers between different bases, functions for searching for happy numbers, and the jupyter notebook in which I did my calculations, is on github.

Posted: Feb 16, 2022. Last updated: Feb 16, 2022.