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 nth 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!










share|improve this question


























    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 nth 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!










    share|improve this question
























      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 nth 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!










      share|improve this question













      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 nth 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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 43 mins ago









      maxb

      2,1781923




      2,1781923






















          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





          share|improve this answer




























            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





            share|improve this answer




























              up vote
              1
              down vote














              Jelly, 14 bytes



              ³RÆNṾ€ẇ€ṾȦ
              Ç1#


              Try it online!






              share|improve this answer





















                Your Answer





                StackExchange.ifUsing("editor", function () {
                return StackExchange.using("mathjaxEditing", function () {
                StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
                StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
                });
                });
                }, "mathjax-editing");

                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "200"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                convertImagesToLinks: false,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                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

























                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





                share|improve this answer

























                  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





                  share|improve this answer























                    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





                    share|improve this answer













                    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






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 19 mins ago









                    Bubbler

                    6,104759




                    6,104759






















                        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





                        share|improve this answer

























                          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





                          share|improve this answer























                            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





                            share|improve this answer













                            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






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 14 mins ago









                            Emigna

                            44.9k432136




                            44.9k432136






















                                up vote
                                1
                                down vote














                                Jelly, 14 bytes



                                ³RÆNṾ€ẇ€ṾȦ
                                Ç1#


                                Try it online!






                                share|improve this answer

























                                  up vote
                                  1
                                  down vote














                                  Jelly, 14 bytes



                                  ³RÆNṾ€ẇ€ṾȦ
                                  Ç1#


                                  Try it online!






                                  share|improve this answer























                                    up vote
                                    1
                                    down vote










                                    up vote
                                    1
                                    down vote










                                    Jelly, 14 bytes



                                    ³RÆNṾ€ẇ€ṾȦ
                                    Ç1#


                                    Try it online!






                                    share|improve this answer













                                    Jelly, 14 bytes



                                    ³RÆNṾ€ẇ€ṾȦ
                                    Ç1#


                                    Try it online!







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered 23 mins ago









                                    lirtosiast

                                    15.6k436105




                                    15.6k436105






























                                        draft saved

                                        draft discarded




















































                                        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.




                                        draft saved


                                        draft discarded














                                        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





















































                                        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







                                        Popular posts from this blog

                                        Михайлов, Христо

                                        Центральная группа войск

                                        Троллейбус