93
\$\begingroup\$

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.
\$\endgroup\$
5
  • \$\begingroup\$ Is outputting an array of strings - 1 string per line - allowed? \$\endgroup\$
    – Shaggy
    Jul 3 '17 at 9:37
  • \$\begingroup\$ @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. \$\endgroup\$ Jul 3 '17 at 11:06
  • \$\begingroup\$ No worries, Kevin; was just chancing my arm to see if I could save myself a couple of bytes. \$\endgroup\$
    – Shaggy
    Jul 3 '17 at 11:09
  • 3
    \$\begingroup\$ @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? ;) \$\endgroup\$ Jul 3 '17 at 11:23
  • 12
    \$\begingroup\$ Ha, that's awesome. I was wondering why that answer suddenly got so much attention. Thanks! \$\endgroup\$ Jul 3 '17 at 19:41

86 Answers 86

1 2
3
1
\$\begingroup\$

[Java 7], 137 132 bytes

Saved 3 bytes thanx to Kevin Cruijssen and 2 more thanx to TheLethalCoder

void a(){int i,j,k;for(i=-8;i<9;i++){String a="";for(j=1;j<11;j++){a+=j%10;for(k=0;k<(i<0?-i:i);k++)a+=" ";}System.out.println(a);}}

 void a(){for(int i=-8;i<9;i++){String a="";for(int j=1;j<11;j++){a+=j%10;for(int k=0;k<Math.abs(i);k++){a+=" ";}}System.out.println(a);}}

Ungolfed:

  void a(){
    int i,j,k;
    for(i=-8;i<9;i++){
        String a="";
        for(j=1;j<11;j++){
            a+=j%10;
            for(k=0;k<(i<0?-i:i);k++)a+=" ";
        }
        System.out.println(a);
    }
}
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Declare i, j, and k in one place to save bytes (I'm sure you go do this in Java). Use Java 8 and compile to an anonymous method. I think int i=-9;++i<9;i should work and similar for j and k. I'm not sure if Math needs qualifying but I don't know Java well enough to say for sure. I think you can remove the braces from the k loop as well. \$\endgroup\$ Jul 5 '17 at 8:29
  • \$\begingroup\$ Also it might be cheaper, especially when compiling to a lambda, to return the results as a string. \$\endgroup\$ Jul 5 '17 at 8:31
  • 2
    \$\begingroup\$ Welcome to PPCG! There is already a shorter Java answer posted, but that doesn't matter because it uses a different approach. But, you can still shorten your code a bit like this: void a(){for(int i=-8,j,k;i<9;i++){String a="";for(j=1;j<11;)for(a+=j++%10,k=0;k++<(i<0?-i:i);)a+=" ";System.out.println(a);}}. (I've put some things inside the for-loop to get rid of the brackets; I've removed the two int by adding ,j,k in the first loop; and I've changed Math.abs(i) to (i<0?-i:i). It might also be useful to read Tips for golfing in Java. :) Enjoy your stay. \$\endgroup\$ Jul 5 '17 at 8:33
1
\$\begingroup\$

C#, 131 bytes

My first participation

for(int i=8;i>-9;i--){for(int n=1;n<=10;n++){Console.Write((n==10?"0":n.ToString())+new String(' ',Math.Abs(i))+(n==10?"\n":""));}}

More easy reading version

for (int i = 8; i > -9; i--)
{
    for (int n = 1; n <= 10; n++)
    {
        Console.Write((n==10 ? "0" : n.ToString()) + new String(' ', Math.Abs(i)) + (n == 10 ? "\n" : ""));
    }
}
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Welcome to PPCG.SE! A nice first post though by default, you should supply a full program or function, not just a snippet like you have here. See this meta post for more. I would also recommend you have a look at Try it Online which lets you run your code online and share it with others. It can also format your answers for you to post here. \$\endgroup\$ Jul 6 '17 at 10:47
  • 1
    \$\begingroup\$ Welcome to PPCG! In addition to what @Notts90 said, I can also recommend reading Tips for golfing in C# and Tips for golfing in <all languages>. Some things you can golf is removing the brackets and int; change the condition to remove the =; and change the Math.abs, like this: o=>{for(int i=8,n;i>-9;i--)for(n=1;n<11;n++)Console.Write((n>9?0:n)+new String(' ',i<0?-i:i)+(n>9?"\n":""));} (where o=> is an unused parameter). Try it here. Again welcome, and enjoy your stay. :) \$\endgroup\$ Jul 6 '17 at 11:03
  • \$\begingroup\$ Oh, and one more thing after my previous golfed version: o=>{for(int i=8,n;i>-9;i--)for(n=1;n<11;)Console.Write((n>9?0:n)+new String(' ',i<0?-i:i)+(n++>9?"\n":""));} (the n++ is removed and ++ is added to the last n. Try it here. So 108 bytes in total. \$\endgroup\$ Jul 6 '17 at 11:47
  • \$\begingroup\$ Thanks for the comments Notts90 and Kevin, I will look at your code this evening :) \$\endgroup\$ Jul 6 '17 at 12:21
