Skip to content

anonymous /gist:4976509

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
namespace NineDigits
{
class Program
{
static void Main(string[] args)
{
var p = new Program();
while (true)
{
p.RunTest();
var text = Console.ReadLine();
if (text == "exit")
break;
}
}
public void RunTest()
{
Numbers = new List<long>();
Stopwatch sw = new Stopwatch();
sw.Start();
Calculate(0, 0);
sw.Stop();
decimal time = sw.ElapsedTicks / (decimal)Stopwatch.Frequency * 1000;
Console.WriteLine("Time: " + time);
}
public List<long> Numbers;
public void Calculate(long x, int len)
{
if (len > 9)
return;
int start = (x == 0) ? 1 : 0;
for(int i = start; i <= 9; i++)
{
var temp = x * 10 + i;
if (temp > 0 && temp % (len + 1) == 0)
{
if (len + 1 == 9)
Numbers.Add(temp);
else
Calculate(temp, len + 1);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.