A number that equals twice the sum of its decimal digits
Riffing on "dix-huit ans aujoud'hui = 18 pounds!" from Frankarr, an australian blogger.
In the entry he mentions that "One fact about 18 which I really love is that 18, aside from 0, is the only number that equals twice the sum of its decimal digits - cool huh?". Now, being a geek I had to write a scratch program t prove that one way or the other, without further ado here it is:
for (int i = 0; i < int.MaxValue -1; i++)
{
string intValue = i.ToString();
int sumValue = 0;
foreach (char digit in intValue.ToCharArray())
{
sumValue += ((Convert.ToInt32(digit.ToString()))* 2);
}
if (sumValue == i)
{
Console.WriteLine("Value found: {0}", i);
}
int modulus = i % 100000;
if (modulus == 0)
{
Console.WriteLine(string.Format("{0}", i));
}
}
The second Console.WriteLine is just so that when running, I can see that the program hasn't frozen/crashed. And it's true, in all the numbers between 0 and int.MaxValue -1, there are no numbers other than 0 and 18 where his fact holds true. Geeky goodnesss!