Description:
In this challenge you are asked to create an alias that will return if a given number is "happy" or not.
Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers, while those that do not end in 1 are unhappy numbers.
Your alias should return
1 if the number is happy or
0 if unhappy. Always assume the correct input is passed to the alias i.e. a integer number >= 0. A number up to and including 1000 will be tested.
Example:
Lets take for example the number 7. First of all we square the number:
7^2 = 49
Then we square each single digit in the answer and add them together;
4^2 + 9^2 = 97
We keep repeating:
9^2 + 7^2 = 130
1^2 + 3^2 + 0^2 = 10
1^2 + 0^2 = 1 we have reached 1 therefore 7 is a happy number
Now lets take a look at an unhappy number 4:
4^2 = 16
1^2 + 6^2 = 37
3^2 + 7^2 = 58
3^2 + 7^2 = 89
8^2 + 9^2 = 145
1^2 + 4^2 + 5^2 = 42
4^2 + 2^2 = 20
2^2 + 0^2 = 4 --> we are back where we started and will now continue going in a loop.
Therefore 4 is not a happy number.
$ishappy(0) = 0
$ishappy(1) = 1
$ishappy(338) = 1
$ishappy(491) = 0
Rules:
Alias name must be 'ishappy'No dlls, coms, socketsOne submission per user.Script must give correct results after consecutive runs.
Testing conditions:
Alias will be run on mIRC v6.35 and loaded into the remotes section.Your code will be taken for EXACTLY as-is.Alias will be run on a mIRC with no variables set - a clean mIRC.