Your condition should be to look for cycles.  There are only two
possibilities when continuously repeating the procedure - either you will
hit '1' (a happy number) or you will find a cycle.  In this case you've got
a cycle of only one number.

On Wed, May 26, 2010 at 8:14 AM, maverick gugu <[email protected]>wrote:

> Hi,
> Then if we consider 10 base 7: we'll always end up with 13 right?
> 10base7 = 13
> Square of Digits add to: 1^2 + 3^2 = 10
> Again 10base7 = 13
> it keeps going on n on.
>
> So i'm not able to put up a condition to stop this check. What condition
> should i put in the end to make this loop stop at a point.
> Is there any other better method? Can its complexity be reduced? I'm not
> able to understand the codes from the people who have solved.
>
> Can some one please give a nice algorithm for this? I've been breaking my
> head over this problem for way too long..
>
>
> Thanks,
> Maverick
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-codejam" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-code%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-code?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-codejam" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en.

Reply via email to