Showing posts with label happy number. Show all posts
Showing posts with label happy number. Show all posts

Thursday, 8 November 2018

2019: A Numerical Profile


With the coming year, 2019, less than two months away, I decided to investigate some of the numerical properties adhering to this number. Right off the bat, we can see that its digit sum is 12 and, because 3 divides 12, we know that 3 will divide 2019 as well. In fact, 2019 has prime factors of 3 and 673. Thus

2019 = 3 * 673

This means that 673 AD and 1346 AD (673 + 673 = 1346) could be associated with 2019 AD. 673 AD was a time of great expansion for the Islamic world (Muhammad had died in 632 AD). The following year, the Siege of Constantinople (one of many over the centuries) began, but "in 672–673 Arab fleets secured bases along the coasts of Asia Minor, and then proceeded to install a loose blockade around Constantinople." Here are some more details :
The First Arab Siege of Constantinople in 674–678 was a major conflict of the Arab–Byzantine wars, and the first culmination of the Umayyad Caliphate's expansionist strategy towards the Byzantine Empire, led by Caliph Mu'awiya I. Mu'awiya, who had emerged in 661 as the ruler of the Muslim Arab empire following a civil war, renewed aggressive warfare against Byzantium after a lapse of some years and hoped to deliver a lethal blow by capturing the Byzantine capital, Constantinople.
As reported by the Byzantine chronicler Theophanes the Confessor, the Arab attack was methodical: in 672–673 Arab fleets secured bases along the coasts of Asia Minor, and then proceeded to install a loose blockade around Constantinople. They used the peninsula of Cyzicus near the city as a base to spend the winter, and returned every spring to launch attacks against the city's fortifications. Finally, the Byzantines, under Emperor Constantine IV, managed to destroy the Arab navy using a new invention, the liquid incendiary substance known as Greek fire. The Byzantines also defeated the Arab land army in Asia Minor, forcing them to lift the siege. The Byzantine victory was of major importance for the survival of the Byzantine state, as the Arab threat receded for a time. A peace treaty was signed soon after, and following the outbreak of another Muslim civil war, the Byzantines even experienced a period of ascendancy over the Caliphate.
1346 AD was also an interesting year. As reported in Wikipedia, it included these events:
  • in Spring, a severe Black Death epidemic began its spread at the River Don near the Black Sea, then spread throughout Russia, the Caucasus, and the Genovese provinces within the year
  • on April 16th,  the Serbian Empire was proclaimed in Skopje by Dusan Silni, occupying much of South-Eastern Europe
  • on July 11th and 12th, Edward III and the English army cross the English Channel, and begin an invasion of France
  • on August 26, at the Battle of Crécy, the English defeat the French, in the first European battle where gunpowder is used.
Well, there's not much Mathematics in the history above so best to move on to more mathematical matters. What follows are some interesting facts about 2019 as number.

OEIS A037015: Numbers n with property that, reading binary expansion of n from right to left, run lengths strictly increase. Here we have \( 2019_{10}=11111100011_2 \). The initial members of the sequence are:

0, 1, 3, 6, 7, 14, 15, 28, 30, 31, 57, 60, 62, 63, 120, 121, 124, 126, 127, 241, 248, 249, 252, 254, 255, 483, 496, 497, 504, 505, 508, 510, 511, 966, 993, 995, 1008, 1009, 1016, 1017, 1020, 1022, 1023, 1987, 1990, 2016, 2017, 2019, 2032, 2033, 2040, 2041, 2044

OEIS A158339: Semiprimes that are the sum of four successive semiprimes. Here we have: 501 + 502 + 505 + 511 = 2019 and 501 = 3 * 167, 502 = 2 * 251, 505 = 5 * 101 and 511 = 7 * 73.

The initial members of this sequence are:

39, 94, 106, 118, 146, 158, 185, 201, 221, 254, 302, 365, 427, 473, 485, 519, 537, 589, 633, 655, 707, 723, 749, 767, 842, 851, 869, 901, 1003, 1145, 1205, 1211, 1219, 1247, 1263, 1337, 1349, 1603, 1646, 1681, 1703, 1731, 1797, 1891, 1903, 1937, 2005, 2019

OEIS A193227: Semiprimes p*q such that p+1 and q+1 are semiprimes. 

Here p+1 = 4 = 2 * 2 and q+1 = 674 = 2 * 337 and the initial members of this sequence are:

9, 15, 25, 39, 65, 111, 169, 183, 185, 219, 305, 365, 471, 481, 579, 785, 793, 831, 939, 949, 965, 1191, 1263, 1369, 1371, 1385, 1565, 1623, 1839, 1983, 1985, 2019

OEIS A091431: Happy-go-Lucky numbers: numbers that are both Happy (OEIS A007770) and Lucky (OEIS A000959). Happy numbers are those whose repeated sums  of squares of digits return 1.

The initial members of this sequence are:
1, 7, 13, 31, 49, 79, 129, 133, 193, 219, 319, 331, 367, 391, 409, 487, 655, 673, 739, 931, 937, 1009, 1029, 1039, 1093, 1209, 1233, 1251, 1275, 1281, 1285, 1303, 1309, 1323, 1339, 1533, 1575, 1587, 1599, 1663, 1771, 1857, 1933, 1959, 1995, 2019

