Fill the Bucket












14














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
























  • What do you exactly mean by "you can start from either 0 or 1"? May the sequence of digits itself be 0-indexed (i.e. |024531| for $n=6$) or only the input?
    – Arnauld
    Dec 11 '18 at 18:37












  • @Arnauld, yes, the sequence may start from 0
    – Vedant Kandoi
    Dec 11 '18 at 19:33










  • This is one of the better coding challenges for code golf that I have seen here!
    – Michael Karas
    Dec 12 '18 at 11:01
















14














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
























  • What do you exactly mean by "you can start from either 0 or 1"? May the sequence of digits itself be 0-indexed (i.e. |024531| for $n=6$) or only the input?
    – Arnauld
    Dec 11 '18 at 18:37












  • @Arnauld, yes, the sequence may start from 0
    – Vedant Kandoi
    Dec 11 '18 at 19:33










  • This is one of the better coding challenges for code golf that I have seen here!
    – Michael Karas
    Dec 12 '18 at 11:01














14












14








14


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 Dec 11 '18 at 12:11









Arnauld

72.6k689306




72.6k689306










asked Dec 11 '18 at 11:52









Vedant Kandoi

1,073226




1,073226












  • What do you exactly mean by "you can start from either 0 or 1"? May the sequence of digits itself be 0-indexed (i.e. |024531| for $n=6$) or only the input?
    – Arnauld
    Dec 11 '18 at 18:37












  • @Arnauld, yes, the sequence may start from 0
    – Vedant Kandoi
    Dec 11 '18 at 19:33










  • This is one of the better coding challenges for code golf that I have seen here!
    – Michael Karas
    Dec 12 '18 at 11:01


















  • What do you exactly mean by "you can start from either 0 or 1"? May the sequence of digits itself be 0-indexed (i.e. |024531| for $n=6$) or only the input?
    – Arnauld
    Dec 11 '18 at 18:37












  • @Arnauld, yes, the sequence may start from 0
    – Vedant Kandoi
    Dec 11 '18 at 19:33










  • This is one of the better coding challenges for code golf that I have seen here!
    – Michael Karas
    Dec 12 '18 at 11:01
















What do you exactly mean by "you can start from either 0 or 1"? May the sequence of digits itself be 0-indexed (i.e. |024531| for $n=6$) or only the input?
– Arnauld
Dec 11 '18 at 18:37






What do you exactly mean by "you can start from either 0 or 1"? May the sequence of digits itself be 0-indexed (i.e. |024531| for $n=6$) or only the input?
– Arnauld
Dec 11 '18 at 18:37














@Arnauld, yes, the sequence may start from 0
– Vedant Kandoi
Dec 11 '18 at 19:33




@Arnauld, yes, the sequence may start from 0
– Vedant Kandoi
Dec 11 '18 at 19:33












This is one of the better coding challenges for code golf that I have seen here!
– Michael Karas
Dec 12 '18 at 11:01




This is one of the better coding challenges for code golf that I have seen here!
– Michael Karas
Dec 12 '18 at 11:01










6 Answers
6






active

oldest

votes


















9















JavaScript (Node.js),  145  143 bytes



A hard-coded pattern (see here for more maths).



1-indexed.





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


Try it online!



Saved 2 bytes thanks to @tsh






share|improve this answer



















  • 1




    /[^s|-]/ -> /[0-z]/
    – tsh
    Dec 12 '18 at 2:40










  • @tsh D'oh! I totally missed this simplification. Thank you!
    – Arnauld
    Dec 12 '18 at 10:15



















7














JavaScript (ES6),  144 ... 139  137 bytes



A mathematical approach (see here for less maths).



0-indexed.



n=>(y=4,g=x=>~y?(X=x>8?17-x:x,k=X<y?g:X<5?24-(z=4+y-X)*~z+y*2:y*6+X*2-18,~X?X^5?k<0?'-':(k+=x>8)<n?k%10:' ':'|':`
`)+g(~X?-~x:!y--):'')()


Try it online!



How?



The output is built character by character, with $y$ decreasing from $4$ to $0$ and $x$ increasing from $0$ to $18$ on each row.



We define:



$$X=begin{cases}x&text{if }xle 8\17-x&text{if }x>8end{cases}$$



By writing the full values rather than just the unit digits, we get the following table:



 x |  0  1  2  3  4  5  6  7  8 |  9 10 11 12 13 14 15 16 17 18
X | 0 1 2 3 4 5 6 7 8 | 8 7 6 5 4 3 2 1 0 -1
---+----------------------------+-------------------------------
4 | .. .. .. .. 52 || 18 20 22 | 23 21 19 || 53 .. .. .. .. n
3 | .. .. .. 50 42 || 12 14 16 | 17 15 13 || 43 51 .. .. .. n
2 | .. .. 48 40 34 || 6 8 10 | 11 9 7 || 35 41 49 .. .. n
1 | .. 46 38 32 28 || 0 2 4 | 5 3 1 || 29 33 39 47 .. n
0 | 44 36 30 26 24 || -- -- -- | -- -- -- || 25 27 31 37 45 n


This table is essentially symmetric across the y-axis, except that the values on the left side are even and the values on the right side are their odd counterparts.



We define:



$$k=begin{cases}24+(4+y-X)(5+y-X)+2y&text{if }X<5\6y+2X-18&text{if }X>5end{cases}$$



$$k'=begin{cases}k&text{if }xle 8\k+1&text{if }x>8end{cases}$$



And for each cell, we append:




  • a linefeed if $X=-1$

  • a pipe if $X=5$

  • a hyphen if $k<0$

  • a space if $X<y$ or $k'>n$ (where $n$ is the input)


  • $k' bmod 10$ otherwise


Commented



