Based on the question How many positive integers < 1,000,000 contain the digit 2?. I'm looking for the most creative solution to count all the Integers from X
to Y
containing the Integer Z
. Z
can be from 0 to Y
.
Every found Integer only counts once, even if the integer Z
appears more often.
For example:
Z = 2
123 counts 1
22222 also counts 1
I will start with a really simple algorithm written in Java (because it's beloved by everyone):
public class Count {
public static void main(String[] args) {
int count = 0;
for (int i = Integer.parseInt(args[0]); i <= Integer.parseInt(args[1]); i++) {
if (Integer.toString(i).contains(args[2])) {
count++;
}
}
System.out.println(count);
}
}
if you run this with
java -jar Count.jar 0 1000000 2
you get this as the result:
468559
Because this problem is not hard to solve it's just a popularity-contest. Most upvoted answer posted by 28th of February wins!
N
can be123
and it would only match if the substring 123 exists? \$\endgroup\$