Ok, so this afternoon I watched the movie “Proof” – really good movie. In the movie, they talk about the number 1729, about how it is the smallest number expressible as the sum of two cubes in two different ways. It also is a natural number – when its digits are added together, produces a sum which, when multiplied by its reversed self, yields the original number.

Just for the helluva it, I decided to write a little program in C# to do this. It would be nice if there was an easier way to reverse strings in .NET, maybe there is and I just don’t know. Anyways, I love how movies can get you into things you never thought you would get into.. now I only wonder what I will code up when I get back from the bars..

using System;
using System.Collections.Generic;
using System.Text;
namespace NaturalNumbers
{
class Program
{
static void Main(string[] args)
{
// when its digits are added together, produces a sum which,
// when multiplied by its reversed self, yields the original number:
for (System.UInt64 i = 1; i < 9223372036854775808; i++)
{
string nums = i.ToString();
System.UInt64 sum = 0;
System.UInt64 product = 0;
// get the sum of each digit of the number
for (int b = 0; b < nums.Length; b++)
{
sum += System.Convert.ToUInt64(nums[b].ToString());
}
string nums2 = sum.ToString();
// reverse the sum
char[] temp = nums2.ToCharArray();
Array.Reverse(temp);
nums2 = new string(temp);
// multiply the sum times the reversed sum
product = sum * System.Convert.ToUInt64(nums2);
// if they equal we hit the jackpot
if (product == i)
{
Console.WriteLine(i.ToString() + " is a natural number");
}
if (i % 10000000 == 0)
{
Console.WriteLine(i.ToString());
}
}
}
}
}