Euler Problem 92


Euler Problem 92

Investigating a square digits number chain with a surprising property.

Solution:

Implementacija jednostavna onako kao je u zadatku definisano:


static void Main(string[] args)
{
 long counter = 0;
 for (int i = 1; i < 10000000; i++)
 {
 if (IsArrivedAt89(i))
  counter++;
 }
 Console.WriteLine(counter);
 Console.Read();
}
static bool IsArrivedAt89(int n)
{
 if (n == 1)
  return false;
 else if (n == 89)
  return true;
 else
 return IsArrivedAt89(Next(n));
}
static int Next(int n)
{
 int value=0;
 char[] str = n.ToString().ToArray();
 for (int i = 0; i < str.Length; i++)
 {
  int temp=int.Parse(str[i].ToString());
  value += temp * temp;
 }
 return value;
}
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s