1
\$\begingroup\$

tcl, 112

Very naïve:

proc x n\ s {time {puts [join {1 2 3 4 5 6 7 8 9 0} [format %[incr n $s]s \ ]]} 9}
x 10 -1
puts 1234567890
x 0 1

demo

\$\endgroup\$
1
1
\$\begingroup\$

/// (Slashes), 377 374 bytes

/a/1_//b/2_//c/3_//d/4_//e/5_//f/6_//g/7_//h/8_//i/9_//z/0
//./  //-/. //_/../a_b_c_d_e_f_g_h_i_za-b-c-d-e-f-g-h-i-za.b.c.d.e.f.g.h.i.za b c d e f g h i zabcdefghiz1-2-3-4-5-6-7-8-9-z1.2.3.4.5.6.7.8.9.z1 2 3 4 5 6 7 8 9 z123456789z1 2 3 4 5 6 7 8 9 z1.2.3.4.5.6.7.h.9.z1-2-3-4-5-6-7-8-9-zabcdefghiza b c d e f g h i za.b.c.d.e.f.g.h.i.za-b-c-d-e-f-g-h-i-za_b_c_d_e_f_g_h_i_0

Try it online!

Explanation

The original output was initially compressed by doing the following replacements:

  •      (4 spaces)_
  •     (3 spaces)-
  •    (2 spaces).

In a second step, 1_ was replaced by a, 2_ by b and so on. Finally, those mappings were inverted and prepended to the code.

Additional step (thx to CalculatorFeline):

/./  //-/   //_/    //_/..//-/. //./  /

\$\endgroup\$
2
  • \$\begingroup\$ /./ //-/ //_/ / can be /_/..//-/. //./ /. Imagine the spaces being correct because Markdown doesn't like multiple spaces in inline code blocks >:( \$\endgroup\$ Jul 9 '17 at 21:17
  • \$\begingroup\$ @CalculatorFeline Thanks, missed that one. Btw, you can fake the spaces with "figure space" (U+2007), markdown doesn't seem to collapse those (it's what I did in the post as well). \$\endgroup\$ Jul 10 '17 at 7:07
1
\$\begingroup\$

Sink, 102 100 bytes

var v=range 0,17
var p=list.push(range 0,10),0
for var s:v
say list.join p,str.pad"",num.abs s-8
end

Try it online! (sort of, it's just a repl so you'll need to type it in)

-2 bytes thanks to @Kevin Cruijssen

\$\endgroup\$
1
  • \$\begingroup\$ Welcome to PPCG! Nice first answer, +1 from me. I've never even heard of Sink before, so it's always great to see a new programming language. Btw, I tried some things in the REPL, and if I'm not mistaken you can golf two spaces on this line: say list.join p,str.pad"",num.abs s-8. Again welcome, and enjoy your stay. :) \$\endgroup\$ Jul 8 '17 at 7:44
1
\$\begingroup\$

Lua, 106 85 bytes

-21 bytes thanks to user202729

n="1L2L3L4L5L6L7L8L9L0"for i=-8,8,1 do print((n:gsub("L",(" "):rep(math.abs(i)))))end

Output has a trailing newline

Ungolfed

n="1L2L3L4L5L6L7L8L9L0"
for i=-8,8,1 do 
    print((n:gsub("L",(" "):rep(math.abs(i)))))
