Inspired by the bugged output in @Carcigenicate's Clojure answer for the Print this diamond challenge.

Print this exact text:

1        2        3        4        5        6        7        8        9        0
1       2       3       4       5       6       7       8       9       0
1      2      3      4      5      6      7      8      9      0
1     2     3     4     5     6     7     8     9     0
1    2    3    4    5    6    7    8    9    0
1   2   3   4   5   6   7   8   9   0
1  2  3  4  5  6  7  8  9  0
1 2 3 4 5 6 7 8 9 0
1234567890
1 2 3 4 5 6 7 8 9 0
1  2  3  4  5  6  7  8  9  0
1   2   3   4   5   6   7   8   9   0
1    2    3    4    5    6    7    8    9    0
1     2     3     4     5     6     7     8     9     0
1      2      3      4      5      6      7      8      9      0
1       2       3       4       5       6       7       8       9       0
1        2        3        4        5        6        7        8        9        0

(From the middle outward in both directions, each digit is separated by one more space than the previous line.)

Challenge rules:

  • There will be no input (or an empty unused input).
  • Trailing spaces are optional.
  • A single trailing new-line is optional.
  • Leading spaces or new-lines are not allowed.
  • Returning a string-array isn't allowed. You should either output the text, or have a function which returns a single string with correct result.

General rules:

  • This is , so shortest answer in bytes wins.
    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
  • Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
  • Default Loopholes are forbidden.
  • If possible, please add a link with a test for your code.
  • Also, please add an explanation if necessary.
  • Is outputting an array of strings - 1 string per line - allowed? – Shaggy Jul 3 '17 at 9:37
  • @Shaggy Sorry, in this case it should either return a single string with new-lines, or output the result. I've added this as rule to the challenge. – Kevin Cruijssen Jul 3 '17 at 11:06
  • No worries, Kevin; was just chancing my arm to see if I could save myself a couple of bytes. – Shaggy Jul 3 '17 at 11:09
  • 2
    @Shaggy Hehe. What other reason would we have to ask question in a code-golf challenge, besides having the purpose of saving those few bytes? ;) – Kevin Cruijssen Jul 3 '17 at 11:23
  • 7
    Ha, that's awesome. I was wondering why that answer suddenly got so much attention. Thanks! – Carcigenicate Jul 3 '17 at 19:41

73 Answers 73

up vote 7 down vote accepted

SOGL V0.12, 12 bytes

9{SUē↕∑}¹№╬«

Try it Here! Explanation:

9{     }      9 times do
  SU            push "1234567890"
    ē           push e, predefined with the input, which defaults to 0, and then increase it
     ↕          get that many spaces
      ∑         join the string of digits with those spaces
        ¹     collect the results in an array
         №    reverse the array vertically
          ή  palindromize vertically with 1 overlap
  • Oh nice, this is even shorter than the accepted answer. Hmm, what is the policy on shorter answers a couple months after an answer has been accepted? Does this now get the check (kinda unfair to the currently accepted answer I think), or should I do something else? Great answer regardless! +1 from me. – Kevin Cruijssen Oct 29 '17 at 10:35
  • @KevinCruijssen Usually the best practice is to update the accepted answer, but as this uses a couple new features, I'd say there's reason to go either way - you choose. – dzaima Oct 29 '17 at 10:44

Python 2, 59 57 56 55 bytes

i=8;exec"print(' '*abs(i)).join('1234567890');i-=1;"*17

Try it online!

@Leaky Nun helped golfing this a lot, @Praind Suggested a method to save 1 byte, which I formerly thought of, but forgot to edit, @CotyJohnathanSaxman suggested changing the loop.


