Happy Numbers
Happy Numbers
Fall 2018
Happy numbers
Elizabeth Todd
Iowa State University
Recommended Citation
Todd, Elizabeth, "Happy numbers" (2018). Creative Components. 109.
https://lib.dr.iastate.edu/creativecomponents/109
This Creative Component is brought to you for free and open access by the Iowa State University Capstones,
Theses and Dissertations at Iowa State University Digital Repository. It has been accepted for inclusion in Creative
Components by an authorized administrator of Iowa State University Digital Repository. For more information,
please contact [email protected].
Elizabeth Todd
Iowa State University
Master of School Mathematics Graduate Program
Creative Component
1
Table of Contents
2 Other Exponents 6
4 Lesson Plan 13
5 Python Code 17
6 References 19
2
students at Iowa State University. The presenter, Leslie Hogben, led our group in an exploration
of happy numbers that invoked our curiosities and led to many interesting discoveries. While
happy numbers do not seem to have a practical application (that I’ve discovered at least), they
Definition
Happy numbers are numbers greater than one such that when the digits of the number are
squared and summed repeatedly, the number eventually goes to 1. For example, take the number
happy number. However, not all numbers exhibit this type of behavior. Consider the number 4.
4 is part of a cycle, because applying the function of squaring the digits and taking their sum will
eventually lead back to the initial number. Once you reach a number in the cycle, you will stay
in the cycle indefinitely. There are eight numbers (4, 15, 37, 58, 89, 145, 42, 20) in this cycle. A
number may also “fall into” the cycle. A number like 90 is not part of the cycle, but by applying
Happy Tree
At the Holl workshop, our group started by investigating the numbers 1 - 100 and
determined if they were happy, part of the cycle, or go to the cycle. The tree in Figure 1
shows all the numbers less than 100 that are happy, and how they get to 1. The remaining
numbers less than 100 are in the cycle or fall into the cycle (4, 15, 37, 58, 89, 145, 42, 20). The
tree uses numbers greater than 100 (such as 130) where necessary in order to complete the tree.
This “happy tree” is based on the drawing of Matt Parker from Numberphile Youtube video
series. [6]
Naturally this poses the question, will this tree “grow” forever? In other words, are there
infinitely many happy numbers? Well to become happy, the sums of squares need to eventually
lead to 1. Any power of 10 would fit that description, as all powers of 10 begin with a digit of
one, followed by zeros. Therefore there are infinitely many happy numbers, as there are an
Cycle
The happy tree contains only a small fraction of the numbers less than 100. Happy
numbers has a lower density of 0.1138 and the upper density of 0.18577. [5] During the
workshop we found that the rest of the numbers were either part of the cycle or go to the cycle.
Matt Parker [6] dubbed this cycle, and the numbers that go into it, the “melancoil.” Figure 2
shows all the numbers less than 100 that are either part of the cycle or go to the cycle. It also
This diagram shows some interesting discoveries. The trees that span from the cycle vary
greatly in length, with no numbers leading to 42 (except those within the cycle) and forty-two
numbers leading to 89. It begs the question- if we were to continue towards infinity, would there
still be no numbers leading to 42? Would there still be a larger amount of numbers leading to
Figure 2: Melancoil
Behavior of Numbers
At the Holl workshop, we determined the classification of numbers less than 100 and
then posed the question, can we prove that all numbers are either one, happy, part of the cycle, or
go to the cycle? If we could show that applying the function of summing the squares of the
digits to a number greater than 100 always produced a smaller value, we could conclude that all
numbers eventually led to two digit numbers, and given that all two digit numbers are either one,
6
happy, part of a cycle, or goes to the cycle, we would be able to conclude all numbers do so as
well. By testing several numbers, we saw that it did, indeed, appear to decrease in value. The
A number with n + 1 digits can be written as an an−1 ...a0 (and juxtaposition does not
imply multiplication). For a = an an−1 ...a0 , define S 2 (a) = a2n + a2n−1 + ... + a20
S 2 (a) > a . Or in another way, a2n + a2n−1 + ... + a20 ≥ 10n an + 10n−1 an−1 + ... + a0
Given that an , an−1 , ... a0 are single digit positive integers and the leading digit ≠ 0, then
10an > an 2 . Therefore, 10an + 10an−1 + .... + 10a0 > a2n + a2n−1 + ... + a20 and by substitution
10an + 10an−1 + .... + 10a0 ≥ 10n an + 10n−1 an−1 + ... + a0 . Simplifying the expression we have
9a0 ≥ (10n − 10)an + (10n−1 − 10)an−1 + .... + 90a2 . This is a contradiction because 9a0 ≤ 81
Theorem 2: All numbers are either one, happy, part of the cycle, or goes to the cycle.
Proof: By Lemma 1, repeatedly applying the sum of squares of digits function to a base
10 number greater than 100 will eventually lead to 2 digit number, indicating all numbers are
2 Other exponents
Consider what happens if the iterated function used an exponent other than 2; what
changes would occur? This question led me to the discovery of fixed points. With an exponent
7
of 2, 1 was the only number that returned itself. With an exponent of 3, that is not the case.
While 1 still returns 1, there are other numbers that do the same thing. There are five fixed
numbers to be exact- 1, 153, 370, 371, and 407. This will be established below and is known [2].
For all of these numbers, if their digits are cubed, the sums of the cubes returns the same number.
The last four numbers are also known as “narcissistic numbers.” Wolfram Math World defines
narcissistic numbers as “An n- digit number that is the sum of the nt h powers of its digits is called
an n- narcissistic number. It is also sometimes known as an Armstrong number, perfect digital
Thus we now have five options for all numbers; they are either fixed, happy, part of the
cycle, go to the cycle, or go to a fixed point. To find the fixed points, we need to apply the
function to numbers one by one and identify the numbers that return themselves. (This is best
done through the aid of programming.) Fortunately, just like the function with an exponent of 2,
applying the function with higher exponents will eventually decrease the number as well.
Therefore to find the fixed points for any exponent, we do not need to search all numbers, just
those below a certain bound. The higher the exponent, e , the higher the bound. A proof of the
Proof: Suppose that a ≥ 10e+1 . Then a = 10n an + 10n−1 an−1 + ... + a0 , where
an , an−1 , ... a0 are single positive integers, an ≠ 0 , and n ≥ e + 1 . Given that a is n + 1 digits
10n = (9 + 1)n
> 9n + (n)9n−1
> 9e + (n)9e
= (n + 1)9e
So then 10n > (n + 1)9e , and by substitution S e (a) ≤ 10n . Since a ≥ 10e+1 , then S e (a) < a. ▢
We now turn our attention to the cycle, or rather, the cycles. When the exponent was 2,
there was one cycle of eight numbers. However, using the exponent of 3 yields four small cycles
of numbers. They are: (55, 250, 130); (136, 244); (160, 217, 352); (919, 1459) [2] By Theorem
2, we know that these are the only cycles given that all numbers greater than 10,000 will
decrease under the operation of summing cubes of digits, and these were the only cycles found
The happy numbers of exponent 3 also have unique qualities. While there is no pattern to
happy numbers (that is currently known at least), cubic happy numbers share that quality that
they are all congruent to 1 modulo 3. [2] The proof is reproduced below.
Proof: Consider the cubic happy number an an−1 ...a0 (where juxtaposition does not imply
multiplication) or written another way 10n an + 10n−1 an−1 + ... + a0 . Given that fact that
a3 ≡ a (mod 3) and 10n ≡ 1 (mod 3), then an 3 + an−1 3 + ... + a0 3 ≡ an + an−1 + ... + a0 (mod 3)
and 10n an + 10n−1 an−1 + ... + a0 ≡ an + an−1 + ... + a0 (mod 3). Given that the sum of the digits
cubed of happy numbers eventually equal 1, and 1 ≡ 1 (mod 1), then all happy numbers are
congruent to 1 modulo 3. ▢
There are many differences between the behavior for numbers with exponents of two and
exponents of three. This raises the question, what happens with other exponents? How many
9
fixed points and cycles will they yield? Is there any way to predict these number of fixed points
and cycles? These questions are best answered with the assistance of a program.
Given an exponent e , the program will need to search through 10e+1 for all fixed points
and cycles. As the exponent increases, the program will have ten times more numbers to search
through, and therefore at some point comprehensive list of fixed points will not be possible.
However, the program was able to find all the fixed points for exponents 2-7, and cycles for 2-6
in a reasonable amount of time. The results are listed in the table below.
7 1
1741725
4210818
98000817
9926315
14459929
Table 1
an opportunity to develop number sense, look for patterns, and build an understanding of
recursive functions through exploring happy numbers. In the lesson, we started off by building
an understanding of what it means to “sum the squares of the digits of a number.” Students were
not accustomed to seeing functions rewritten descriptively, rather than with an equation.
I took the number 23 and summed the squares of the digits. I asked the students what
they think would happen if I kept doing this. Most students, inaccurately, thought that the
number would mostly increase and keep increasing. I think that came from an understanding
11
that squaring a number makes it bigger, but they did not think about how the biggest square of a
After students saw that 23 lead to 1 through the recursive function, I defined all such
numbers as “happy.” For middle schoolers, clear definitions are important, as well as being able
to describe them in their own words. The first thing I had students do in their groups was write
their own definition of happy numbers. This allowed me to check understanding of happy
I then challenged students to find as many happy numbers as they can. This showed
students that there are many happy numbers, that there are patterns to happy numbers, and it
helped students develop number sense and an understanding of happy numbers. This part of the
lesson provoked curiosity and creativity from the students. Many students realized that the
numbers that we found from 23 on our way to 1 (13, 10, and 1) are also happy numbers. They
also quickly learned that the reverse of these numbers were also happy. In other words, the order
of the digits did not matter. Other students realized that all the powers of 10 are happy, or started
taking the numbers 23, 13, etc and adding zeros onto the end. One student realized if the sum of
the squares was 10, the number was happy. The easiest route for him to do this was the number
1,111,111,111. Another student, having the same realization, stuck to the digits of 0, 1, 2, and 3
and found many unique numbers others did not consider, such as 2,211 or 301. She transposed
After giving students sufficient time to find these patterns, we discussed and highlighted
the key findings as a class. When posed with the question “Are there an infinite amount of
happy numbers?” a few students seemed stumped or unsure, but many quickly surmised that
12
because there are an infinite amount of powers of 10, there are naturally an infinite amount of
happy numbers. Then I asked the class “Are there non-happy numbers?” Many realized that
there are non-happy numbers, and one student predicted that non-happy sum to single digits
other than 1. Another student disproved this with the number 7, and we also talked about how
we do not stop summing the digits with a recursive function just because we reached a single
digit.
To introduce the cycle, I used the number 4, and said we will investigate what happens
when we sum the squares of the digits. We continued to do this until we reached the number 4
again. Some students were flummoxed why I stopped, while other students immediately let out a
knowledgeable “ohhhhhhhhh.” Using the age-old wise teaching words of “what do you notice?”
students pointed out that we ended up back where we started, that the numbers got stuck in a
loop. From here other questions arose: “Are there other cycles?” “What about the numbers that
While we did not reach a conclusion to the first question (some students did hang out
after class to ask more questions about that), we did figure out what happens to numbers that
were not happy or part of the cycle. Using another example, students discovered that other
numbers lead to the cycle. Students used the last few remaining minutes to fill out a table and
label numbers a happy, part of the cycle, or goes to the cycle. Based off of the natural curiosity
and questions that they posed, a good follow lesson would be to look at other exponents.
13
4 Lesson Plan
Overview of Lesson
Students will introduced to the concept of a recursive function through happy numbers.
Students will explore the different outcomes that will occur through this function, and make
predictions. Students will be guided to prove their predictions. Students can also extend their
exploration of happy numbers by using different exponents or bases.
Learning Objectives
The objective of this lesson is focused on reasoning and problem solving skills. Students
will be making sense of the recursive function for happy numbers. Using that structure, students
will see how the function results in two different outcomes. Students will construct an argument
as to whether there it is possible to have more than those two outcomes. This relates to the Iowa
Core Standard HSF.BF.A.1.a
“Determine an explicit expression, a recursive process, or steps for calculation from a context.”
Prerequisites
Students should have background knowledge on using exponents. Knowledge of other
bases can help extend the lesson, but is not required.
Time Required
45- 90 minutes. Basics of the lesson can be done in one class period, but further
explorations and extensions could make this two class periods.
Lesson Plan
Introduction
Start with the number 23. Define what it means to “sum the squares of the digits.” Ask
the students to make a prediction about what will happen. (Will the value increase? Decrease?
Stay the same?) Repeat summing the squares until you get to one. Ask the students what
happens when we sum the squares of 1. Ask students if they think this will happen with any
other numbers. Define these numbers as “happy numbers.”
Cycle
Ask students to share their happy numbers, and highlight any patterns, such as 10, 100,
1000, etc. Then ask students to share numbers that were not happy. Highlight one of the
numbers that is part of the cycle. Use the number to introduce the cycle. Ask students to explain
why a cycle occurred, and predict if any other numbers would enter into this cycle. Ask students
to predict if there are any other cycles.
Testing Numbers
Students should define what the possible results of recursive function are. Then have
students work collectively to complete the table. Ask students to define any patterns they see,
such as numbers like 23 and 32 both are happy.
Student Handout
Write your own definition of a happy number
Determine if the following numbers in the table are happy, part of the cycle, or go to the cycle
Do you notice any patterns with the numbers that are happy?
17
6 References
[1] Budden, C., Chalmers, J., Hogben, L., Reece, B., Wilson, U., & Yoder, L.
Adventures with numbers and iteration. Preprint. (2014)
[2] Grundman, H. G., & Teeple, E. A. Generalized Happy Numbers. The Fibonacci
Quarterly, 39(2001), 462-466.
[3] Grundman, H. G., & Teeple, E. A. Iterated Sums of Fifth Powers of Digits Rocky
Mountain Journal of Mathematics, 38(2008), 1139- 1146
[4] Hogben, L. (2017, June 14). Happy Numbers. Lecture presented at Holl Mini-Workshop
for MSM students at Iowa State University, Ames.
[5] OEIS, The Online Encyclopedia of Integer Sequences. Sequence A007770 (2018)
[6] Parker, Matt (2012, February 26). 145 and the Melancoil. Retrieved November 06,
2017, from https://www.youtube.com/watch?v=_DpzAvb3Vk4
[7] Weisstein, Eric W. "Narcissistic Number." From MathWorld--A Wolfram Web Resource.
http://mathworld.wolfram.com/NarcissisticNumber.html