using System.Collections.Generic;
public class HowManyNumbers
public static void Main()
Console.WriteLine(SelNumber(100, 3));
public static int SelNumber(int n, int d)
return Enumerable.Range(12, n - 12 + 1)
GetReversedDigits(i).Zip(
GetReversedDigits(i).Skip(1).Concat(new[]{0}),
.Take(i.ToString().Length - 1)
.All(x => x > 0 && x <= d))
public static IEnumerable<int> GetReversedDigits(int i)
return i.ToString().Reverse().Select(x => x - '0');