Happy Numbers make Happy Programmers ! :-)

Here is one question which one of my students, Vedant Sahai asked me. It appeared in his computer subject exam of his recent ICSE X exam (Mumbai):

write a program to accept a number from the user, and check if the number is a happy number or not; and the program has to display a message accordingly:

A Happy Number is defined as follows: take a positive number and replace the number by the sum of the squares of its digits. Repeat the process until the number equals 1 (one). If the number ends with 1, then it is called a happy number.

For example: 31

Solution : 31 replaced by 3^{2}+1^{2}=10 and 10 replaced by 1^{2}+0^{2}=1.

So, are you really happy? 🙂 🙂 🙂

Cheers,

Nalin Pithwa.

Another cute proof: square root of 2 is irrational.

Reference: Elementary Number Theory, David M. Burton, Sixth Edition, Tata McGraw-Hill.

(We are all aware of the proof we learn in high school that \sqrt{2} is irrational. (due Pythagoras)). But, there is an interesting variation of that proof.

Let \sqrt{2}=\frac{a}{b} with gcd(a,b)=1, there must exist integers r and s such that ar+bs=1. As a result, \sqrt{2}=\sqrt{2}(ar+bs)=(\sqrt{2}a)r+(\sqrt{2}b)s=2br+2bs. This representation leads us to conclude that \sqrt{2} is an integer, an obvious impossibility. QED.

Problems from Russian Mathematical Circles

I  have culled these problems for fun with mathematics or for practising for Pre-RMO. (The source is Russian Mathematical Circles):

Problem 1:

A number of bacteria are placed in a glass. One second later each bacterium divides in two, the next second each of the resulting bacteria divides in two again, etc. After one minute, the glass is full. When was the glass half-full?

Problem 2:

Ann, John, and Alex took a bus tour of Disneyland. Each of them must pay 5 plastic chips for the ride, but they have only plastic coins of values 10, 15 and 20 chips (each has an unlimited number of each type of coin). How can they pay for the ride?

Problem 3:

Jack tore out several successive pages from a book. The number of the first page he tore out was 183, and it is known that the number of the last page is written with the same digits in some order. How many pages did Jack tear out of the book?

Problem 4:

There are 24 pounds of nails in a sack. Can you measure out 9 pounds of  nails using only a balance with two pans?

Problem 5:

A caterpillar crawls up a pole 75 inches high, starting from the ground. Each day it travels up 5 inches, and each night it slides down 4 inches. When will it reach the top of the pole?

Go ahead and solve them in your coffee break !!

Nalin Pithwa