n => (                                // main function taking n
y = 4, // start with y = 4
g = x => // g = recursive function taking x
~y ? // if y is not equal to -1:
( X = x > 8 ? 17 - x : x, // compute X
k = X < y ? // if X is less than y:
g // set k to a non-numeric value
: // else:
X < 5 ? // if X is less than 5:
24 - (z = 4 + y - X) * ~z // apply the 'side numbers' formula
+ y * 2 //
: // else:
y * 6 + X * 2 - 18, // apply the 'middle numbers' formula
~X ? // if X is not equal to -1:
X ^ 5 ? // if X is not equal to 5:
k < 0 ? // if k is less than 0:
'-' // append a hyphen
: // else:
(k += x > 8) < n ? // update k to k'; if it's less than n:
k % 10 // append the unit digit of k'
: // else:
' ' // append a space
: // else (X = 5):
'|' // append a pipe
: // else (X = -1):
`n` // append a linefeed
) //
+ g(~X ? -~x : !y--) // update x and y, and do a recursive call
: // else (y = -1):
'' // stop recursion
)() // initial call to g with x undefined





share|improve this answer































    3















    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





























      3














      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|improve this answer





























        1















        6502 machine code (C64), 130 bytes



        00 C0 20 9B B7 A9 C0 65 65 85 FB A2 00 BD 2B C0 F0 1A 10 12 C5 FB 90 04 A9 20
        D0 0A 69 70 C9 3A 90 04 E9 0A B0 F8 20 D2 FF E8 D0 E1 60 20 20 20 20 F5 7D D3
        D5 D7 D8 D6 D4 7D F6 0D 20 20 20 F3 EB 7D CD CF D1 D2 D0 CE 7D EC F4 0D 20 20
        F1 E9 E3 7D C7 C9 CB CC CA C8 7D E4 EA F2 0D 20 EF E7 E1 DD 7D C1 C3 C5 C6 C4
        C2 7D DE E2 E8 F0 0D ED E5 DF DB D9 7D 2D 2D 2D 2D 2D 2D 7D DA DC E0 E6 EE 00


        This uses a modified version of the "preformatted" approach of some other answers. It contains a full string of the bucket, but the digits are replaced by values starting from 0xC1, while any characters for direct printing are in the range 0x01-0x7f.



        The C64 charset doesn't include a pipe (|) character, it's therefore replaced with the similar-looking PETSCII character 0x7d.



        Online demo



        Usage: SYS49152,[n] (1-indexed, e.g. SYS49152,54 for the full output)



        Commented disassembly:



                 00 C0       .WORD $C000        ; load address
        .C:c000 20 9B B7 JSR $B79B ; get unsigned byte from commandline
        .C:c003 A9 C0 LDA #$C0 ; add #$C0 (+ carry = #$C1) ...
        .C:c005 65 65 ADC $65 ; ... to parameter
        .C:c007 85 FB STA $FB ; and store in $FB
        .C:c009 A2 00 LDX #$00 ; loop index
        .C:c00b .loop:
        .C:c00b BD 2B C0 LDA .bucket,X ; loop over encoded string
        .C:c00e F0 1A BEQ .done ; null-terminator -> done
        .C:c010 10 12 BPL .out ; positive (bit 7 clear) -> output
        .C:c012 C5 FB CMP $FB ; compare with parameter+#$C1
        .C:c014 90 04 BCC .digit ; smaller -> convert to digit
        .C:c016 A9 20 LDA #$20 ; otherwise load space character
        .C:c018 D0 0A BNE .out ; and output
        .C:c01a .digit:
        .C:c01a 69 70 ADC #$70 ; add offset to '0' (#$30)
        .C:c01c .check:
        .C:c01c C9 3A CMP #$3A ; greater than '9' (#$39) ?
        .C:c01e 90 04 BCC .out ; no -> to output
        .C:c020 E9 0A SBC #$0A ; otherwise subtract 10 (#$a)
        .C:c022 B0 F8 BCS .check ; and check again
        .C:c024 .out:
        .C:c024 20 D2 FF JSR $FFD2 ; output character
        .C:c027 E8 INX ; next index
        .C:c028 D0 E1 BNE .loop ; and repeat loop
        .C:c02a .done:
        .C:c02a 60 RTS ; exit ....
        .C:c02b .bucket:
        .C:c02b 20 20 20 [...] ; "encoded" string for bucket





        share|improve this answer





























          0















          Charcoal, 64 bytes



          Nθ³↑⁵‖M←F²«‖J⁻³ι±¹F⊘⁺θ¬ι«↖I﹪⁺⊗κ⊕ιχM§”)⊟E≡≦⌈▷⊖ü∕”꧔)⊟&hXτtD(λM”κ


          Try it online! Link is to verbose version of code. Explanation:



          Nθ


          Input the number.



          ³↑⁵‖M←


          Draw half of the bucket and then mirror it to complete the bucket.



          F²«


          Loop for each side of the bucket.



          ‖J⁻³ι±¹


          Reflect the bucket so that we can draw in a consistent direction on both loops, and jump to the position of the first digit on that side of the bucket.



          F⊘⁺θ¬ι«


          Loop over the number of digits on that side of the bucket.



          ↖I﹪⁺⊗κ⊕ιχ


          Print the next digit and move the cursor up and left.



          M§”)⊟E≡≦⌈▷⊖ü∕”꧔)⊟&hXτtD(λM”κ


          Adjust the cursor position by reading the offsets from two compressed strings, 003003003005203004000500 (horizontal offsets) and 11011011011510200300040000 (vertical offsets). These offsets take the above cursor movement into account which conveniently means that they never have to be negative.






          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',
            autoActivateHeartbeat: false,
            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

























            6 Answers
            6






            active

            oldest

            votes








            6 Answers
            6






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            9















            JavaScript (Node.js),  145  143 bytes



            A hard-coded pattern (see here for more maths).



            1-indexed.





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


            Try it online!



            Saved 2 bytes thanks to @tsh






            share|improve this answer



















            • 1




              /[^s|-]/ -> /[0-z]/
              – tsh
              Dec 12 '18 at 2:40










            • @tsh D'oh! I totally missed this simplification. Thank you!
              – Arnauld
              Dec 12 '18 at 10:15
















            9















            JavaScript (Node.js),  145  143 bytes



            A hard-coded pattern (see here for more maths).



            1-indexed.





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


            Try it online!



            Saved 2 bytes thanks to @tsh






            share|improve this answer



















            • 1




              /[^s|-]/ -> /[0-z]/
              – tsh
              Dec 12 '18 at 2:40










            • @tsh D'oh! I totally missed this simplification. Thank you!
              – Arnauld
              Dec 12 '18 at 10:15














            9












            9








            9







            JavaScript (Node.js),  145  143 bytes



            A hard-coded pattern (see here for more maths).



            1-indexed.





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


            Try it online!



            Saved 2 bytes thanks to @tsh






            share|improve this answer















            JavaScript (Node.js),  145  143 bytes



            A hard-coded pattern (see here for more maths).



            1-indexed.





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


            Try it online!



            Saved 2 bytes thanks to @tsh







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 12 '18 at 10:12

























            answered Dec 11 '18 at 12:44









            Arnauld

            72.6k689306




            72.6k689306








            • 1




              /[^s|-]/ -> /[0-z]/
              – tsh
              Dec 12 '18 at 2:40










            • @tsh D'oh! I totally missed this simplification. Thank you!
              – Arnauld
              Dec 12 '18 at 10:15














            • 1




              /[^s|-]/ -> /[0-z]/
              – tsh
              Dec 12 '18 at 2:40










            • @tsh D'oh! I totally missed this simplification. Thank you!
              – Arnauld
              Dec 12 '18 at 10:15








            1




            1




            /[^s|-]/ -> /[0-z]/
            – tsh
            Dec 12 '18 at 2:40




            /[^s|-]/ -> /[0-z]/
            – tsh
            Dec 12 '18 at 2:40












            @tsh D'oh! I totally missed this simplification. Thank you!
            – Arnauld
            Dec 12 '18 at 10:15




            @tsh D'oh! I totally missed this simplification. Thank you!
            – Arnauld
            Dec 12 '18 at 10:15











            7














            JavaScript (ES6),  144 ... 139  137 bytes



            A mathematical approach (see here for less maths).



            0-indexed.



            n=>(y=4,g=x=>~y?(X=x>8?17-x:x,k=X<y?g:X<5?24-(z=4+y-X)*~z+y*2:y*6+X*2-18,~X?X^5?k<0?'-':(k+=x>8)<n?k%10:' ':'|':`
            `)+g(~X?-~x:!y--):'')()


            Try it online!



            How?



            The output is built character by character, with $y$ decreasing from $4$ to $0$ and $x$ increasing from $0$ to $18$ on each row.



            We define:



            $$X=begin{cases}x&text{if }xle 8\17-x&text{if }x>8end{cases}$$



            By writing the full values rather than just the unit digits, we get the following table:



             x |  0  1  2  3  4  5  6  7  8 |  9 10 11 12 13 14 15 16 17 18
            X | 0 1 2 3 4 5 6 7 8 | 8 7 6 5 4 3 2 1 0 -1
            ---+----------------------------+-------------------------------
            4 | .. .. .. .. 52 || 18 20 22 | 23 21 19 || 53 .. .. .. .. n
            3 | .. .. .. 50 42 || 12 14 16 | 17 15 13 || 43 51 .. .. .. n
            2 | .. .. 48 40 34 || 6 8 10 | 11 9 7 || 35 41 49 .. .. n
            1 | .. 46 38 32 28 || 0 2 4 | 5 3 1 || 29 33 39 47 .. n
            0 | 44 36 30 26 24 || -- -- -- | -- -- -- || 25 27 31 37 45 n


            This table is essentially symmetric across the y-axis, except that the values on the left side are even and the values on the right side are their odd counterparts.



            We define:



            $$k=begin{cases}24+(4+y-X)(5+y-X)+2y&text{if }X<5\6y+2X-18&text{if }X>5end{cases}$$



            $$k'=begin{cases}k&text{if }xle 8\k+1&text{if }x>8end{cases}$$



            And for each cell, we append:




            • a linefeed if $X=-1$

            • a pipe if $X=5$

            • a hyphen if $k<0$

            • a space if $X<y$ or $k'>n$ (where $n$ is the input)


            • $k' bmod 10$ otherwise


            Commented



            n => (                                // main function taking n
            y = 4, // start with y = 4
            g = x => // g = recursive function taking x
            ~y ? // if y is not equal to -1:
            ( X = x > 8 ? 17 - x : x, // compute X
            k = X < y ? // if X is less than y:
            g // set k to a non-numeric value
            : // else:
            X < 5 ? // if X is less than 5:
            24 - (z = 4 + y - X) * ~z // apply the 'side numbers' formula
            + y * 2 //
            : // else:
            y * 6 + X * 2 - 18, // apply the 'middle numbers' formula
            ~X ? // if X is not equal to -1:
            X ^ 5 ? // if X is not equal to 5:
            k < 0 ? // if k is less than 0:
            '-' // append a hyphen
            : // else:
            (k += x > 8) < n ? // update k to k'; if it's less than n:
            k % 10 // append the unit digit of k'
            : // else:
            ' ' // append a space
            : // else (X = 5):
            '|' // append a pipe
            : // else (X = -1):
            `n` // append a linefeed
            ) //
            + g(~X ? -~x : !y--) // update x and y, and do a recursive call
            : // else (y = -1):
            '' // stop recursion
            )() // initial call to g with x undefined





            share|improve this answer




























              7














              JavaScript (ES6),  144 ... 139  137 bytes



              A mathematical approach (see here for less maths).



              0-indexed.



              n=>(y=4,g=x=>~y?(X=x>8?17-x:x,k=X<y?g:X<5?24-(z=4+y-X)*~z+y*2:y*6+X*2-18,~X?X^5?k<0?'-':(k+=x>8)<n?k%10:' ':'|':`
              `)+g(~X?-~x:!y--):'')()


              Try it online!



              How?



              The output is built character by character, with $y$ decreasing from $4$ to $0$ and $x$ increasing from $0$ to $18$ on each row.



              We define:



              $$X=begin{cases}x&text{if }xle 8\17-x&text{if }x>8end{cases}$$



              By writing the full values rather than just the unit digits, we get the following table:



               x |  0  1  2  3  4  5  6  7  8 |  9 10 11 12 13 14 15 16 17 18
              X | 0 1 2 3 4 5 6 7 8 | 8 7 6 5 4 3 2 1 0 -1
              ---+----------------------------+-------------------------------
              4 | .. .. .. .. 52 || 18 20 22 | 23 21 19 || 53 .. .. .. .. n
              3 | .. .. .. 50 42 || 12 14 16 | 17 15 13 || 43 51 .. .. .. n
              2 | .. .. 48 40 34 || 6 8 10 | 11 9 7 || 35 41 49 .. .. n
              1 | .. 46 38 32 28 || 0 2 4 | 5 3 1 || 29 33 39 47 .. n
              0 | 44 36 30 26 24 || -- -- -- | -- -- -- || 25 27 31 37 45 n


              This table is essentially symmetric across the y-axis, except that the values on the left side are even and the values on the right side are their odd counterparts.



              We define:



              $$k=begin{cases}24+(4+y-X)(5+y-X)+2y&text{if }X<5\6y+2X-18&text{if }X>5end{cases}$$



              $$k'=begin{cases}k&text{if }xle 8\k+1&text{if }x>8end{cases}$$



              And for each cell, we append:




              • a linefeed if $X=-1$

              • a pipe if $X=5$

              • a hyphen if $k<0$

              • a space if $X<y$ or $k'>n$ (where $n$ is the input)


              • $k' bmod 10$ otherwise


              Commented



              n => (                                // main function taking n
              y = 4, // start with y = 4
              g = x => // g = recursive function taking x
              ~y ? // if y is not equal to -1:
              ( X = x > 8 ? 17 - x : x, // compute X
              k = X < y ? // if X is less than y:
              g // set k to a non-numeric value
              : // else:
              X < 5 ? // if X is less than 5:
              24 - (z = 4 + y - X) * ~z // apply the 'side numbers' formula
              + y * 2 //
              : // else:
              y * 6 + X * 2 - 18, // apply the 'middle numbers' formula
              ~X ? // if X is not equal to -1:
              X ^ 5 ? // if X is not equal to 5:
              k < 0 ? // if k is less than 0:
              '-' // append a hyphen
              : // else:
              (k += x > 8) < n ? // update k to k'; if it's less than n:
              k % 10 // append the unit digit of k'
              : // else:
              ' ' // append a space
              : // else (X = 5):
              '|' // append a pipe
              : // else (X = -1):
              `n` // append a linefeed
              ) //
              + g(~X ? -~x : !y--) // update x and y, and do a recursive call
              : // else (y = -1):
              '' // stop recursion
              )() // initial call to g with x undefined





              share|improve this answer


























                7












                7








                7






                JavaScript (ES6),  144 ... 139  137 bytes



                A mathematical approach (see here for less maths).



                0-indexed.



                n=>(y=4,g=x=>~y?(X=x>8?17-x:x,k=X<y?g:X<5?24-(z=4+y-X)*~z+y*2:y*6+X*2-18,~X?X^5?k<0?'-':(k+=x>8)<n?k%10:' ':'|':`
                `)+g(~X?-~x:!y--):'')()


                Try it online!



                How?



                The output is built character by character, with $y$ decreasing from $4$ to $0$ and $x$ increasing from $0$ to $18$ on each row.



                We define:



                $$X=begin{cases}x&text{if }xle 8\17-x&text{if }x>8end{cases}$$



                By writing the full values rather than just the unit digits, we get the following table:



                 x |  0  1  2  3  4  5  6  7  8 |  9 10 11 12 13 14 15 16 17 18
                X | 0 1 2 3 4 5 6 7 8 | 8 7 6 5 4 3 2 1 0 -1
                ---+----------------------------+-------------------------------
                4 | .. .. .. .. 52 || 18 20 22 | 23 21 19 || 53 .. .. .. .. n
                3 | .. .. .. 50 42 || 12 14 16 | 17 15 13 || 43 51 .. .. .. n
                2 | .. .. 48 40 34 || 6 8 10 | 11 9 7 || 35 41 49 .. .. n
                1 | .. 46 38 32 28 || 0 2 4 | 5 3 1 || 29 33 39 47 .. n
                0 | 44 36 30 26 24 || -- -- -- | -- -- -- || 25 27 31 37 45 n


                This table is essentially symmetric across the y-axis, except that the values on the left side are even and the values on the right side are their odd counterparts.



                We define:



                $$k=begin{cases}24+(4+y-X)(5+y-X)+2y&text{if }X<5\6y+2X-18&text{if }X>5end{cases}$$



                $$k'=begin{cases}k&text{if }xle 8\k+1&text{if }x>8end{cases}$$



                And for each cell, we append:




                • a linefeed if $X=-1$

                • a pipe if $X=5$

                • a hyphen if $k<0$

                • a space if $X<y$ or $k'>n$ (where $n$ is the input)


                • $k' bmod 10$ otherwise


                Commented



                n => (                                // main function taking n
                y = 4, // start with y = 4
                g = x => // g = recursive function taking x
                ~y ? // if y is not equal to -1:
                ( X = x > 8 ? 17 - x : x, // compute X
                k = X < y ? // if X is less than y:
                g // set k to a non-numeric value
                : // else:
                X < 5 ? // if X is less than 5:
                24 - (z = 4 + y - X) * ~z // apply the 'side numbers' formula
                + y * 2 //
                : // else:
                y * 6 + X * 2 - 18, // apply the 'middle numbers' formula
                ~X ? // if X is not equal to -1:
                X ^ 5 ? // if X is not equal to 5:
                k < 0 ? // if k is less than 0:
                '-' // append a hyphen
                : // else:
                (k += x > 8) < n ? // update k to k'; if it's less than n:
                k % 10 // append the unit digit of k'
                : // else:
                ' ' // append a space
                : // else (X = 5):
                '|' // append a pipe
                : // else (X = -1):
                `n` // append a linefeed
                ) //
                + g(~X ? -~x : !y--) // update x and y, and do a recursive call
                : // else (y = -1):
                '' // stop recursion
                )() // initial call to g with x undefined





                share|improve this answer














                JavaScript (ES6),  144 ... 139  137 bytes



                A mathematical approach (see here for less maths).



                0-indexed.



                n=>(y=4,g=x=>~y?(X=x>8?17-x:x,k=X<y?g:X<5?24-(z=4+y-X)*~z+y*2:y*6+X*2-18,~X?X^5?k<0?'-':(k+=x>8)<n?k%10:' ':'|':`
                `)+g(~X?-~x:!y--):'')()


                Try it online!



                How?



                The output is built character by character, with $y$ decreasing from $4$ to $0$ and $x$ increasing from $0$ to $18$ on each row.



                We define:



                $$X=begin{cases}x&text{if }xle 8\17-x&text{if }x>8end{cases}$$



                By writing the full values rather than just the unit digits, we get the following table:



                 x |  0  1  2  3  4  5  6  7  8 |  9 10 11 12 13 14 15 16 17 18
                X | 0 1 2 3 4 5 6 7 8 | 8 7 6 5 4 3 2 1 0 -1
                ---+----------------------------+-------------------------------
                4 | .. .. .. .. 52 || 18 20 22 | 23 21 19 || 53 .. .. .. .. n
                3 | .. .. .. 50 42 || 12 14 16 | 17 15 13 || 43 51 .. .. .. n
                2 | .. .. 48 40 34 || 6 8 10 | 11 9 7 || 35 41 49 .. .. n
                1 | .. 46 38 32 28 || 0 2 4 | 5 3 1 || 29 33 39 47 .. n
                0 | 44 36 30 26 24 || -- -- -- | -- -- -- || 25 27 31 37 45 n


                This table is essentially symmetric across the y-axis, except that the values on the left side are even and the values on the right side are their odd counterparts.



                We define:



                $$k=begin{cases}24+(4+y-X)(5+y-X)+2y&text{if }X<5\6y+2X-18&text{if }X>5end{cases}$$



                $$k'=begin{cases}k&text{if }xle 8\k+1&text{if }x>8end{cases}$$



                And for each cell, we append:




                • a linefeed if $X=-1$

                • a pipe if $X=5$

                • a hyphen if $k<0$

                • a space if $X<y$ or $k'>n$ (where $n$ is the input)


                • $k' bmod 10$ otherwise


                Commented



                n => (                                // main function taking n
                y = 4, // start with y = 4
                g = x => // g = recursive function taking x
                ~y ? // if y is not equal to -1:
                ( X = x > 8 ? 17 - x : x, // compute X
                k = X < y ? // if X is less than y:
                g // set k to a non-numeric value
                : // else:
                X < 5 ? // if X is less than 5:
                24 - (z = 4 + y - X) * ~z // apply the 'side numbers' formula
                + y * 2 //
                : // else:
                y * 6 + X * 2 - 18, // apply the 'middle numbers' formula
                ~X ? // if X is not equal to -1:
                X ^ 5 ? // if X is not equal to 5:
                k < 0 ? // if k is less than 0:
                '-' // append a hyphen
                : // else:
                (k += x > 8) < n ? // update k to k'; if it's less than n:
                k % 10 // append the unit digit of k'
                : // else:
                ' ' // append a space
                : // else (X = 5):
                '|' // append a pipe
                : // else (X = -1):
                `n` // append a linefeed
                ) //
                + g(~X ? -~x : !y--) // update x and y, and do a recursive call
                : // else (y = -1):
                '' // stop recursion
                )() // initial call to g with x undefined






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 12 '18 at 10:40

























                answered Dec 11 '18 at 16:47









                Arnauld

                72.6k689306




                72.6k689306























                    3















                    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


























                      3















                      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
























                        3












                        3








                        3







                        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 Dec 11 '18 at 13:15









                        TFeld

                        14.3k21240




                        14.3k21240























                            3














                            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|improve this answer


























                              3














                              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|improve this answer
























                                3












                                3








                                3






                                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|improve this answer












                                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|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Dec 11 '18 at 16:21









                                Kevin Cruijssen

                                35.9k554188




                                35.9k554188























                                    1















                                    6502 machine code (C64), 130 bytes



                                    00 C0 20 9B B7 A9 C0 65 65 85 FB A2 00 BD 2B C0 F0 1A 10 12 C5 FB 90 04 A9 20
                                    D0 0A 69 70 C9 3A 90 04 E9 0A B0 F8 20 D2 FF E8 D0 E1 60 20 20 20 20 F5 7D D3
                                    D5 D7 D8 D6 D4 7D F6 0D 20 20 20 F3 EB 7D CD CF D1 D2 D0 CE 7D EC F4 0D 20 20
                                    F1 E9 E3 7D C7 C9 CB CC CA C8 7D E4 EA F2 0D 20 EF E7 E1 DD 7D C1 C3 C5 C6 C4
                                    C2 7D DE E2 E8 F0 0D ED E5 DF DB D9 7D 2D 2D 2D 2D 2D 2D 7D DA DC E0 E6 EE 00


                                    This uses a modified version of the "preformatted" approach of some other answers. It contains a full string of the bucket, but the digits are replaced by values starting from 0xC1, while any characters for direct printing are in the range 0x01-0x7f.



                                    The C64 charset doesn't include a pipe (|) character, it's therefore replaced with the similar-looking PETSCII character 0x7d.



                                    Online demo



                                    Usage: SYS49152,[n] (1-indexed, e.g. SYS49152,54 for the full output)



                                    Commented disassembly:



                                             00 C0       .WORD $C000        ; load address
                                    .C:c000 20 9B B7 JSR $B79B ; get unsigned byte from commandline
                                    .C:c003 A9 C0 LDA #$C0 ; add #$C0 (+ carry = #$C1) ...
                                    .C:c005 65 65 ADC $65 ; ... to parameter
                                    .C:c007 85 FB STA $FB ; and store in $FB
                                    .C:c009 A2 00 LDX #$00 ; loop index
                                    .C:c00b .loop:
                                    .C:c00b BD 2B C0 LDA .bucket,X ; loop over encoded string
                                    .C:c00e F0 1A BEQ .done ; null-terminator -> done
                                    .C:c010 10 12 BPL .out ; positive (bit 7 clear) -> output
                                    .C:c012 C5 FB CMP $FB ; compare with parameter+#$C1
                                    .C:c014 90 04 BCC .digit ; smaller -> convert to digit
                                    .C:c016 A9 20 LDA #$20 ; otherwise load space character
                                    .C:c018 D0 0A BNE .out ; and output
                                    .C:c01a .digit:
                                    .C:c01a 69 70 ADC #$70 ; add offset to '0' (#$30)
                                    .C:c01c .check:
                                    .C:c01c C9 3A CMP #$3A ; greater than '9' (#$39) ?
                                    .C:c01e 90 04 BCC .out ; no -> to output
                                    .C:c020 E9 0A SBC #$0A ; otherwise subtract 10 (#$a)
                                    .C:c022 B0 F8 BCS .check ; and check again
                                    .C:c024 .out:
                                    .C:c024 20 D2 FF JSR $FFD2 ; output character
                                    .C:c027 E8 INX ; next index
                                    .C:c028 D0 E1 BNE .loop ; and repeat loop
                                    .C:c02a .done:
                                    .C:c02a 60 RTS ; exit ....
                                    .C:c02b .bucket:
                                    .C:c02b 20 20 20 [...] ; "encoded" string for bucket





                                    share|improve this answer


























                                      1















                                      6502 machine code (C64), 130 bytes



                                      00 C0 20 9B B7 A9 C0 65 65 85 FB A2 00 BD 2B C0 F0 1A 10 12 C5 FB 90 04 A9 20
                                      D0 0A 69 70 C9 3A 90 04 E9 0A B0 F8 20 D2 FF E8 D0 E1 60 20 20 20 20 F5 7D D3
                                      D5 D7 D8 D6 D4 7D F6 0D 20 20 20 F3 EB 7D CD CF D1 D2 D0 CE 7D EC F4 0D 20 20
                                      F1 E9 E3 7D C7 C9 CB CC CA C8 7D E4 EA F2 0D 20 EF E7 E1 DD 7D C1 C3 C5 C6 C4
                                      C2 7D DE E2 E8 F0 0D ED E5 DF DB D9 7D 2D 2D 2D 2D 2D 2D 7D DA DC E0 E6 EE 00


                                      This uses a modified version of the "preformatted" approach of some other answers. It contains a full string of the bucket, but the digits are replaced by values starting from 0xC1, while any characters for direct printing are in the range 0x01-0x7f.



                                      The C64 charset doesn't include a pipe (|) character, it's therefore replaced with the similar-looking PETSCII character 0x7d.



                                      Online demo



                                      Usage: SYS49152,[n] (1-indexed, e.g. SYS49152,54 for the full output)



                                      Commented disassembly:



                                               00 C0       .WORD $C000        ; load address
                                      .C:c000 20 9B B7 JSR $B79B ; get unsigned byte from commandline
                                      .C:c003 A9 C0 LDA #$C0 ; add #$C0 (+ carry = #$C1) ...
                                      .C:c005 65 65 ADC $65 ; ... to parameter
                                      .C:c007 85 FB STA $FB ; and store in $FB
                                      .C:c009 A2 00 LDX #$00 ; loop index
                                      .C:c00b .loop:
                                      .C:c00b BD 2B C0 LDA .bucket,X ; loop over encoded string
                                      .C:c00e F0 1A BEQ .done ; null-terminator -> done
                                      .C:c010 10 12 BPL .out ; positive (bit 7 clear) -> output
                                      .C:c012 C5 FB CMP $FB ; compare with parameter+#$C1
                                      .C:c014 90 04 BCC .digit ; smaller -> convert to digit
                                      .C:c016 A9 20 LDA #$20 ; otherwise load space character
                                      .C:c018 D0 0A BNE .out ; and output
                                      .C:c01a .digit:
                                      .C:c01a 69 70 ADC #$70 ; add offset to '0' (#$30)
                                      .C:c01c .check:
                                      .C:c01c C9 3A CMP #$3A ; greater than '9' (#$39) ?
                                      .C:c01e 90 04 BCC .out ; no -> to output
                                      .C:c020 E9 0A SBC #$0A ; otherwise subtract 10 (#$a)
                                      .C:c022 B0 F8 BCS .check ; and check again
                                      .C:c024 .out:
                                      .C:c024 20 D2 FF JSR $FFD2 ; output character
                                      .C:c027 E8 INX ; next index
                                      .C:c028 D0 E1 BNE .loop ; and repeat loop
                                      .C:c02a .done:
                                      .C:c02a 60 RTS ; exit ....
                                      .C:c02b .bucket:
                                      .C:c02b 20 20 20 [...] ; "encoded" string for bucket





                                      share|improve this answer
























                                        1












                                        1








                                        1







                                        6502 machine code (C64), 130 bytes



                                        00 C0 20 9B B7 A9 C0 65 65 85 FB A2 00 BD 2B C0 F0 1A 10 12 C5 FB 90 04 A9 20
                                        D0 0A 69 70 C9 3A 90 04 E9 0A B0 F8 20 D2 FF E8 D0 E1 60 20 20 20 20 F5 7D D3
                                        D5 D7 D8 D6 D4 7D F6 0D 20 20 20 F3 EB 7D CD CF D1 D2 D0 CE 7D EC F4 0D 20 20
                                        F1 E9 E3 7D C7 C9 CB CC CA C8 7D E4 EA F2 0D 20 EF E7 E1 DD 7D C1 C3 C5 C6 C4
                                        C2 7D DE E2 E8 F0 0D ED E5 DF DB D9 7D 2D 2D 2D 2D 2D 2D 7D DA DC E0 E6 EE 00


                                        This uses a modified version of the "preformatted" approach of some other answers. It contains a full string of the bucket, but the digits are replaced by values starting from 0xC1, while any characters for direct printing are in the range 0x01-0x7f.



                                        The C64 charset doesn't include a pipe (|) character, it's therefore replaced with the similar-looking PETSCII character 0x7d.



                                        Online demo



                                        Usage: SYS49152,[n] (1-indexed, e.g. SYS49152,54 for the full output)



                                        Commented disassembly:



                                                 00 C0       .WORD $C000        ; load address
                                        .C:c000 20 9B B7 JSR $B79B ; get unsigned byte from commandline
                                        .C:c003 A9 C0 LDA #$C0 ; add #$C0 (+ carry = #$C1) ...
                                        .C:c005 65 65 ADC $65 ; ... to parameter
                                        .C:c007 85 FB STA $FB ; and store in $FB
                                        .C:c009 A2 00 LDX #$00 ; loop index
                                        .C:c00b .loop:
                                        .C:c00b BD 2B C0 LDA .bucket,X ; loop over encoded string
                                        .C:c00e F0 1A BEQ .done ; null-terminator -> done
                                        .C:c010 10 12 BPL .out ; positive (bit 7 clear) -> output
                                        .C:c012 C5 FB CMP $FB ; compare with parameter+#$C1
                                        .C:c014 90 04 BCC .digit ; smaller -> convert to digit
                                        .C:c016 A9 20 LDA #$20 ; otherwise load space character
                                        .C:c018 D0 0A BNE .out ; and output
                                        .C:c01a .digit:
                                        .C:c01a 69 70 ADC #$70 ; add offset to '0' (#$30)
                                        .C:c01c .check:
                                        .C:c01c C9 3A CMP #$3A ; greater than '9' (#$39) ?
                                        .C:c01e 90 04 BCC .out ; no -> to output
                                        .C:c020 E9 0A SBC #$0A ; otherwise subtract 10 (#$a)
                                        .C:c022 B0 F8 BCS .check ; and check again
                                        .C:c024 .out:
                                        .C:c024 20 D2 FF JSR $FFD2 ; output character
                                        .C:c027 E8 INX ; next index
                                        .C:c028 D0 E1 BNE .loop ; and repeat loop
                                        .C:c02a .done:
                                        .C:c02a 60 RTS ; exit ....
                                        .C:c02b .bucket:
                                        .C:c02b 20 20 20 [...] ; "encoded" string for bucket





                                        share|improve this answer













                                        6502 machine code (C64), 130 bytes



                                        00 C0 20 9B B7 A9 C0 65 65 85 FB A2 00 BD 2B C0 F0 1A 10 12 C5 FB 90 04 A9 20
                                        D0 0A 69 70 C9 3A 90 04 E9 0A B0 F8 20 D2 FF E8 D0 E1 60 20 20 20 20 F5 7D D3
                                        D5 D7 D8 D6 D4 7D F6 0D 20 20 20 F3 EB 7D CD CF D1 D2 D0 CE 7D EC F4 0D 20 20
                                        F1 E9 E3 7D C7 C9 CB CC CA C8 7D E4 EA F2 0D 20 EF E7 E1 DD 7D C1 C3 C5 C6 C4
                                        C2 7D DE E2 E8 F0 0D ED E5 DF DB D9 7D 2D 2D 2D 2D 2D 2D 7D DA DC E0 E6 EE 00


                                        This uses a modified version of the "preformatted" approach of some other answers. It contains a full string of the bucket, but the digits are replaced by values starting from 0xC1, while any characters for direct printing are in the range 0x01-0x7f.



                                        The C64 charset doesn't include a pipe (|) character, it's therefore replaced with the similar-looking PETSCII character 0x7d.



                                        Online demo



                                        Usage: SYS49152,[n] (1-indexed, e.g. SYS49152,54 for the full output)



                                        Commented disassembly:



                                                 00 C0       .WORD $C000        ; load address
                                        .C:c000 20 9B B7 JSR $B79B ; get unsigned byte from commandline
                                        .C:c003 A9 C0 LDA #$C0 ; add #$C0 (+ carry = #$C1) ...
                                        .C:c005 65 65 ADC $65 ; ... to parameter
                                        .C:c007 85 FB STA $FB ; and store in $FB
                                        .C:c009 A2 00 LDX #$00 ; loop index
                                        .C:c00b .loop:
                                        .C:c00b BD 2B C0 LDA .bucket,X ; loop over encoded string
                                        .C:c00e F0 1A BEQ .done ; null-terminator -> done
                                        .C:c010 10 12 BPL .out ; positive (bit 7 clear) -> output
                                        .C:c012 C5 FB CMP $FB ; compare with parameter+#$C1
                                        .C:c014 90 04 BCC .digit ; smaller -> convert to digit
                                        .C:c016 A9 20 LDA #$20 ; otherwise load space character
                                        .C:c018 D0 0A BNE .out ; and output
                                        .C:c01a .digit:
                                        .C:c01a 69 70 ADC #$70 ; add offset to '0' (#$30)
                                        .C:c01c .check:
                                        .C:c01c C9 3A CMP #$3A ; greater than '9' (#$39) ?
                                        .C:c01e 90 04 BCC .out ; no -> to output
                                        .C:c020 E9 0A SBC #$0A ; otherwise subtract 10 (#$a)
                                        .C:c022 B0 F8 BCS .check ; and check again
                                        .C:c024 .out:
                                        .C:c024 20 D2 FF JSR $FFD2 ; output character
                                        .C:c027 E8 INX ; next index
                                        .C:c028 D0 E1 BNE .loop ; and repeat loop
                                        .C:c02a .done:
                                        .C:c02a 60 RTS ; exit ....
                                        .C:c02b .bucket:
                                        .C:c02b 20 20 20 [...] ; "encoded" string for bucket






                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Dec 12 '18 at 10:48









                                        Felix Palmen

                                        3,341525




                                        3,341525























                                            0















                                            Charcoal, 64 bytes



                                            Nθ³↑⁵‖M←F²«‖J⁻³ι±¹F⊘⁺θ¬ι«↖I﹪⁺⊗κ⊕ιχM§”)⊟E≡≦⌈▷⊖ü∕”꧔)⊟&hXτtD(λM”κ


                                            Try it online! Link is to verbose version of code. Explanation:



                                            Nθ


                                            Input the number.



                                            ³↑⁵‖M←


                                            Draw half of the bucket and then mirror it to complete the bucket.



                                            F²«


                                            Loop for each side of the bucket.



                                            ‖J⁻³ι±¹


                                            Reflect the bucket so that we can draw in a consistent direction on both loops, and jump to the position of the first digit on that side of the bucket.



                                            F⊘⁺θ¬ι«


                                            Loop over the number of digits on that side of the bucket.



                                            ↖I﹪⁺⊗κ⊕ιχ


                                            Print the next digit and move the cursor up and left.



                                            M§”)⊟E≡≦⌈▷⊖ü∕”꧔)⊟&hXτtD(λM”κ


                                            Adjust the cursor position by reading the offsets from two compressed strings, 003003003005203004000500 (horizontal offsets) and 11011011011510200300040000 (vertical offsets). These offsets take the above cursor movement into account which conveniently means that they never have to be negative.






                                            share|improve this answer




























                                              0















                                              Charcoal, 64 bytes



                                              Nθ³↑⁵‖M←F²«‖J⁻³ι±¹F⊘⁺θ¬ι«↖I﹪⁺⊗κ⊕ιχM§”)⊟E≡≦⌈▷⊖ü∕”꧔)⊟&hXτtD(λM”κ


                                              Try it online! Link is to verbose version of code. Explanation:



                                              Nθ


                                              Input the number.



                                              ³↑⁵‖M←


                                              Draw half of the bucket and then mirror it to complete the bucket.



                                              F²«


                                              Loop for each side of the bucket.



                                              ‖J⁻³ι±¹


                                              Reflect the bucket so that we can draw in a consistent direction on both loops, and jump to the position of the first digit on that side of the bucket.



                                              F⊘⁺θ¬ι«


                                              Loop over the number of digits on that side of the bucket.



                                              ↖I﹪⁺⊗κ⊕ιχ


                                              Print the next digit and move the cursor up and left.



                                              M§”)⊟E≡≦⌈▷⊖ü∕”꧔)⊟&hXτtD(λM”κ


                                              Adjust the cursor position by reading the offsets from two compressed strings, 003003003005203004000500 (horizontal offsets) and 11011011011510200300040000 (vertical offsets). These offsets take the above cursor movement into account which conveniently means that they never have to be negative.






                                              share|improve this answer


























                                                0












                                                0








                                                0







                                                Charcoal, 64 bytes



                                                Nθ³↑⁵‖M←F²«‖J⁻³ι±¹F⊘⁺θ¬ι«↖I﹪⁺⊗κ⊕ιχM§”)⊟E≡≦⌈▷⊖ü∕”꧔)⊟&hXτtD(λM”κ


                                                Try it online! Link is to verbose version of code. Explanation:



                                                Nθ


                                                Input the number.



                                                ³↑⁵‖M←


                                                Draw half of the bucket and then mirror it to complete the bucket.



                                                F²«


                                                Loop for each side of the bucket.



                                                ‖J⁻³ι±¹


                                                Reflect the bucket so that we can draw in a consistent direction on both loops, and jump to the position of the first digit on that side of the bucket.



                                                F⊘⁺θ¬ι«


                                                Loop over the number of digits on that side of the bucket.



                                                ↖I﹪⁺⊗κ⊕ιχ


                                                Print the next digit and move the cursor up and left.



                                                M§”)⊟E≡≦⌈▷⊖ü∕”꧔)⊟&hXτtD(λM”κ


                                                Adjust the cursor position by reading the offsets from two compressed strings, 003003003005203004000500 (horizontal offsets) and 11011011011510200300040000 (vertical offsets). These offsets take the above cursor movement into account which conveniently means that they never have to be negative.






                                                share|improve this answer















                                                Charcoal, 64 bytes



                                                Nθ³↑⁵‖M←F²«‖J⁻³ι±¹F⊘⁺θ¬ι«↖I﹪⁺⊗κ⊕ιχM§”)⊟E≡≦⌈▷⊖ü∕”꧔)⊟&hXτtD(λM”κ


                                                Try it online! Link is to verbose version of code. Explanation:



                                                Nθ


                                                Input the number.



                                                ³↑⁵‖M←


                                                Draw half of the bucket and then mirror it to complete the bucket.



                                                F²«


                                                Loop for each side of the bucket.



                                                ‖J⁻³ι±¹


                                                Reflect the bucket so that we can draw in a consistent direction on both loops, and jump to the position of the first digit on that side of the bucket.



                                                F⊘⁺θ¬ι«


                                                Loop over the number of digits on that side of the bucket.



                                                ↖I﹪⁺⊗κ⊕ιχ


                                                Print the next digit and move the cursor up and left.



                                                M§”)⊟E≡≦⌈▷⊖ü∕”꧔)⊟&hXτtD(λM”κ


                                                Adjust the cursor position by reading the offsets from two compressed strings, 003003003005203004000500 (horizontal offsets) and 11011011011510200300040000 (vertical offsets). These offsets take the above cursor movement into account which conveniently means that they never have to be negative.







                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited Dec 16 '18 at 0:57

























                                                answered Dec 14 '18 at 0:00









                                                Neil

                                                79.5k744177




                                                79.5k744177






























                                                    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

                                                    Bressuire

                                                    Cabo Verde

                                                    Gyllenstierna