end

Try It Online

\$\endgroup\$
3
  • \$\begingroup\$ Hi there. Would you mind adding a TIO-link with test code? Lua should be available on TIO as well. \$\endgroup\$ Apr 5 '18 at 7:36
  • \$\begingroup\$ You can save 5 bytes by using (" "):rep. \$\endgroup\$
    – DELETE_ME
    Apr 5 '18 at 12:37
  • \$\begingroup\$ You can also get it down to 82 bytes with pattern. Hint: %1. \$\endgroup\$
    – DELETE_ME
    Apr 5 '18 at 12:43
1
\$\begingroup\$

brainfuck, 209 bytes

++++++++[->+>+>+>++++>++++++>+>>+<<<<<<<<]>++>+>+>>>>>+<<<<<<-[->>>>>>[-<<<+.>[-<<.>>>+<]>[-<+>]>>+<]>[-<+<<<->>>>]<<<-<.<<<<.>]>[->>>>>[-<<<+.>>>>>[->+<<<<<<<.>>>>>>]>[-<+>]<<+<]>[-<+<<<->>>>]>+<<<<<.<<<<.>>]

Try it online!

I noticed there wasn’t a brainfuck submission yet, so I gave it my best shot. Definitely not the most golfed solution possible, but I’m not upset with the result.

\$\endgroup\$
1
\$\begingroup\$

Canvas, 20 15 bytes

9{9∔ ×9R0∔∑;*]─

Try it here!

Explanation:
9{9∔ ×9R0∔∑;*]─  | (Full code)
                        | Print (implicit)
    9∔ ×               | 9-i spaces
         9R0∔∑;*    | Inserted between the characters of the string "1234567890"
9{                    | For each i in [1-9]
                   ]   | Separated by newlines
                     ─  | Palindromized vertically with 1 line of overlap
\$\endgroup\$
1
\$\begingroup\$

QBasic, 66 bytes

An undeclared subroutine that takes no input and outputs to STDOUT

FOR i=-8TO 8
FOR j=49TO 57
?CHR$(j)SPC(ABS(i));
NEXT
?"0
NEXT
\$\endgroup\$
1
\$\begingroup\$

Elixir, 126 bytes

Enum.each 8..-8,fn n->IO.puts Enum.map Enum.into(1..10,[],&(rem &1,10)),&(Integer.to_string(&1)<>String.duplicate" ",abs n)end

Try it online!

Enum.each 8..-8,
          fn n->
            IO.puts 
              Enum.map 
                Enum.into(1..10, [], &(rem &1,10)),
                &(Integer.to_string(&1) <> String.duplicate" ",abs n)
          end

For each number in the range 8 to -8, do this anonymous function with the number as n. The function (inner to outer) sets the range 1 to 10 into a list after applying the remainder mod 10 (so we have the list 1,2,3,4,5,6,7,8,9,0). Then maps that list of numbers into strings, and concatenates the absolute value of n spaces onto the end. After getting each string we print out the whole list of strings... and Elixir doesn't put any delimiter on that by default.

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        
\$\endgroup\$
1
\$\begingroup\$

Sisi, 239 bytes

0set s8
1set d0-1
2set o""
3set i1
4set o o+i
5jumpif i7
6jump17
7set x s
8jump11
9set o o+" "
10set x x-1
11jumpif x9
12set c9>i
13jumpif c15
14set i0-1
15set i1+i
16jump4
17print o
18set s s+d
19jumpif s21
20set d1
21set q9>s
22jumpif q2

Try it online!

The basic strategy is to run a loop from 8 down to 0 and back up to 8, constructing each line accordingly and printing it. I'm not going to write a detailed explanation, but if you're trying to follow the algorithm, the following key to the variable names may be helpful:

  • s: number of spaces to print between digits
  • d: direction of change in s (-1 or 1)
  • o: the current line of output
  • i: the current digit
  • x: loop counter while printing spaces
  • c: conditional that tests whether i is less than 9 (if not, we set it to -1 so it gets incremented to 0 instead of 10)
  • q: conditional that tests whether s is less than 9 (if so, we continue looping)
\$\endgroup\$
2
1
\$\begingroup\$

///, 244 bytes

