The Limber Lambda

Eric Smith’s technical musings

“Sharpen Up” Series: Episode 2

leave a comment »

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;
	}
}

Written by Eric Smith

November 5, 2008 at 4:05 PM

Posted in Fun

Leave a Reply