Happy numbers script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
leron
Forum Newbie
Posts: 2
Joined: Wed Nov 24, 2010 2:16 am

Happy numbers script

Post by leron »

Hello.I have a relatively simple question but if you could help me it would be appreciated.I need a script which have a submit form, and after submiting it should check if the number submited by the user is happy or not.The definition for happy numbers is here :
http://en.wikipedia.org/wiki/Happy_number
Every new number from the current check should be saved in array and call back later if needed, but first thing first, If someone could help me with the script for checking if the number is happy or not would be more than enough to begin with.
Thanks
Leron
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Happy numbers script

Post by requinix »

1. Figure out how long the number is, in digits.
2. Look at each digit.
3. Add its square to a counter.
4. ???
5. Profit.
leron
Forum Newbie
Posts: 2
Joined: Wed Nov 24, 2010 2:16 am

Re: Happy numbers script

Post by leron »

That really helps.... :banghead:
Post Reply