- The only digits that can be used are 3, 6 and 9.
- A specific digit can occur at most three times in the number.
- The number must be divisible by 9.
This is my following code:
for (int i = 0; i <= 9999; i=i+9)
{
if (Math.Ceiling(Math.Log10(i)) == 4)
{
if (i.ToString().Contains('3') && i.ToString().Contains('6') && i.ToString().Contains('9')&&!i.ToString().Contains('0'))
{
Console.WriteLine(i);
}
}
}
The issue with my code is restriction #2: A specific digit can occur at most three times in the number.
It is not printing out for example: 3339, which is also divisible by 9 and follows all the criteria, any suggestions?
Thank you