Prime containment numbers (golf edition)
up vote
2
down vote
favorite
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, I do not know if the sequence if strictly increasing.
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!
code-golf math primes integer
add a comment |
up vote
2
down vote
favorite
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, I do not know if the sequence if strictly increasing.
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!
code-golf math primes integer
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
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, I do not know if the sequence if strictly increasing.
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!
code-golf math primes integer
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, I do not know if the sequence if strictly increasing.
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!
code-golf math primes integer
code-golf math primes integer
asked 43 mins ago
maxb
2,1781923
2,1781923
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
2
down vote
Jelly, 11 bytes
³ÆN€ẇ€µẠ$1#
Try it online!
Simple brute force. Not completely sure how #
's arity works, so there may be some room for improvement.
How it works
³ÆN€ẇ€µẠ$1# Main link. Input: Index n.
1# Find the first natural number N that satisfies:
³ÆN€ First n primes...
ẇ€ ...are substrings of N
µẠ$ All of them are true
add a comment |
up vote
2
down vote
05AB1E, 8 bytes
∞.ΔIÅpåP
Try it online!
Explanation
# from
∞ # a list of infinite positive integers
.Δ # find the first which satisfies the condition:
P # all
IÅp # of the first <input> prime numbers
å # are contained in the number
add a comment |
up vote
1
down vote
Jelly, 14 bytes
³RÆNṾ€ẇ€ṾȦ
Ç1#
Try it online!
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Jelly, 11 bytes
³ÆN€ẇ€µẠ$1#
Try it online!
Simple brute force. Not completely sure how #
's arity works, so there may be some room for improvement.
How it works
³ÆN€ẇ€µẠ$1# Main link. Input: Index n.
1# Find the first natural number N that satisfies:
³ÆN€ First n primes...
ẇ€ ...are substrings of N
µẠ$ All of them are true
add a comment |
up vote
2
down vote
Jelly, 11 bytes
³ÆN€ẇ€µẠ$1#
Try it online!
Simple brute force. Not completely sure how #
's arity works, so there may be some room for improvement.
How it works
³ÆN€ẇ€µẠ$1# Main link. Input: Index n.
1# Find the first natural number N that satisfies:
³ÆN€ First n primes...
ẇ€ ...are substrings of N
µẠ$ All of them are true
add a comment |
up vote
2
down vote
up vote
2
down vote
Jelly, 11 bytes
³ÆN€ẇ€µẠ$1#
Try it online!
Simple brute force. Not completely sure how #
's arity works, so there may be some room for improvement.
How it works
³ÆN€ẇ€µẠ$1# Main link. Input: Index n.
1# Find the first natural number N that satisfies:
³ÆN€ First n primes...
ẇ€ ...are substrings of N
µẠ$ All of them are true
Jelly, 11 bytes
³ÆN€ẇ€µẠ$1#
Try it online!
Simple brute force. Not completely sure how #
's arity works, so there may be some room for improvement.
How it works
³ÆN€ẇ€µẠ$1# Main link. Input: Index n.
1# Find the first natural number N that satisfies:
³ÆN€ First n primes...
ẇ€ ...are substrings of N
µẠ$ All of them are true
answered 19 mins ago
Bubbler
6,104759
6,104759
add a comment |
add a comment |
up vote
2
down vote
05AB1E, 8 bytes
∞.ΔIÅpåP
Try it online!
Explanation
# from
∞ # a list of infinite positive integers
.Δ # find the first which satisfies the condition:
P # all
IÅp # of the first <input> prime numbers
å # are contained in the number
add a comment |
up vote
2
down vote
05AB1E, 8 bytes
∞.ΔIÅpåP
Try it online!
Explanation
# from
∞ # a list of infinite positive integers
.Δ # find the first which satisfies the condition:
P # all
IÅp # of the first <input> prime numbers
å # are contained in the number
add a comment |
up vote
2
down vote
up vote
2
down vote
05AB1E, 8 bytes
∞.ΔIÅpåP
Try it online!
Explanation
# from
∞ # a list of infinite positive integers
.Δ # find the first which satisfies the condition:
P # all
IÅp # of the first <input> prime numbers
å # are contained in the number
05AB1E, 8 bytes
∞.ΔIÅpåP
Try it online!
Explanation
# from
∞ # a list of infinite positive integers
.Δ # find the first which satisfies the condition:
P # all
IÅp # of the first <input> prime numbers
å # are contained in the number
answered 14 mins ago
Emigna
44.9k432136
44.9k432136
add a comment |
add a comment |
up vote
1
down vote
Jelly, 14 bytes
³RÆNṾ€ẇ€ṾȦ
Ç1#
Try it online!
add a comment |
up vote
1
down vote
Jelly, 14 bytes
³RÆNṾ€ẇ€ṾȦ
Ç1#
Try it online!
add a comment |
up vote
1
down vote
up vote
1
down vote
Jelly, 14 bytes
³RÆNṾ€ẇ€ṾȦ
Ç1#
Try it online!
Jelly, 14 bytes
³RÆNṾ€ẇ€ṾȦ
Ç1#
Try it online!
answered 23 mins ago
lirtosiast
15.6k436105
15.6k436105
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f176823%2fprime-containment-numbers-golf-edition%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown