For instance, 13 is a happy number because
On the other hand, 4 is not a happy number because the sequence starting with
, the number that started the sequence, and so the process continues in an infinite cycle without ever reaching 1.
A number which is not happy is called sad or unhappy.
that eventually reaches 1 when iterated over the perfect digital invariant function for
[1] The origin of happy numbers is not clear.
Happy numbers were brought to the attention of Reg Allenby (a British author and senior lecturer in pure mathematics at Leeds University) by his daughter, who had learned of them at school.
Given the perfect digital invariant function for base
If a number is a nontrivial perfect digital invariant of
The happiness of a number is preserved by removing or inserting zeroes at will, since they do not contribute to the cross sum.
By inspection of the first million or so 10-happy numbers, it appears that they have a natural density of around 0.15.
Perhaps surprisingly, then, the 10-happy numbers do not have an asymptotic density.
, the only positive perfect digital invariant for
is the trivial perfect digital invariant 1, and there are no other cycles.
, all numbers lead to 1 and are happy.
, the only positive perfect digital invariant for
is the trivial perfect digital invariant 1, and the only cycle is the eight-number cycle and because all numbers are preperiodic points for
Because base 6 has no other perfect digital invariants except for 1, no positive integer other than 1 is the sum of the squares of its own digits.
, the only positive perfect digital invariant for
is the trivial perfect digital invariant 1, and the only cycle is the eight-number cycle and because all numbers are preperiodic points for
Because base 10 has no other perfect digital invariants except for 1, no positive integer other than 1 is the sum of the squares of its own digits.
In base 10, the 143 10-happy numbers up to 1000 are: The distinct combinations of digits that form 10-happy numbers below 1000 are (the rest are just rearrangements and/or insertions of zero digits): The first pair of consecutive 10-happy numbers is 31 and 32.
[5] It has been proven that there exist sequences of consecutive happy numbers of any natural number length.
[6] The beginning of the first run of at least n consecutive 10-happy numbers for n = 1, 2, 3, ... is[7] As Robert Styer puts it in his paper calculating this series: "Amazingly, the same value of N that begins the least sequence of six consecutive happy numbers also begins the least sequence of seven consecutive happy numbers.
Unlike happy numbers, rearranging the digits of a
Paul Jobling discovered the prime in 2005.
[dubious – discuss] Its decimal expansion has 12837064 digits.
[11] In base 12, there are no 12-happy primes less than 10000, the first 12-happy primes are (the letters X and E represent the decimal numbers 10 and 11 respectively) The examples below implement the perfect digital invariant function for
described in the definition of happy given at the top of this article, repeatedly; after each time, they check for both halt conditions: reaching 1, and repeating a number.
A simple test in Python to check if a number is happy: