This is sequence A054261.
The \$n\$th prime containment number is the lowest number which contains the first \$n\$ prime numbers as substrings. For example, the number \$235\$ is the lowest number which contains the first 3 primes as substrings, making it the 3rd prime containment number.
It is trivial to figure out that the first four prime containment numbers are \$2\$, \$23\$, \$235\$ and \$2357\$, but then it gets more interesting. Since the next prime is 11, the next prime containment number is not \$235711\$, but it is \$112357\$ since it's defined as the smallest number with the property.
However, the real challenge comes when you go beyond 11. The next prime containment number is \$113257\$. Note that in this number, the substrings 11
and 13
are overlapping. The number 3
is also overlapping with the number 13
.
It is easy to prove that this sequence is increasing, since the next number needs to fulfill all criteria of the number before it, and have one more substring. However, the sequence is not strictly increasing, as is shown by the results for n=10
and n=11
.
Input
A single integer n>0
(I suppose you could also have it 0-indexed, then making n>=0
)
Output
Either the n
th prime containment number, or a list containing the first n
prime containment numbers.
The numbers I have found so far are:
1 => 2
2 => 23
3 => 235
4 => 2357
5 => 112357
6 => 113257
7 => 1131725
8 => 113171925
9 => 1131719235
10 => 113171923295
11 => 113171923295
12 => 1131719237295
Note that n = 10
and n = 11
are the same number, since \$113171923295\$ is the lowest number which contains all numbers \$[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]\$, but it also contains \$31\$.
Since this is marked code golf, get golfing! Brute force solutions are allowed, but your code has to work for any input in theory (meaning that you can't just concatenate the first n primes). Happy golfing!