Explanation

  • i=8 - Assigns the value 8 to a variable called i.

  • exec"..."*17 - Execute that block of code (...) 17 times.

  • print(...) - Output the result.

  • ' '*abs(i) - Create a String with a space repeated |i| times.

  • .join('1234567890') - Interleave the string created above with 1234567890, such that |i| spaces are inserted between the digits.

  • i-=1 - Decrement i, and by executing it 17 times, it reaches -8, which creates te repetitive pattern with the help of abs().

  • 5
    59 bytes – Leaky Nun Jul 3 '17 at 7:30
  • 23
    This is farm more impressive than 25 bytes in any golfing language imho. – Jylo Jul 3 '17 at 9:30
  • 4
    @Jylo Thanks, but the 25 byte-solutions are very impressive, since they show lots of golfing efforts made by their authors. You should first know what each character in their source means, and then you will understand how beautifully golfed they are. – Mr. Xcoder Jul 3 '17 at 9:33
  • 2
    @JasonChen No, Python does not allow that syntax, because that's specific to C-like languages. – Mr. Xcoder Jul 4 '17 at 20:11
  • 5
    Possible inspiration: Can be done without exec in 55 bytes as well. Used a similar approach to get Python 3 down to 57 bytes. Didn't see any obvious way to get it shorter, by omitting exec, but figured I'd mention it as a possibility. – ShadowRanger Jul 6 '17 at 2:27

Vim, 35 bytes:

i1234567890<esc>qqYP:s/\d/& /g
YGp{q7@q

Explanation:

i1234567890<esc>    " insert '1234567890'
qq                  " Record the following into register 'q'
  Y                 "   Yank a line
   P                "   Paste it above us
    :s/\d/& /g      "   Put a space after each number
Y                   "   Yank this line
 G                  "   Move the end of the buffer
  p                 "   Paste the line
   {                "   Move the beginning of the buffer
    q               " Stop recording
     7@q            " Call macro 'q' 7 times
  • 6
    I don't even care that this isn't the winner, it's beautiful. – MrDuk Jul 5 '17 at 15:19
  • @MrDuk Thankyou! I'm glad you like it :) – DJMcMayhem Jul 5 '17 at 20:09

05AB1E,  14  13 bytes

17F9ÝÀN8αð×ý,

Try it online!

Explanation

17F            # for N in [0 ... 16] do
   9Ý          # push [0 ... 9]
     À         # rotate left
      N8α      # compute the absolute difference between N and 8
         ð×    # push that many spaces
           ý   # merge the list of digits with the space string as separator
            ,  # print
  • 1
    Hmm...you could've beaten SOGL if you didn't need the s...does it make sense to join a string with a list or a list with a string? I'll suggest improvement to Adnan. Oh, and there's .∊ for û». – Erik the Outgolfer Jul 3 '17 at 13:06
  • @EriktheOutgolfer: Or I could switch up my method and save that 1 byte I needed :) – Emigna Jul 3 '17 at 13:32
  • Sorry already upvoted. – Erik the Outgolfer Jul 3 '17 at 13:33
  • 2
    That means I'd have upvoted again... – Erik the Outgolfer Jul 3 '17 at 13:36
  • 3
    8F9ÝÀNð×ý}».∊ I done did made a spaceship maw! And I was all excited about suggesting a 12-byte edit. – Magic Octopus Urn Jul 17 '17 at 20:10

C64 ASM, 358 bytes (102 bytes compiled with basicstub)

This is the closest I could get due to obvious limitations:

C64

jsr $E544
lda #9
sta $FD
nl1: jsr dl
jsr il
dec $FD
bne nl1
inc $FD
nl2: ldy $FD
cpy #9
bne nt1
bl: jmp bl
nt1: iny
sty $FD
jsr dl
jsr il
jmp nl2
dl: clc
ldx #$31
ldy #0
lp: txa
sm: sta $0400, y
inx
cpx #$31
bne c1
rts
c1: cpx #$3A
bne nt2
ldx #$30
clc
nt2: tya
adc $FD
cmp #40
bcc c2
rts
c2: tay
jmp lp
il: lda sm+1
adc #39
bcc nc
inc sm+2
nc: sta sm+1
rts