OEIS A076408: Sum of first n perfect powers. As Wikipedia defines it: 
In mathematics, a perfect power is a positive integer that can be expressed as an integer power of another positive integer. More formally, n is a perfect power if there exist natural numbers m > 1, and k > 1 such that \( m^k = n \). In this case, n may be called a perfect k-th power. If k = 2 or k = 3, then n is called a perfect square or perfect cube, respectively. Sometimes 1 is also considered a perfect power (\(1^k = 1\) for any k).
Here n=22 and, as shown in OEIS A001597, the first 22 perfect powers are: 1, 4, 8, 9, 16, 25, 27, 32, 36, 49, 64, 81, 100, 121, 125, 128, 144, 169, 196, 216, 225, 243 with the sequence of progressive sums being: 1, 5, 13, 22, 38, 63, 90, 122, 158, 207, 271, 352, 452, 573, 698, 826, 970, 1139, 1335, 1551, 1776, 2019.

In fact, there are 140 sequences listed in the OEIS that contain a reference to 2019. I've covered some of the more interesting ones, or at least ones that I could understand.

From Numbers Aplenty, we have the following properties:

2019 is the smallest number that can be written in six ways as the sum of the squares of three primes. Here are the prime triplets:

7 11 43, 7 17 41, 11 23 37, 13 13 41, 17 19 37, 23 23 31

Figure 1 is an extract from the Numbers Aplenty page:

FIGURE 1

Tuesday, 26 June 2018

Happy Numbers

Today I turned 25286 days old and 25286 happens to be a happy number, defined as:
Let us define a function \( s(n) \), for \( n>0 \), which gives the sum of the squares of the digits of \( n \), so, for example, \( s(37)=3^2+7^2=58 \).

If we start from a number \(n\)  and we repeatedly apply \( s(\cdot) \), we obtain a sequence \(S_n\) of numbers \(n\), \(s(n) \), \(s(s(n)\), \(\dots \), and so on.

A number \(n\) is called happy if \(S_n \) contains the number 1.

Note that \(s(1)=1 \), so in that case the sequence \( S_n \) has an infinite tail of \(1\)'s.

If a number is not happy then it is easy to see that at a certain point \(S_n\) will enter the infinite loop$$ \dots,4, 16, 37, 58, 89, 145, 42, 20, 4,\dots $$So, for example, starting from  \(94\)  we obtain \(94\rightarrow97\rightarrow130\rightarrow10\rightarrow1\), so \(94\) is happy. 

On the contrary, starting from 61 we obtain \(61\rightarrow37\rightarrow58\rightarrow89 \) and thus 61 is not happy, since 89 belongs to the unhappy loop.

According to Wikipedia
by inspection of the first million or so happy numbers, it appears they have a natural density of around 0.15. Perhaps surprisingly, then, the happy numbers do not have an asymptotic density. The upper density of the happy numbers is greater than 0.18577, and the lower density is less than 0.1138. After 25286, the next happy number is 25294 (followed by 25295).
As usual I tried to write some SAGE code to determine whether a number was happy or not. Here is what I came up with:
INPUT (using a happy number 25286):
entered_number=25286
number=str(entered_number)
while sum!= 1 and sum!=4:
    sum=0
    for x in range(len(number)):
        sum+=Integer(number[x])^2
    number=str(sum)
    print(sum) 
OUTPUT
133
19
82
68
100
1
INPUT (using an unhappy number 89)
entered_number=89
number=str(entered_number)
while sum!= 1 and sum!=4:
    sum=0
    for x in range(len(number)):
        sum+=Integer(number[x])^2
    number=str(sum)
    print(sum) 
OUTPUT
145
42
20
4
The 4 is used to prevent the program going into an infinite loop and, at the same time, to mark a number as happy. Unhappy numbers will always enter the following loop:

... 4, 16, 37, 58, 89, 145, 42, 20, 4, ...

Any of the above numbers could be used to identify an unhappy number and break the loop.

The Wikipedia article on unhappy numbers includes the following Python code for determining whether a number is happy or unhappy (rather than displaying the trajectory as I did in my SAGE program):
INPUT (using happy number 25286)
def square(x):
    return int(x) * int(x)
def happy(number):
    return sum(map(square, list(str(number))))
def is_happy(number):
    seen_numbers = set()
    while number > 1 and (number not in seen_numbers):
        seen_numbers.add(number)
        number = happy(number)
    return number == 1
is_happy(25286) 
OUTPUT
True
INPUT (using unhappy number 89)
def square(x):
    return int(x) * int(x)
def happy(number):
    return sum(map(square, list(str(number))))
def is_happy(number):
    seen_numbers = set()
    while number > 1 and (number not in seen_numbers):
        seen_numbers.add(number)
        number = happy(number)
    return number == 1
is_happy(89) 
OUTPUT
False 
As can be seen, the Python code involves a quite different approach. It defines three functions, the second building on the first and the third building on the second : square(x), happy(number) and is_happy(number).

The command sum(map(square, list(str(number)))) caught my eye. This is a very useful command that takes two inputs:
  • a function (in this case, square)
  • a list (in this case, str(number))
It outputs a list (in this case, the sum of the number's digits squared).