/*/\/\///X/0
1*j/\/X*x/  *S/x *s/SS*-/S *_/s *(/- *)/_ *A/)2)3)4)5)6)7)8)9)*Bj_2_3_4_5_6_7_8_9_*Cjs2s3s4s5s6s7s8s9s*Dj(2(3(4(5(6(7(8(9(*Ej-2-3-4-5-6-7-8-9-*FjS2S3S4S5S6S7S8S9S*Gjx2x3x4x5x6x7x8x9x*Hj 2 3 4 5 6 7 8 9 /1ABCDEFGHX23456789HGFEDCBXA0

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Tcl, 99 bytes

time {incr i;time {puts -nonewline [incr j][string repe " " [expr abs(9-$i)]]} 9;puts 0;unset j} 17

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Pushy, 27 bytes

Not the most elegant solution, but it does the job.

N9X@wL:Ocv:32;ZT:hT%#^"v;T'

Try it online!

Explanation:

N                                \ Set printing delimiter to empty string
 9X                              \ Push range(9) to stack: [0, 1, 2, 3, 4, 5, 6, 7, 8]
   @                             \ Reverse: [8, 7, 6, 5, 4, 3, 2, 1, 0]
    w                            \ Mirror: [8, 7, 6... 1, 0, 1... 6, 7, 8]
     L:                          \ Length (17) times do:
       Oc                        \   Go to (cleared) auxiliary stack
         v:                      \   Pop top of main stack, and that many times:
           32;                           Push character 32 (space)
              Z                  \   Push 0
               T                 \   Ten times do:
                :hT%             \      counter = (counter + 1) mod 10
                    #            \      Print the counter
                     ^"v;        \      Print the rest of the stack (spaces)
                         T'      \   Print a newline
\$\endgroup\$
1
  • \$\begingroup\$ Would you mind adding an explanation? \$\endgroup\$ Dec 16 '18 at 19:05
1
\$\begingroup\$

Rockstar, 127 126 124 bytes

-1 byte thanks to Kevin

F takes X
cut 1234567890 into L
join L with " "*X
say L

X's9
while X
let X be-1
F taking X

while X-8
let X be+1
F taking X

Try it here (Code will need to be pasted in)

\$\endgroup\$
2
  • \$\begingroup\$ Based on your other Rockstar answer the space can be removed at be-1, right? \$\endgroup\$ Sep 11 '20 at 12:21
  • \$\begingroup\$ Thanks, @KevinCruijssen. Dunno how that snuck in there; omitting that space is one of my favourite wee byte-saving tricks in Rockstar. \$\endgroup\$
    – Shaggy
    Sep 11 '20 at 13:13
1
\$\begingroup\$

Stax, 12 bytes

ü¡↑├☼Rσ┬q▄└m

Run and debug it

can probably tie mathgolf. Port of Emigna's answer.

\$\endgroup\$
1
\$\begingroup\$

Pip -l, 18 16 bytes

(\,t)%tJsXPZRV,9

Try it online!

Explanation

                  t is 10, s is " " (implicit)
              ,9  Range(9): [0 1 2 3 4 5 6 7 8]
            RV    Reverse: [8 7 6 5 4 3 2 1 0]
          PZ      Palindromize: [8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8]
        sX        For each element of the above list, a string of that many spaces
 \,t              Inclusive-range(10): [1 2 3 4 5 6 7 8 9 10]
(   )%t           Mod 10: [1 2 3 4 5 6 7 8 9 0]
       J          For each string of spaces, join the above list on that string
                  Output the list of results one per line (`-l` flag)

The PZ operator was added more than a year after this challenge was posted, so here's a 17-byte answer that would have worked at that time:

(\,t)%tJsXAB:-8,9

Try it online!

\$\endgroup\$
1
\$\begingroup\$

BRASCA, 72 bytes

8[a09Ir,m[oA:a[Eo{]x]xloA{]x09Ir,m[o]lo8[9$-a09Ir,m[oA:a[Eo{]x]xloA}9$-]

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Deadfish~, 2606 bytes

ioi{iii}cccccccc{ddd}o{iii}ccccccccd{ii}ci{dd}cccccccc{ii}c{dd}cccccccci{ii}cd{dd}ccccccccii{ii}cdd{dd}ccccccccd{{{i}}}odsddddcccccccc{{{i}}}oddsddddcccccccci{ddd}soiii{ii}cccccccc{{d}}o{i}ci{d}oi{iii}ccccccc{ddd}o{iii}cccccccd{ii}ci{dd}ccccccc{ii}c{dd}ccccccci{ii}cd{dd}cccccccii{ii}cdd{dd}cccccccd{{{i}}}odsddddccccccc{{{i}}}oddsddddccccccci{ddd}soiii{ii}ccccccc{{d}}o{i}ci{d}oi{iii}cccccc{ddd}o{iii}ccccccd{ii}ci{dd}cccccc{ii}c{dd}cccccci{ii}cd{dd}ccccccii{ii}cdd{dd}ccccccd{{{i}}}odsddddcccccc{{{i}}}oddsddddcccccci{ddd}soiii{ii}cccccc{{d}}o{i}ci{d}oi{iii}ccccc{ddd}o{iii}cccccd{ii}ci{dd}ccccc{ii}c{dd}ccccci{ii}cd{dd}cccccii{ii}cdd{dd}cccccd{{{i}}}odsddddccccc{{{i}}}oddsddddccccci{ddd}soiii{ii}ccccc{{d}}o{i}ci{d}oi{iii}cccc{ddd}o{iii}ccccd{ii}ci{dd}cccc{ii}c{dd}cccci{ii}cd{dd}ccccii{ii}cdd{dd}ccccd{{{i}}}odsddddcccc{{{i}}}oddsddddcccci{ddd}soiii{ii}cccc{{d}}o{i}ci{d}oi{iii}ccc{ddd}o{iii}cccd{ii}ci{dd}ccc{ii}c{dd}ccci{ii}cd{dd}cccii{ii}cdd{dd}cccd{{{i}}}odsddddccc{{{i}}}oddsddddccci{ddd}soiii{ii}ccc{{d}}o{i}ci{d}oi{iii}cc{ddd}o{iii}ccd{ii}ci{dd}cc{ii}c{dd}cci{ii}cd{dd}ccii{ii}cdd{dd}ccd{{{i}}}odsddddcc{{{i}}}oddsddddcci{ddd}soiii{ii}cc{{d}}o{i}ci{d}oi{iii}c{ddd}o{iii}cd{ii}ci{dd}c{ii}c{dd}ci{ii}cd{dd}cii{ii}cdd{dd}cd{{{i}}}odsddddc{{{i}}}oddsddddci{ddd}soiii{ii}c{{d}}o{i}ciio{d}ioioioioioioioi{d}o{i}ci{d}oi{iii}c{ddd}o{iii}cd{ii}ci{dd}c{ii}c{dd}ci{ii}cd{dd}cii{ii}cdd{dd}cd{{{i}}}odsddddc{{{i}}}oddsddddci{ddd}soiii{ii}c{{d}}o{i}ci{d}oi{iii}cc{ddd}o{iii}ccd{ii}ci{dd}cc{ii}c{dd}cci{ii}cd{dd}ccii{ii}cdd{dd}ccd{{{i}}}odsddddcc{{{i}}}oddsddddcci{ddd}soiii{ii}cc{{d}}o{i}ci{d}oi{iii}ccc{ddd}o{iii}cccd{ii}ci{dd}ccc{ii}c{dd}ccci{ii}cd{dd}cccii{ii}cdd{dd}cccd{{{i}}}odsddddccc{{{i}}}oddsddddccci{ddd}soiii{ii}ccc{{d}}o{i}ci{d}oi{iii}cccc{ddd}o{iii}ccccd{ii}ci{dd}cccc{ii}c{dd}cccci{ii}cd{dd}ccccii{ii}cdd{dd}ccccd{{{i}}}odsddddcccc{{{i}}}oddsddddcccci{ddd}soiii{ii}cccc{{d}}o{i}ci{d}oi{iii}ccccc{ddd}o{iii}cccccd{ii}ci{dd}ccccc{ii}c{dd}ccccci{ii}cd{dd}cccccii{ii}cdd{dd}cccccd{{{i}}}odsddddccccc{{{i}}}oddsddddccccci{ddd}soiii{ii}ccccc{{d}}o{i}ci{d}oi{iii}cccccc{ddd}o{iii}ccccccd{ii}ci{dd}cccccc{ii}c{dd}cccccci{ii}cd{dd}ccccccii{ii}cdd{dd}ccccccd{{{i}}}odsddddcccccc{{{i}}}oddsddddcccccci{ddd}soiii{ii}cccccc{{d}}o{i}ci{d}oi{iii}ccccccc{ddd}o{iii}cccccccd{ii}ci{dd}ccccccc{ii}c{dd}ccccccci{ii}cd{dd}cccccccii{ii}cdd{dd}cccccccd{{{i}}}odsddddccccccc{{{i}}}oddsddddccccccci{ddd}soiii{ii}ccccccc{{d}}o{i}ci{d}oi{iii}cccccccc{ddd}o{iii}ccccccccd{ii}ci{dd}cccccccc{ii}c{dd}cccccccci{ii}cd{dd}ccccccccii{ii}cdd{dd}ccccccccd{{{i}}}odsddddcccccccc{{{i}}}oddsddddcccccccci{ddd}soiii{ii}cccccccc{{d}}o

Try it online!

Deadfish~ has two output commands, o to print the accumulator as an integer and c to print a character. All whitespace is printed with c, and 84 of the 190 digits are printed with c, determined by an exhaustive search. If you're interested, here is the semi-golfed and fully unreadable generator: Try it online!

\$\endgroup\$
1
\$\begingroup\$

Excel, 74 bytes

=LET(x,MOD(COLUMN(A:J),10),CONCAT(x&IF(x,REPT(" ",ABS(ROW(1:17)-9)),"
")))

Link to Spreadsheet

The version without LET that would have been valid when the question was asked is only 2 bytes longer.

Without LET, 76 bytes

=CONCAT(RIGHT(COLUMN(A:J))&IF(COLUMN(A:J)>9,"
",REPT(" ",ABS(ROW(1:17)-9))))
\$\endgroup\$
0
\$\begingroup\$

Python 2, 72 bytes

for i in range(-8,9):print(('%-'+'%ds'%-~abs(i))*10)%tuple('1234567890')

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Vim, 53 bytes

i1234567890^[^qq8a ^[lq8@qqeYpPqqqlxbequ^qw9@q@eq7@wdj

Where ^[ is the ESC Key.

i1234567890^[^       puts 1-9+0 in the buffer and returns the cursor to the beginning
qq8a ^[lq8@q         puts 8 spaces between each of the numbers
qeYpPq               records @e to duplicate the line twice and stay on the middle one
qqlxbequ^            records @q to delete one space between numbers and undoes it
qw9@q@eq             records @w to do @q 9 times, then @e
7@wdj                does @w 7 more times, then deletes two lines
\$\endgroup\$
0
\$\begingroup\$

Python, 84 bytes

for x in range(-8,9):
 z=""
 for y in range(1,11):z+=str(y%10)+" "*abs(x)
 print(z)

Try it online

\$\endgroup\$
0
\$\begingroup\$

VBA, 58 bytes

An immediate window function that takes no input and outputs to the console.

For i=-8To 8:For j=1To 9:?j &""Spc(Abs(i));:Next:?"0":Next

Ungolfed and Commented

For i=-8To 8        ''  Iterate `i` from `-8` to `8`
For j=1To 9         ''  Iterate `j` from `1` to `9`
?j &""Spc(Abs(i));  ''  Print `j` and `i` spaces
Next                ''  Loop `j`
?"0"                ''  Print `0`, with a newline
Next                ''  Loop `i`
\$\endgroup\$
0
\$\begingroup\$

JavaScript, 71 bytes

f=(i=8,q=[..."1234567890"].join(" ".repeat(i)))=>i?q+`
`+f(i-1)+`
`+q:q
\$\endgroup\$
0
\$\begingroup\$

Java (JDK), 105 103 bytes

a->{for(int j,i=-9;i++<8;){var s="";for(j=0;j++<9;)s+=j+" ".repeat(i<0?-i:i);System.out.println(s+0);}}

Try it online!

Thanks to ceilingcat for -2

\$\endgroup\$
0
1 2
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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