Background
For the purpose of this challenge, all numbers and their string representations are assumed to be in decimal (base 10). I tried to find proper terminology for this challenge, but I do not think there is any, so I made it up.
A self-replicating number is a number that appears as a substring in any of its multiples up to and including its square, excluding itself. An \$n\$-order self-replicating number appears as a substring in exactly \$n\$ multiples of itself up to its square, including itself. All numbers are at least 1st-order self-replicating numbers, because they appear as a substring in their first multiple (1 times the number).
For example: 5 is a 3rd-order self-replicating number, because it appears 3 times in the multiples of itself up to its square: 5, 10, 15, 20, 25. On the other hand, 4 is a 1st-order self-replicating number, because it appears only once: 4, 8, 12, 16.
There are only 6 1st-order replicators, because numbers will always have a self-replicator order \$\geq\lfloor\log_{10}(x)\rfloor+1\$, where \$x\$ is the number, as multiples of the number and any power of ten are guaranteed to have the number as a substring. Because of this property of self-replicating numbers, the series of \$n\$-order self-replicating numbers cannot ever be an infinite series. The last possible \$n\$-order self-replicating number is \$10^n-1\$.
The Challenge
Your task is to write a program which takes two integers, \$m\$ and \$n\$, and does one of the following:
- return the first \$m\$ \$n\$-order self-replicating numbers \$or\$
- return the \$m^{th}\$ \$n\$-order self-replicating number (0 or 1-indexed, your choice) \$or\$
- output the series of numbers that are either \$m\$-order or \$n\$-order self-replicating numbers. You may treat this series as if it were infinite; in other words, your code is not required to halt - it'd be very cool if it did, though. \$or\$
- By popular demand, and because the previous option was a source of valid misinterpretation, you may now instead take a single integer, \$n\$, and output the series of \$n\$-order self-replicating numbers. As with the last option, you may treat the series as if it were infinite.
Rules
- You are allowed undefined behavior for values of \$m\leq0\$ or \$n\leq0\$.
- Your code is not required to halt if the next number in the sequence does not exist. For example: if you chose either of the first two output options and your code receives \$m=7, n=1\$ as input, a 7th 1st-order self-replicating number will never be found because no 1st-order self-replicating numbers higher than 9 exist.
- Standard loopholes forbidden.
- This is code-golf, shortest program in bytes for each language wins.
Test Cases
\$m\$ | \$n\$ | Output |
---|---|---|
5 | 0 | undefined |
6 | 1 | 1,2,3,4,7,9 |
7 | 1 | 1,2,3,4,7,9 \$or\$ undefined |
20 | 2 | 6,8,10,11,12,13,14,15,16,17,18,19,21,22,23,24,26,27,29,31 |
30 | 4 | 30,45,48,52,55,59,68,69,82,94,110,115,122,128,130,136,137,139,144,145,152,168,170,171,176,177,184,187,190,192 |
10 | 38 | 650,3520,3680,3920,6050,6350,6840,7640,7880,7960 |
3 | 101 | 7125,8900,9920 |
1 | 2778 | 5000 |