“Sharpen Up” Series: Episode 2
This one is an example of “trivial”. Problem description: find how many digits in a given number divide evenly into the number. This took me around about 2 minutes for a whopping 239 points out of 250. My solution:
public class DivisorDigits
{
public int howMany(int number)
{
int count = 0;
foreach (char c in number.ToString())
{
if (c == '0')
continue;
if (number % (c - '0') == 0)
{
count++;
}
}
return count;
}
}
leave a comment