This was an easy one.. at last!
http://projecteuler.net/index.php?section=problems&id=34
______________________
static void Main(string[] args)
{
long bigsum = 0;
for (long i = 3; i < 1000000; i++)
{
string s = i.ToString();
long sum = 0;
foreach (char c in s) //split up to chars
{
sum+= factorial(c-48); //convert from ASCII to numerical value of char (c)
if (sum > i) { break; }
}
if (sum == i) {bigsum += sum;
}
}
Console.WriteLine(bigsum);
Console.ReadLine();
}
static long factorial(long n)
{
long tot = 1;
for (long i = 1; i < n+1; i++)
{
tot *= i;
}
return tot;
}
No comments:
Post a Comment