Fill the Bucket











up vote
8
down vote

favorite
2












Your task is to fill the bucket with numbers upto a given input.



Rules



Numbers occupy the leftmost position then rightmost, then leftmost and so on.



After overflow, the numbers start to gather around the bucket in a similar manner. They occupy position diagonally.



The examples should make it clear what the expected output is (Some rules are mentioned in the examples).



For more then 10, use the rightmost digit



Examples:



The bucket: 
| | or | |
| | | |
| | | |
| | | |
|------| |______|

input:1 (You can start from either 0 or 1)
output:
| | (There can be whitespace to the left even if there is no overflow
| | but the bucket must not be distorted.)
| |
|1 |
|------|

input:6
output:
| |
| |
| |
|135642|
|------|

input:8
output:
| |
| |
|7 8|
|135642|
|------|

input:23
output:
|913 20|
|357864|
|791208|
|135642|
|------|

input:27
output:
|913420|
|357864|
|791208|
|135642|
75|------|6

input:30
output:
|913420|
|357864|
|791208|
9|135642|0
75|------|68

input:40
output:
|913420|
|357864|
5|791208|6
939|135642|040
7175|------|6828

input:54 (Maximum input for start=1)
3|913420|4
13|357864|42
915|791208|620
7939|135642|0408
57175|------|68286


This is code-golf so shortest code wins.