(Could probably be optimized quite a bit)

  • Welcome to PPCG! Please use code tag to post pretty. I edited you post. After changes apply you can see, what changed by clicking edit – Евгений Новиков Jul 4 '17 at 18:32
  • I've just checked and it won't even fit on an 80 cols PET as the first and last line require 82 columns. – Shaun Bebbers Apr 5 at 16:25

TSQL, 220 148 bytes

Improvement posted by ZLK:

DECLARE @ VARCHAR(MAX)=''SELECT TOP 17@+=REPLACE('1@2@3@4@5@6@7@8@9@0','@',SPACE(ABS(9-RANK()OVER(ORDER BY object_id))))+'
'FROM sys.objects PRINT @

Output:

1        2        3        4        5        6        7        8        9        0
1       2       3       4       5       6       7       8       9       0
1      2      3      4      5      6      7      8      9      0
1     2     3     4     5     6     7     8     9     0
1    2    3    4    5    6    7    8    9    0
1   2   3   4   5   6   7   8   9   0
1  2  3  4  5  6  7  8  9  0
1 2 3 4 5 6 7 8 9 0
1234567890
1 2 3 4 5 6 7 8 9 0
1  2  3  4  5  6  7  8  9  0
1   2   3   4   5   6   7   8   9   0
1    2    3    4    5    6    7    8    9    0
1     2     3     4     5     6     7     8     9     0
1      2      3      4      5      6      7      8      9      0
1       2       3       4       5       6       7       8       9       0
1        2        3        4        5        6        7        8        9        0
  • DECLARE @ VARCHAR(MAX)=''SELECT TOP 17@+=REPLACE('1@2@3@4@5@6@7@8@9@0','@',SPACE(ABS(9-RANK()OVER(ORDER BY object_id))))+' 'FROM sys.objects PRINT @ – ZLK Jul 4 '17 at 1:23
  • Replace sys.objects with sysobjects, and 1object_id` with id I looked for shorter tables in the sys schema, but nothing short had columns as short as sysobjects – Jaloopa Jul 4 '17 at 11:19
  • And you can save another few bytes by changing the inner CAST (with the POWER(10)) to VARCHAR – Jaloopa Jul 4 '17 at 11:21
  • In fact, avoid all that replace stuff by using LOG10 and REPLICATE: DECLARE @o VARCHAR(MAX)=''SELECT TOP 17 @o+=REPLACE('1@2@3@4@5@6@7@8@9@0','@',replicate(' ',LOG10(POWER(10,ABS(ROW_NUMBER()OVER(ORDER BY id)-9)+1)/10)))+' 'FROM sysobjects PRINT @o – Jaloopa Jul 4 '17 at 11:32
  • You can change the variable name to just @ to shave off 3 characters. – Bridge Jul 4 '17 at 13:18

APL (Dyalog), 22 bytes

↑∊¨(1+|¯9+⍳17)↑¨¨⊂1⌽⎕D

Try it online!

⎕DDigits from zero to nine

1⌽ rotate one step right (puts zero at end)

 enclose (to treat as unit)

()↑¨¨ for each of these numbers, take that many characters from each of the letters:

⍳17 one through seventeen

¯9+ subtract nine

| find the absolute values

1+ add one

∊¨ enlist (flatten) each

 change one layer of depth into a level of rank (matrify)

  • 3
    In a compact language like this it seriously takes two bytes to add one? – aschepler Jul 4 '17 at 12:05
  • 3
    @aschepler Yes. APL is not a golfing language, and doesn't have an increment primitive. J does, but it takes two bytes; >:. – Adám Jul 4 '17 at 12:07
  • 4
    APL is not a golfing language ... ↑⊃¨,/¨(1+|¯9+⍳17)↑¨¨⊂1⌽⎕D ... ಠ_ಠ – Alexander Jul 6 '17 at 15:54
  • 1
    @Alexander Thanks for getting my attention back to this one. I could golf 3 bytes. – Adám Jul 6 '17 at 15:59

Haskell, 58 55 bytes

unlines["1234567890">>=(:(' '<$[1..abs n]))|n<-[-8..8]]

Try it online!

This is basically @nimi 's solution :)

Java 11 (JDK), 98 bytes

o->{for(int i=-9;++i<9;)System.out.println("".join(" ".repeat(i<0?-i:i),"1234567890".split("")));}

Try it online!

  • -14 bytes by switching to JDK 11, which now has a native String::repeat.

Previous answer (Java (OpenJDK 8)), 113 112 bytes

o->{for(int i=-9;++i<9;)System.out.printf("".join("%1$"+(i<0?-i:i>0?i:"")+"s","1234567890".split(""))+"%n","");}

Try it online!

Explanations

I'm basically constructing the following String 17 times (N is a variable, not an actual value):

"1%1$Ns2%1$Ns3%1$Ns4%1$Ns5%1$Ns6%1$Ns7%1$Ns8%1$Ns9%1$Ns0%n"

It's all the expected digits, joined by %1$Ns where N is the number of spaces between each digit.

%1$Ns basically means "take the first argument and pad it until length is at least N". Also, %1$0s is not supported so a special case %1$s is made for 0.

Finally, I format-print that string using a single argument: "", so the formatter reuses always the same empty string, padding it with spaces as needed.

Saves

  • 1 byte thanks to Kevin Cruijssen
  • 2
    Nice answer! Btw, I explicitly mentioned in the challenge an unused empty parameter is allowed, so you can replace ()-> with o-> to save a byte. :) – Kevin Cruijssen Jul 3 '17 at 10:57
  • Can you make o an int and use it in your for loop ? for(o=-9;++o<9;) – Winter Jul 9 '17 at 16:15
  • 2
    @Winter No, because the challenge says "unused", and that would use the parameter variable, even if the value wouldn't be used. – Olivier Grégoire Jul 9 '17 at 16:44
  • @OlivierGrégoire It links to this post codegolf.meta.stackexchange.com/questions/12681/… and this posts only says it should be empty (0 for ints). – Winter Jul 9 '17 at 16:47
  • @Indeed Indeed, but the challenge itself says "unused". Specific rulings in a challenge overrule defaults. – Olivier Grégoire Jul 9 '17 at 17:43

Japt -R, 19 18 16 14 bytes

Aõ%A
£qYçÃw Åê

Test it or try it online


Explanation

A             :10
 õ            :Range [1,10]
  %A          :Modulo each by 10
\n            :Assign to variable U
£             :Map each element at 0-based index Y
 q            :  Join U with
  Yç          :   Space repeated Y times
    Ã         :End map
     w        :Reverse
       Å      :Slice off first element
        ê     :Mirror
              :Implicitly join with newlines and output

Alternative

AõuA
9Æú´A qÃê

Test it or try it online

Explanation

Only the second line differs here.

9Æú´A qÃê
9Æ             :Map the rand [0,9)
   ´A          :  Decrement A
  ú            :  Left pad the elements in U to that length
      ¬        :  Join
        Ã      :End map
         ê     :Mirror
  • 2
    Nice. My 16-byte solution was 9ÆAõ%A qXîÃw ê · – ETHproductions Jul 3 '17 at 20:22

JavaScript(ES2017), 83 73 72 68 bytes

Thanks Shaggy for saving 10 bytes. Thanks Craig for saving 1 byte. Thanks arcs for saving 4 bytes.

for(i=-9,a="";i++<8;)a+=[...`1234567890
`].join("".padEnd(i<0?-i:i))

for(i=-9,a="";i++<8;)a+=[...`1234567890
`].join("".padEnd(i<0?-i:i))

console.log(a);
.as-console-wrapper { max-height: 100% !important; top: 0; }
.as-console-row:after { display: none !important; }

  • Save 1 byte by using a polyfill for Math.abs. I also made the a list not hardcoded, but that's a preference... a=[...Array(10).keys()];for(i=-8;i<9;i++)console.log(a.join(' '.repeat(i<0?-i:i))) – Thomas W Jul 3 '17 at 8:33
  • 1
    Save some bytes with [..."1234567890"].join("".padEnd(i<0?-i:i)) – Shaggy Jul 3 '17 at 8:35
  • @Shaggy Thanks. That saved 10 bytes. :) – Tushar Jul 3 '17 at 9:23
  • 1
    @ThomasW: [...Array(10).keys] would have 0 as the first element, not the last. – Shaggy Jul 3 '17 at 10:29
  • 1
    You can save a byte using your method storing the result in a string rather than logging: for(i=-8,s="";i<9;i++)s+=[..."1234567890"].join("".padEnd(i<0?-i:i))+`X`, where X is an actual newline – Craig Ayre Jul 4 '17 at 9:25

Brachylog, 30 29 28 bytes

Ị↺{∧≜;Ṣj₍g;?↔zcc}ᶠ⁹↔;XcP↔Pẉᵐ

Try it online!

Saved one byte thanks to Leaky Nun.

Explanation

Ị↺                               The string "1234567890"
  {               }ᶠ⁹            Find the first 9 outputs of:
   ∧≜                              Take an integer
       ;Ṣj₍                        Juxtapose " " that number of times
           g;?↔z                   Zip that string of spaces with "1234567890"
                cc                 Concatenate twice into one string
                    ↔            Reverse the resuling list
                     ;XcP↔P      Palindromize the list (concatenate X to it into the list P,
                                   P reversed is still P)
                           ẉᵐ    Map writeln
  • 2
    28 bytes – Leaky Nun Jul 3 '17 at 7:45
  • @LeakyNun I got stuck on the big "Print this exact text" and didn't read that we could have trailing lines… – Fatalize Jul 3 '17 at 7:49
  • 4
    23 bytes – Leaky Nun Jul 3 '17 at 7:50
  • 1
    @LeakyNun Why didn't you post your own answer? – Fatalize Jul 4 '17 at 7:19

Charcoal, 18 bytes

F⁹⪫⁺…I¹:⟦0¶⟧× ι‖B↑

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

F⁹      Repeat 9 times (i = loop variable)
  ⪫       Join
   ⁺       Concatentate
    …I¹:    All the characters from str(1) below ":" (i.e. to "9") as a list
    ⟦0¶⟧    A list whose element is the string "0\n"
   × ι     With i spaces
‖B↑     Reflect everything upwards but without duplicating the top line

Note: Cast(1) takes the same number of bytes because "1" would need a separator before ":" (which as it happens the deverbosifier fails to insert).

R, 108 bytes

for(i in abs(-8:8))cat(paste0(el(strsplit("1234567890","")),paste(rep(" ",i),collapse=""),collapse=""),"\n")

Just pasting and collapsing the strings.

Try it online!

Edit: thanks for Challenger5 for pointing out a problem. Fixed it now.

Edit 2: saved a byte thanks to bouncyball.

  • Welcome to the site! :) – DJMcMayhem Jul 3 '17 at 14:31
  • 2
    This doesn't look quite right - the middle line shouldn't have any spaces at all. – Esolanging Fruit Jul 4 '17 at 6:32
  • @Challenger5 you are right! fixed it by using paste0 instead of paste so had to add a byte:( – Probel Jul 4 '17 at 7:36
  • 1
    save 2 bytes using el: el(strsplit("1234567890","")) instead of strsplit("1234567890","")[[1]] – bouncyball Jul 5 '17 at 16:21
  • You can get rid of one of the paste statements by using the sep argument to cat and doing a bit more to get it to 70 bytes – Giuseppe Apr 5 at 13:36

Pyth, 14 13 bytes

1 byte thanks to Mnemonic.

V17j*da8NeMST

Try it online!

  • You can save a byte if you loop instead of mapping and joining. Try it here. – Mnemonic Apr 5 at 14:57

Java 8, 235 234 206 163 bytes

interface A{static void main(String[]a){for(int i=-8;i<9;i++){String s="";for(int j=1,k;j<10;j++){s+=j;for(k=0;k<(i>0?i:-i);k++)s+=" ";}System.out.println(s+0);}}}

Update : -28 bytes thanks to Leaky Nun !
Update 2 : -43 bytes thanks to Leaky Nun again !

Ungolfed :

interface A {
    static void main(String[] a) {
        for (int i = -8; i < 9; i++) {
            String s = "";
            for (int j = 1, k; j < 10; j++) {
                s += j;
                for (k = 0; k < (i > 0 ? i : -i); k++)
                    s += " ";
            }
            System.out.println(s + 0);
        }
    }
}

Try it online

EDIT : The code earlier was wrong ! Made a mistake while golfing the code, it should work as intended now !

  • 4
    Welcome to PPCG! Tips for golfing in Java and Tips for golfing in <all languages> might be interesting to read through. :) Some things you can golf is removing the public, and get rid of some unnecessary spaces. And there are some more things to improve, but I suggest to read through the tips, and see where you can improve yourself. Again welcome, and enjoy your stay! :) – Kevin Cruijssen Jul 3 '17 at 8:24
  • 2
    Hmm, also, are you sure you've posted the correct code? When I copy-paste your code into TryItOnline it doesn't give the correct output. – Kevin Cruijssen Jul 3 '17 at 8:27
  • 1
    Aww damn, i did something wrong while golfing the code ! I'll fix this ! – Alex Ferretti Jul 3 '17 at 8:31
  • 1
    148 bytes: one loop – Leaky Nun Jul 3 '17 at 9:07
  • 1
    144 bytes – Leaky Nun Jul 3 '17 at 9:36

Husk, 21 bytes

mΣṪ`:§+↔tḣR8' ṁs`:0ḣ9

