Happy Numbers, Kata in Lua

For my first kata, I picked Happy Numbers at Coding Kata and decided to play with Lua, which I don’t know well.

The user-story is as follows :

You are dead (yes, again). You see a long queue leading up to what you belief must be heaven’s gate. You get in line. After a few minutes of waiting you reach the gate. Suddenly you hear loud sirens, balloons and confetti rain from above.

The gate keeper says that you are the 6666th visitor today! As a reward you get to choose your reincarnation form. Cool! You think for a moment and come to the conclusion that after an unhappy life as a math teacher you want to be happy – so you decide to become a happy number!

Which one will you pick ?

The mathematical definition for happy numbers can naturally be found on wikipedia.

The point is to implement the function isHappy() which takes a number and returns true if the number is happy.

/**
 * Check if a number is a 'happy number'
 *
 * @param number    number to be checked
 * @return          true if parameter is a happy number
 */
boolean isHappy (long number);

Read the rest of this entry »

Advertisements