# Small Basic – The Happy Number Challenge

As part of LitDev's December Challenges, Nonki suggested this Happy Number challenge:

"Calculate happy numbers below 1000."

Math Man wasted no time in contributing this program:

Math Man's Happy Number Checker (click to try it out!)

Here is what it looks like (just an image):

Now that's a poor, sad number! Bonus points to Math Man for a little humor. =^)

What do you think of the challenge?

- Tall Basic Ed

1. Math Man says:

I thought it was a good challenge because the check for happy numbers was recursive, so we had to be able to contain that recursion while still providing the correct answer to whether that was a happy number or not. The 6 smallest happy numbers are 1, 7, 10, 13, 19, and 23.

2. Math Man says:

Please note, however, that if you enter '0' in the text box, it will crash. I will fix that as soon as I can.

3. Math Man says:

Ed, can you update the program link to smallbasic.com/program It just contains a minor bug fix. Thanks.

4. Math Man says:

Sorry, when I put the link at the end of the sentence, it thought the question mark was part of the link. Here's the link: smallbasic.com/program

5. Math Man, I updated the link.

Thanks!

6. Ha, Ha, Ha

21122012 – End Of World – is Happy.

There is not going to be an end of world. ðŸ™‚

7. @Math Man,

You could do this app easier. Every digit is an character and the Text.SubString() for every character in text string: power up twice x * x and add to accumulator. Repeat, until accumulator is >=0 and <9. If accumulator = 1: happy, other: sad.

accum = 0

string = …

for every charcter in string

accum = accum + (character * character)

'''''''''''''''' a character is a single digit, so only it's lenght is 1.

end for every

string = accum (Small Basic will make a string out of accum)

if accum > 9

repeat from the beginning, preserve the string

endif

if accum < 9  then

if accum = then

-> HAPPY

else

endif

endif

8. Math Man says:

@ logic thinker

Yes. That is actually kind of what I did.

9. @Math Man

Of course, I didn't mean to teach You. ðŸ™‚

But I just wanted to mention that the problem about determining happy numbers is to repeat an action on a sequence until the length of items making the sequence = 1.

Happy Holidays!

10. Logic Thinker,

You said, "There is not going to be an end of world."

Well, if it ended, would you know you were wrong? =^)

Thanks to both of you. Good discussion.