This is a full program that prints to STDOUT. Try it online! There are lots of trailing spaces.

Explanation

Husk is still missing lots of essential stuff like a two-argument range function, so parts of this solution are a little hacky.

mΣṪ`:§+↔tḣR8' ṁs`:0ḣ9
              ṁs`:0ḣ9  This part evaluates to the string "1234567890".
                   ḣ9   Range from 1 to 9.
                `:0     Append 0.
              ṁs        Convert each number to string and concatenate.
     §+↔tḣR8'          This part evaluates to a list like ["  "," ",""," ","  "]
                       but with 17 elements instead of 5.
          R8'           A string of 8 spaces.
         ḣ              Take prefixes.
     §+                 Concatenate
       ↔                the reversal and
        t               tail of the prefix list, palindromizing it.
  Ṫ                    Take outer product of the two lists
   `:                  with respect to flipped prepeding.
                       This prepends each digit to each string of spaces.
mΣ                     Map concatenation over the results, computing the rows.
                       Implicitly join with newlines and print.
  • You could replace ṁs`:0ḣ9 with uṁsḣ10 to generate the string "1234567890" with one fewer byte! – Sophia Lechner Apr 5 at 16:48

T-SQL 145 152 bytes

DECLARE @ VARCHAR(MAX)=''SELECT TOP 17@+=REPLACE('1x2x3x4x5x6x7x8x9x0','x',SPACE(ABS(number-8)))+'
'FROM master..spt_values WHERE type='P'PRINT @