share|improve this question




























    up vote
    8
    down vote

    favorite
    2












    Your task is to fill the bucket with numbers upto a given input.



    Rules



    Numbers occupy the leftmost position then rightmost, then leftmost and so on.



    After overflow, the numbers start to gather around the bucket in a similar manner. They occupy position diagonally.



    The examples should make it clear what the expected output is (Some rules are mentioned in the examples).



    For more then 10, use the rightmost digit



    Examples:



    The bucket: 
    | | or | |
    | | | |
    | | | |
    | | | |
    |------| |______|

    input:1 (You can start from either 0 or 1)
    output:
    | | (There can be whitespace to the left even if there is no overflow
    | | but the bucket must not be distorted.)
    | |
    |1 |
    |------|

    input:6
    output:
    | |
    | |
    | |
    |135642|
    |------|

    input:8
    output:
    | |
    | |
    |7 8|
    |135642|
    |------|

    input:23
    output:
    |913 20|
    |357864|
    |791208|
    |135642|
    |------|

    input:27
    output:
    |913420|
    |357864|
    |791208|
    |135642|
    75|------|6

    input:30
    output:
    |913420|
    |357864|
    |791208|
    9|135642|0
    75|------|68

    input:40
    output:
    |913420|
    |357864|
    5|791208|6
    939|135642|040
    7175|------|6828

    input:54 (Maximum input for start=1)
    3|913420|4
    13|357864|42
    915|791208|620
    7939|135642|0408
    57175|------|68286


    This is code-golf so shortest code wins.










    share|improve this question


























      up vote
      8
      down vote

      favorite
      2









      up vote
      8
      down vote

      favorite
      2






      2





      Your task is to fill the bucket with numbers upto a given input.



      Rules



      Numbers occupy the leftmost position then rightmost, then leftmost and so on.



      After overflow, the numbers start to gather around the bucket in a similar manner. They occupy position diagonally.



      The examples should make it clear what the expected output is (Some rules are mentioned in the examples).



      For more then 10, use the rightmost digit



      Examples:



      The bucket: 
      | | or | |
      | | | |
      | | | |
      | | | |
      |------| |______|

      input:1 (You can start from either 0 or 1)
      output:
      | | (There can be whitespace to the left even if there is no overflow
      | | but the bucket must not be distorted.)
      | |
      |1 |
      |------|

      input:6
      output:
      | |
      | |
      | |
      |135642|
      |------|

      input:8
      output:
      | |
      | |
      |7 8|
      |135642|
      |------|

      input:23
      output:
      |913 20|
      |357864|
      |791208|
      |135642|
      |------|

      input:27
      output:
      |913420|
      |357864|
      |791208|
      |135642|
      75|------|6

      input:30
      output:
      |913420|
      |357864|
      |791208|
      9|135642|0
      75|------|68

      input:40
      output:
      |913420|
      |357864|
      5|791208|6
      939|135642|040
      7175|------|6828

      input:54 (Maximum input for start=1)
      3|913420|4
      13|357864|42
      915|791208|620
      7939|135642|0408
      57175|------|68286


      This is code-golf so shortest code wins.










      share|improve this question















      Your task is to fill the bucket with numbers upto a given input.



      Rules



      Numbers occupy the leftmost position then rightmost, then leftmost and so on.



      After overflow, the numbers start to gather around the bucket in a similar manner. They occupy position diagonally.



      The examples should make it clear what the expected output is (Some rules are mentioned in the examples).



      For more then 10, use the rightmost digit



      Examples:



      The bucket: 
      | | or | |
      | | | |
      | | | |
      | | | |
      |------| |______|

      input:1 (You can start from either 0 or 1)
      output:
      | | (There can be whitespace to the left even if there is no overflow
      | | but the bucket must not be distorted.)
      | |
      |1 |
      |------|

      input:6
      output:
      | |
      | |
      | |
      |135642|
      |------|

      input:8
      output:
      | |
      | |
      |7 8|
      |135642|
      |------|

      input:23
      output:
      |913 20|
      |357864|
      |791208|
      |135642|
      |------|

      input:27
      output:
      |913420|
      |357864|
      |791208|
      |135642|
      75|------|6

      input:30
      output:
      |913420|
      |357864|
      |791208|
      9|135642|0
      75|------|68

      input:40
      output:
      |913420|
      |357864|
      5|791208|6
      939|135642|040
      7175|------|6828

      input:54 (Maximum input for start=1)
      3|913420|4
      13|357864|42
      915|791208|620
      7939|135642|0408
      57175|------|68286


      This is code-golf so shortest code wins.







      code-golf ascii-art






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 4 hours ago









      Arnauld

      71k688298




      71k688298










      asked 4 hours ago









      Vedant Kandoi

      953223




      953223






















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          4
          down vote














          JavaScript (Node.js), 145 bytes



          1-indexed.





          n=>`    g|EGIJHF|h
          e]|?ACDB@|^f
          c[U|9;=><:|V\d
          aYSO|357864|PTZb
          _WQMK|------|LNRX``.replace(/[^s|-]/g,c=>(x=Buffer(c)[0])<n+51?x%10:' ')


          Try it online!






          share|improve this answer




























            up vote
            0
            down vote














            Python 2, 170 bytes





            I=input()
            s=" u|SUWXVT|vn sk|MOQRPN|ltn qic|GIKLJH|djrn oga]|ACEFDB|^bhpnme_[Y|------|Z`fn"
            i=1
            exec"s=s.replace(chr(64+i),[`i%10`,' '][i>I]);i+=1;"*55
            print s


            Try it online!






            share|improve this answer




























              up vote
              0
              down vote













              Java 10, 168 bytes





              n->"    g|EGIJHF|hn   e]|?ACDB@|^fn  c[U|9;=><:|V\dn aYSO|357864|PTZbn_WQMK|------|LNRX`".chars().forEach(c->System.out.print(c<46|c==124?(char)c:c<n+51?c%10:" "))


              Port of @Arnauld's JavaScript answer (so also 1-indexed, and outputting - as bottom). If you like this answer, make sure to upvote him as well!



              Try it online.



              Explanation:



              n->                      // Method with integer parameter and no return-type
              " g|EGIJHF|hn e]|?ACDB@|^fn c[U|9;=><:|V\dn aYSO|357864|PTZbn_WQMK|------|LNRX`"
              // String containing the bucket and magic string
              .chars().forEach(c-> // Loop over the characters (as integers)
              System.out.print( // Print:
              c<46|c==124? // If the character is "n", " ", "-", or "|":
              (char)c // Output the character as is
              :c<n+51? // Else-if the character value is smaller than the input + 51:
              c%10 // Output a digit: the character value modulo-9
              : // Else:
              " ")) // Output a space




              share





















                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%2f177365%2ffill-the-bucket%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
                4
                down vote














                JavaScript (Node.js), 145 bytes



                1-indexed.





                n=>`    g|EGIJHF|h
                e]|?ACDB@|^f
                c[U|9;=><:|V\d
                aYSO|357864|PTZb
                _WQMK|------|LNRX``.replace(/[^s|-]/g,c=>(x=Buffer(c)[0])<n+51?x%10:' ')


                Try it online!






                share|improve this answer

























                  up vote
                  4
                  down vote














                  JavaScript (Node.js), 145 bytes



                  1-indexed.





                  n=>`    g|EGIJHF|h
                  e]|?ACDB@|^f
                  c[U|9;=><:|V\d
                  aYSO|357864|PTZb
                  _WQMK|------|LNRX``.replace(/[^s|-]/g,c=>(x=Buffer(c)[0])<n+51?x%10:' ')


                  Try it online!






                  share|improve this answer























                    up vote
                    4
                    down vote










                    up vote
                    4
                    down vote










                    JavaScript (Node.js), 145 bytes



                    1-indexed.





                    n=>`    g|EGIJHF|h
                    e]|?ACDB@|^f
                    c[U|9;=><:|V\d
                    aYSO|357864|PTZb
                    _WQMK|------|LNRX``.replace(/[^s|-]/g,c=>(x=Buffer(c)[0])<n+51?x%10:' ')


                    Try it online!






                    share|improve this answer













                    JavaScript (Node.js), 145 bytes



                    1-indexed.





                    n=>`    g|EGIJHF|h
                    e]|?ACDB@|^f
                    c[U|9;=><:|V\d
                    aYSO|357864|PTZb
                    _WQMK|------|LNRX``.replace(/[^s|-]/g,c=>(x=Buffer(c)[0])<n+51?x%10:' ')


                    Try it online!







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 3 hours ago









                    Arnauld

                    71k688298




                    71k688298






















                        up vote
                        0
                        down vote














                        Python 2, 170 bytes





                        I=input()
                        s=" u|SUWXVT|vn sk|MOQRPN|ltn qic|GIKLJH|djrn oga]|ACEFDB|^bhpnme_[Y|------|Z`fn"
                        i=1
                        exec"s=s.replace(chr(64+i),[`i%10`,' '][i>I]);i+=1;"*55
                        print s


                        Try it online!






                        share|improve this answer

























                          up vote
                          0
                          down vote














                          Python 2, 170 bytes





                          I=input()
                          s=" u|SUWXVT|vn sk|MOQRPN|ltn qic|GIKLJH|djrn oga]|ACEFDB|^bhpnme_[Y|------|Z`fn"
                          i=1
                          exec"s=s.replace(chr(64+i),[`i%10`,' '][i>I]);i+=1;"*55
                          print s


                          Try it online!






                          share|improve this answer























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote










                            Python 2, 170 bytes





                            I=input()
                            s=" u|SUWXVT|vn sk|MOQRPN|ltn qic|GIKLJH|djrn oga]|ACEFDB|^bhpnme_[Y|------|Z`fn"
                            i=1
                            exec"s=s.replace(chr(64+i),[`i%10`,' '][i>I]);i+=1;"*55
                            print s


                            Try it online!






                            share|improve this answer













                            Python 2, 170 bytes





                            I=input()
                            s=" u|SUWXVT|vn sk|MOQRPN|ltn qic|GIKLJH|djrn oga]|ACEFDB|^bhpnme_[Y|------|Z`fn"
                            i=1
                            exec"s=s.replace(chr(64+i),[`i%10`,' '][i>I]);i+=1;"*55
                            print s


                            Try it online!







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 3 hours ago









                            TFeld

                            13.9k21240




                            13.9k21240






















                                up vote
                                0
                                down vote













                                Java 10, 168 bytes





                                n->"    g|EGIJHF|hn   e]|?ACDB@|^fn  c[U|9;=><:|V\dn aYSO|357864|PTZbn_WQMK|------|LNRX`".chars().forEach(c->System.out.print(c<46|c==124?(char)c:c<n+51?c%10:" "))


                                Port of @Arnauld's JavaScript answer (so also 1-indexed, and outputting - as bottom). If you like this answer, make sure to upvote him as well!



                                Try it online.



                                Explanation:



                                n->                      // Method with integer parameter and no return-type
                                " g|EGIJHF|hn e]|?ACDB@|^fn c[U|9;=><:|V\dn aYSO|357864|PTZbn_WQMK|------|LNRX`"
                                // String containing the bucket and magic string
                                .chars().forEach(c-> // Loop over the characters (as integers)
                                System.out.print( // Print:
                                c<46|c==124? // If the character is "n", " ", "-", or "|":
                                (char)c // Output the character as is
                                :c<n+51? // Else-if the character value is smaller than the input + 51:
                                c%10 // Output a digit: the character value modulo-9
                                : // Else:
                                " ")) // Output a space




                                share

























                                  up vote
                                  0
                                  down vote













                                  Java 10, 168 bytes





                                  n->"    g|EGIJHF|hn   e]|?ACDB@|^fn  c[U|9;=><:|V\dn aYSO|357864|PTZbn_WQMK|------|LNRX`".chars().forEach(c->System.out.print(c<46|c==124?(char)c:c<n+51?c%10:" "))


                                  Port of @Arnauld's JavaScript answer (so also 1-indexed, and outputting - as bottom). If you like this answer, make sure to upvote him as well!



                                  Try it online.



                                  Explanation:



                                  n->                      // Method with integer parameter and no return-type
                                  " g|EGIJHF|hn e]|?ACDB@|^fn c[U|9;=><:|V\dn aYSO|357864|PTZbn_WQMK|------|LNRX`"
                                  // String containing the bucket and magic string
                                  .chars().forEach(c-> // Loop over the characters (as integers)
                                  System.out.print( // Print:
                                  c<46|c==124? // If the character is "n", " ", "-", or "|":
                                  (char)c // Output the character as is
                                  :c<n+51? // Else-if the character value is smaller than the input + 51:
                                  c%10 // Output a digit: the character value modulo-9
                                  : // Else:
                                  " ")) // Output a space




                                  share























                                    up vote
                                    0
                                    down vote










                                    up vote
                                    0
                                    down vote









                                    Java 10, 168 bytes





                                    n->"    g|EGIJHF|hn   e]|?ACDB@|^fn  c[U|9;=><:|V\dn aYSO|357864|PTZbn_WQMK|------|LNRX`".chars().forEach(c->System.out.print(c<46|c==124?(char)c:c<n+51?c%10:" "))


                                    Port of @Arnauld's JavaScript answer (so also 1-indexed, and outputting - as bottom). If you like this answer, make sure to upvote him as well!



                                    Try it online.



                                    Explanation:



                                    n->                      // Method with integer parameter and no return-type
                                    " g|EGIJHF|hn e]|?ACDB@|^fn c[U|9;=><:|V\dn aYSO|357864|PTZbn_WQMK|------|LNRX`"
                                    // String containing the bucket and magic string
                                    .chars().forEach(c-> // Loop over the characters (as integers)
                                    System.out.print( // Print:
                                    c<46|c==124? // If the character is "n", " ", "-", or "|":
                                    (char)c // Output the character as is
                                    :c<n+51? // Else-if the character value is smaller than the input + 51:
                                    c%10 // Output a digit: the character value modulo-9
                                    : // Else:
                                    " ")) // Output a space




                                    share












                                    Java 10, 168 bytes





                                    n->"    g|EGIJHF|hn   e]|?ACDB@|^fn  c[U|9;=><:|V\dn aYSO|357864|PTZbn_WQMK|------|LNRX`".chars().forEach(c->System.out.print(c<46|c==124?(char)c:c<n+51?c%10:" "))


                                    Port of @Arnauld's JavaScript answer (so also 1-indexed, and outputting - as bottom). If you like this answer, make sure to upvote him as well!



                                    Try it online.



                                    Explanation:



                                    n->                      // Method with integer parameter and no return-type
                                    " g|EGIJHF|hn e]|?ACDB@|^fn c[U|9;=><:|V\dn aYSO|357864|PTZbn_WQMK|------|LNRX`"
                                    // String containing the bucket and magic string
                                    .chars().forEach(c-> // Loop over the characters (as integers)
                                    System.out.print( // Print:
                                    c<46|c==124? // If the character is "n", " ", "-", or "|":
                                    (char)c // Output the character as is
                                    :c<n+51? // Else-if the character value is smaller than the input + 51:
                                    c%10 // Output a digit: the character value modulo-9
                                    : // Else:
                                    " ")) // Output a space





                                    share











                                    share


                                    share










                                    answered 7 mins ago









                                    Kevin Cruijssen

                                    35.1k554185




                                    35.1k554185






























                                        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%2f177365%2ffill-the-bucket%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

                                        What visual should I use to simply compare current year value vs last year in Power BI desktop

                                        Alexandru Averescu

                                        Trompette piccolo