Updated to use:

  • master..spt_values to generate numbers (WHERE type = 'P', these are always consecutive, starting at 0)
  • @ZLK's TOP 17 idea
  • PRINT (to obey the rules - no stringlists)
  • @JanDrozen's great idea of including the carriage return in the string (I counted that as just one byte - Windows CRLF what?)
  • Idea of @Bridge to use just @ for variable name - all these tricks!!

Results:

1        2        3        4        5        6        7        8        9        0
1       2       3       4       5       6       7       8       9       0
1      2      3      4      5      6      7      8      9      0
1     2     3     4     5     6     7     8     9     0
1    2    3    4    5    6    7    8    9    0
1   2   3   4   5   6   7   8   9   0
1  2  3  4  5  6  7  8  9  0
1 2 3 4 5 6 7 8 9 0
1234567890
1 2 3 4 5 6 7 8 9 0
1  2  3  4  5  6  7  8  9  0
1   2   3   4   5   6   7   8   9   0
1    2    3    4    5    6    7    8    9    0
1     2     3     4     5     6     7     8     9     0
1      2      3      4      5      6      7      8      9      0
1       2       3       4       5       6       7       8       9       0
1        2        3        4        5        6        7        8        9        0

(Thanks @JanDrozen for the REPLACE idea)

  • This is a nice answer! Welcome to the site :) – DJMcMayhem Jul 3 '17 at 18:59
  • Thanks. I see some of us have invented our own languages here :) – DaveBoltman Jul 3 '17 at 19:22
  • 1
    A mix between this answer and the other is optimal: e.g. SELECT TOP 17REPLACE('1x2x3x4x5x6x7x8x9x0','x',SPACE(ABS(9-RANK()OVER(ORDER BY object_id))))FROM sys.objects (assuming you don't need to print). – ZLK Jul 4 '17 at 1:12
  • Aha @ZLK - a few nice tricks - TOP 17, RANK OVER, and sys.objects - thank you! – DaveBoltman Jul 4 '17 at 8:02

Clojure, 126 99 bytes

-27 by fixing a couple of dumb mistakes. The outer use of a wasn't necessary, so I was able to get rid of a altogether and just write apply str once. That also allowed me to use a function macro for the main function, which saved some bytes. I also inlined the call to Math/abs instead of rebinding n-spaces.

Basically a Clojure port of @Mr.Xcoder's Python idea. In retrospect, I should have used the abs/range method for the diamond challenge originally, but I then I may not have produced the bugged output!

Pretty simple. Joins the number string with a number of spaces that depends on the current row.

#(doseq[n(range -8 9)](println(clojure.string/join(apply str(repeat (Math/abs n)\ ))"1234567890")))

(defn bugged []
  (doseq [n-spaces (range -8 9)]
    (println
        (clojure.string/join
          ; "String multiplication"
          (apply str
                 (repeat (Math/abs n-spaces) \space))
          "1234567890"))))

Jelly, 15 bytes

8ŒRA⁶ẋØDṙ1¤jЀY

Try it online!

Mathematica, 92 bytes

Column@Join[Reverse@(s=Row/@Table[Riffle[Range@10~Mod~10,""<>Table[" ",i]],{i,0,8}]),Rest@s]

Try it online

copy/paste code with ctrl-v
press shift+enter to run

  • Could you perhaps add a TryItOnline link? – Kevin Cruijssen Jul 3 '17 at 7:34
  • @KevinCruijssen Mathematica is not a free language, and Mathics doesn't seem to work. – Leaky Nun Jul 3 '17 at 7:36
  • @LeakyNun Ah ok, thanks. I see MartinEnder post TIO-links sometimes, but those were indeed Mathics links. – Kevin Cruijssen Jul 3 '17 at 7:41
  • 1
    @Kevin Cruijssen yes of course, I added link with instructions – J42161217 Jul 3 '17 at 7:43

C, 97 bytes

i=-9;main(j){for(;++i<9;putchar(10))for(j=0;++j<11;printf("        "+8-abs(i)))putchar(48+j%10);}

Your compiler will probably complain a lot about this code; mine threw 7 warnings of 4 different types. Might improve the code later.

Try it online!

C (gcc), 76 bytes

f(x,y){for(y=-9;++y<9;puts(""))for(x=10;x++;printf("%-*d",abs(y)+1,x%=10));}

Try it online!

It outputs some trailing spaces, which is supposed to be OK.

It prints the numbers using left-justified fields of dynamic length - that's what the format string %-*d is for.

The inner loop has some funny initialization (starts from 10; any multiple of 10 would be fine) to "simplify" its termination condition.

Python 3, 58 57 54 bytes

i=8
while i+9:print(*'1234567890',sep=' '*abs(i));i-=1

Try it online!

(thanks to @flornquake for the last three bytes; I completely forgot using sep to save vs. .join)

  • 1
    54 bytes: while i+9:print(*'1234567890',sep=' '*abs(i));i-=1 – flornquake Jul 8 '17 at 12:30

Charcoal, 21 20 19 18 bytes

F⁹«F…¹χ⁺κ… ι0⸿»‖B↑

Try it online!

Link to the verbose version. Basically I create the lower part of the drawing and then reflect the text up.

  • 1
    When I saw the question I though I'd try this myself in Charcoal before looking at the answer. I started with a 21-byte answer but golfed it to 20 bytes... spooky! – Neil Jul 3 '17 at 8:02
  • @Neil :-D Well, it's 19 bytes now! – Charlie Jul 3 '17 at 8:08
  • Yup, just found that golf myself. I was also looking into E…⁹⪫E…·¹χI﹪κχ× ι‖B↑ (also for 19 bytes) but the interpreter doesn't seem to like it (I can't see what's wrong with it myself). – Neil Jul 3 '17 at 8:24
  • Oh, Range takes two arguments, silly me. – Neil Jul 3 '17 at 8:53
  • 1
    Turns out Map was a red herring, so I've now posted my 18-byte answer. – Neil Jul 3 '17 at 10:30

CJam, 21 bytes

A,(+aH*ee{:\8-zS**n}/

Try it online!

Explanation

A,     e# Get [0 1 2 ... 9].
(+     e# Rotate the 0 to the end.
aH*    e# Wrap in an array and repeat 17 times.
ee     e# Enumerate. This pairs each copy of the array with its index in
       e# the list.
{      e# For each [index array] pair...
  :\   e#   Unwrap the pair and swap its order.
  8-z  e#   Get the absolute difference of the index from 8.
  S*   e#   Get a string of that many spaces.
  *    e#   Riffle the list of digits with the string of spaces.
  n    e#   Print it with a trailing linefeed.
}/
  • 1
    Alternative solution (also 21 bytes): 9{S*A,(+\*}%_W%);\+N* – Esolanging Fruit Jul 4 '17 at 6:10

Batch, 163 bytes

@set s=1 2 3 4 5 6 7 8 9 0
@set t=         
@for %%l in (9 7)do @for /l %%i in (1,1,%%l)do @call:%%l
:7
@set t=  %t%
:9
@set t=%t:~1%
@call echo %%s: =%t%%%

Note: First line ends in 9 spaces. Explanation: Uses creative line numbering! The first loop needs to run 9 times and delete a space each time, while the second loop needs to run 8 times and add a space each time. The former is achieved by running it 7 times and falling through for the 8th time, while the latter is achieved by adding two spaces and falling through to delete one of them again.

SOGL V0.12, 14 bytes

ā9{SUčf@*∑Κ}╬Æ

Try it Here!

Explanation:

ā               push an empty array
 9{        }    9 times do
   SU             push "1234567890"
     č            chop into characters
      f@*         get current iteration (0-based) amount of spaces
         ∑        join with that
          Κ       prepend this to the array
            Β  palindromize vertically with 1 overlap

PHP, 69 bytes

for(;$i<17;)echo join(str_pad("",abs($i++-8)),range(1,9)+[9=>0]),"
";

Try it online!

PowerShell, 30 bytes

8..0+1..8|%{1..9+0-join' '*$_}

Try it online!

Constructs a range of 8,7,6...2,1,0,1,2...8 then loops through each number. Inside the loop we construct a range of 1..9 concatenated with 0 then -join the numbers in the range together with the appropriate number of spaces. Each string is left on the pipeline, and output is implicit at program completion.

  • 1
    Nice answer! Powershell suddenly feels more golfy :) – Mr. Xcoder Aug 29 '17 at 19:56

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.