It was just a bug

77

14

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.

Kevin Cruijssen

Posted 8 years ago

Reputation: 67 575

Is outputting an array of strings - 1 string per line - allowed? – Shaggy – 8 years ago

@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 – 8 years ago

No worries, Kevin; was just chancing my arm to see if I could save myself a couple of bytes. – Shaggy – 8 years ago

3@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 – 8 years ago

8Ha, that's awesome. I was wondering why that answer suddenly got so much attention. Thanks! – Carcigenicate – 8 years ago

Answers

7

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

dzaima

Posted 8 years ago

Reputation: 19 048

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 – 7 years ago

@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 – 7 years ago

62

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().

Mr. Xcoder

Posted 8 years ago

Reputation: 39 774

176 bytes – Leaky Nun – 8 years ago

@LeakyNun Just updating with 77 :P

– Mr. Xcoder – 8 years ago

62 bytes – Leaky Nun – 8 years ago

559 bytes – Leaky Nun – 8 years ago

23This is farm more impressive than 25 bytes in any golfing language imho. – Jylo – 8 years ago

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 – 8 years ago

You can save one more byte by losing the 'range' for a 'while'. <a href="https://tio.run/##K6gsycjPM/r/P9NW14KrPCMzJ1Uh08bSqqAoM69EQ11BXSsxqVgjU1NTLys/M09D3dDI2MTUzNzC0kBd0zpT29bw/38A" title="56 bytes">Try it online!</a> – Coty Johnathan Saxman – 8 years ago

You can save another byte. Start with positive 8 and decrement it at the end. With that you omit the minus character :) – Praind – 8 years ago

Just a noob programmer asking a noob question: Can't you replace i-=1 with i--, saving a byte? – Jason Chen – 8 years ago

2@JasonChen No, Python does not allow that syntax, because that's specific to C-like languages. – Mr. Xcoder – 8 years ago

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 – 8 years ago

32

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

James

Posted 8 years ago

Reputation: 54 537

6I don't even care that this isn't the winner, it's beautiful. – MrDuk – 8 years ago

@MrDuk Thankyou! I'm glad you like it :) – James – 8 years ago

21

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

Emigna

Posted 8 years ago

Reputation: 50 798

1Hmm...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 – 8 years ago

@EriktheOutgolfer: Or I could switch up my method and save that 1 byte I needed :) – Emigna – 8 years ago

Sorry already upvoted. – Erik the Outgolfer – 8 years ago

@EriktheOutgolfer: I don't see what that has to do with anything. Thanks for notifying me that I needed to golf my answer :) – Emigna – 8 years ago

3That means I'd have upvoted again... – Erik the Outgolfer – 8 years ago

@EriktheOutgolfer let me do it for you.... Here we go. – Andrew Savinykh – 8 years ago

48F9ÝÀNð×ý}».∊ I done did made a spaceship maw! And I was all excited about suggesting a 12-byte edit. – Magic Octopus Urn – 8 years ago

@MagicOctopusUrn: Hehe, yeah I made a spaceship while golfing as well :) – Emigna – 8 years ago

Hi, someone else just posted a 12-byte solution. Since it's been a couple of months ago since I accepted yours, I'm not sure what the policy is. Since the other one is shorter, I'm thinking about accepting that one, but since I feel it's also unfair to you I'd like to ask your opinion about this first as well. Should I leave the accepted mark, or accept another answer if a shorter one comes up in the future?

– Kevin Cruijssen – 7 years ago

There are lots of alternate 13s, like 9LRûv9ÝÀÀyjÁ, or 9LR©ûv®yjR?0,. It feels like 12 should be possible. – Grimmy – 5 years ago

20

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)

Jupp3

Posted 8 years ago

Reputation: 301

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 – Евгений Новиков – 8 years ago

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 – 7 years ago

17

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

Jan Drozen

Posted 8 years ago

Reputation: 491

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 – 8 years ago

Replace sys.objects with sysobjects, and 1object_idwithidI looked for shorter tables in thesysschema, but nothing short had columns as short assysobjects` – Jaloopa – 8 years ago

And you can save another few bytes by changing the inner CAST (with the POWER(10)) to VARCHAR – Jaloopa – 8 years ago

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 – 8 years ago

You can change the variable name to just @ to shave off 3 characters. – Bridge – 8 years ago

14

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)

Adám

Posted 8 years ago

Reputation: 37 779

3In a compact language like this it seriously takes two bytes to add one? – aschepler – 8 years ago

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 – 8 years ago

4APL is not a golfing language ... ↑⊃¨,/¨(1+|¯9+⍳17)↑¨¨⊂1⌽⎕D ... ಠ_ಠ – Alexander - Reinstate Monica – 8 years ago

1@Alexander Thanks for getting my attention back to this one. I could golf 3 bytes. – Adám – 8 years ago

13

Haskell, 58 55 bytes

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

Try it online!

This is basically @nimi 's solution :)

bartavelle

Posted 8 years ago

Reputation: 1 261

12

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

Olivier Grégoire

Posted 8 years ago

Reputation: 10 647

2Nice 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 – 8 years ago

Can you make o an int and use it in your for loop ? for(o=-9;++o<9;) – Winter – 8 years ago

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 – 8 years ago

@OlivierGrégoire It links to this post https://codegolf.meta.stackexchange.com/questions/12681/are-we-allowed-to-use-empty-input-we-wont-use-when-no-input-is-asked-regarding and this posts only says it should be empty (0 for ints).

– Winter – 8 years ago

@Indeed Indeed, but the challenge itself says "unused". Specific rulings in a challenge overrule defaults. – Olivier Grégoire – 8 years ago

Just came across this answer again. In Java 11 this can become 98 bytes with the use of " ".repeat :D I liked your original answer with printf more though, but figured it's worth mentioning. EDIT: Just noticed you are asking about updating the JDK in the talk.tio chat. XD Was about to do that myself.

– Kevin Cruijssen – 6 years ago

11

Japt -R, 19 18 16 14 13 bytes

Aõ%A
£qYçÃÔÅê

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
     Ô       :Reverse
      Å      :Slice off first element
       ê     :Mirror
             :Implicitly join with newlines and output

Shaggy

Posted 8 years ago

Reputation: 24 623

2Nice. My 16-byte solution was 9ÆAõ%A qXîÃw ê · – ETHproductions – 8 years ago

8

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; }

Tushar

Posted 8 years ago

Reputation: 181

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 – 8 years ago

1Save some bytes with [..."1234567890"].join("".padEnd(i<0?-i:i)) – Shaggy – 8 years ago

@Shaggy Thanks. That saved 10 bytes. :) – Tushar – 8 years ago

@ThomasW I used [...'1234567890'], it saved 3 bytes. Thanks for the polyfill. – Tushar – 8 years ago

1@ThomasW: [...Array(10).keys] would have 0 as the first element, not the last. – Shaggy – 8 years ago

1You 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 – 8 years ago

This would be considered JavaScript (ES8) due to its use of padEnd. – darrylyeo – 8 years ago

@CraigAyre Thanks. And nice to see you here. :) – Tushar – 8 years ago

@darrylyeo True. I've mentioned it. – Tushar – 8 years ago

You can save even more by shorting the for to for(i=-9,a="";i++<8;) and defining the array as [...1234567890 ] (line break as last character of this), with that you can remove the last addition. – arcs – 8 years ago

@arcs Thanks. Answer updated. :) – Tushar – 8 years ago

7

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

Fatalize

Posted 8 years ago

Reputation: 32 976

228 bytes – Leaky Nun – 8 years ago

@LeakyNun I got stuck on the big "Print this exact text" and didn't read that we could have trailing lines… – Fatalize – 8 years ago

423 bytes – Leaky Nun – 8 years ago

1@LeakyNun Why didn't you post your own answer? – Fatalize – 8 years ago

7

Pyth, 14 13 bytes

1 byte thanks to Mnemonic.

V17j*da8NeMST

Try it online!

Leaky Nun

Posted 8 years ago

Reputation: 45 011

You can save a byte if you loop instead of mapping and joining. Try it here.

– None – 7 years ago

7

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).

Neil

Posted 8 years ago

Reputation: 95 035

7

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.

Probel

Posted 8 years ago

Reputation: 71

Welcome to the site! :) – James – 8 years ago

2This doesn't look quite right - the middle line shouldn't have any spaces at all. – Esolanging Fruit – 8 years ago

@Challenger5 you are right! fixed it by using paste0 instead of paste so had to add a byte:( – Probel – 8 years ago

1save 2 bytes using el: el(strsplit("1234567890","")) instead of strsplit("1234567890","")[[1]] – bouncyball – 8 years ago

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 – 7 years ago

@Giuseppe I think you can post this as a separate answer (and also golf it down to 51 bytes...) – JayCe – 7 years ago

@JayCe if you have to big of a golf, you should post it yourself! – Giuseppe – 7 years ago

@Giuseppe nah... you should post the 70 bytes answer which is the big improvement :) – JayCe – 7 years ago

7

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)

ShadowRanger

Posted 8 years ago

Reputation: 282

154 bytes: while i+9:print(*'1234567890',sep=' '*abs(i));i-=1 – flornquake – 8 years ago

6

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 !

Alex Ferretti

Posted 8 years ago

Reputation: 71

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 – 8 years ago

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 – 8 years ago

1Aww damn, i did something wrong while golfing the code ! I'll fix this ! – Alex Ferretti – 8 years ago

206 bytes: some preliminary golfing – Leaky Nun – 8 years ago

163 bytes: remove m also and merge into main – Leaky Nun – 8 years ago

171 bytes: combine two loops into one – Leaky Nun – 8 years ago

1148 bytes: one loop – Leaky Nun – 8 years ago

Nice one, @LeakyNun, that last one is one byte shorter than my Java answer (if used in the same format). Also, you can extract i%79 in a variable to gain a few bytes. – Olivier Grégoire – 8 years ago

1144 bytes – Leaky Nun – 8 years ago

1Nicely fixed after your first edit. :) And golfed a lot of course by LeakyNun afterwards. – Kevin Cruijssen – 8 years ago

not much but saves you 5 bytes for(int i=-8,j,k;i++<9;){String s="";for(j=1;j<10;){s+=j++;for(k=0;k++<(i>0?i:-i);)s+=" ";}System.out.println(s+0);} – user902383 – 8 years ago

6

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.

Zgarb

Posted 8 years ago

Reputation: 39 083

You could replace ṁs\:0ḣ9withuṁsḣ10` to generate the string "1234567890" with one fewer byte! – Sophia Lechner – 7 years ago

6

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)

Reversed Engineer

Posted 8 years ago

Reputation: 161

This is a nice answer! Welcome to the site :) – James – 8 years ago

Thanks. I see some of us have invented our own languages here :) – Reversed Engineer – 8 years ago

1A 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 – 8 years ago

Aha @ZLK - a few nice tricks - TOP 17, RANK OVER, and sys.objects - thank you! – Reversed Engineer – 8 years ago

6

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"))))

Carcigenicate

Posted 8 years ago

Reputation: 3 295

5

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

J42161217

Posted 8 years ago

Reputation: 15 931

Could you perhaps add a TryItOnline link?

– Kevin Cruijssen – 8 years ago

@KevinCruijssen Mathematica is not a free language, and Mathics doesn't seem to work.

– Leaky Nun – 8 years ago

@LeakyNun Ah ok, thanks. I see MartinEnder post TIO-links sometimes, but those were indeed Mathics links. – Kevin Cruijssen – 8 years ago

1@Kevin Cruijssen yes of course, I added link with instructions – J42161217 – 8 years ago

5

Jelly, 15 bytes

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

Try it online!

Leaky Nun

Posted 8 years ago

Reputation: 45 011

5

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!

tomsmeding

Posted 8 years ago

Reputation: 2 034

4

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.

Charlie

Posted 8 years ago

Reputation: 11 448

1When 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 – 8 years ago

@Neil :-D Well, it's 19 bytes now! – Charlie – 8 years ago

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 – 8 years ago

Oh, Range takes two arguments, silly me. – Neil – 8 years ago

@Neil I've never managed to write an answer in Charcoal using the map () operator... – Charlie – 8 years ago

My best Map attempt is still 20 bytes: F⁹⪫⁺E…¹χIκ⟦0¶⟧× ι‖B↑. (Edit: typo fix) – Neil – 8 years ago

1Turns out Map was a red herring, so I've now posted my 18-byte answer. – Neil – 8 years ago

4

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.
}/

Martin Ender

Posted 8 years ago

Reputation: 184 808

1Alternative solution (also 21 bytes): 9{S*A,(+\*}%_W%);\+N* – Esolanging Fruit – 8 years ago

4

PHP, 69 bytes

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

Try it online!

Jörg Hülsermann

Posted 8 years ago

Reputation: 13 026

4

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.

Neil

Posted 8 years ago

Reputation: 95 035

4

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

dzaima

Posted 8 years ago

Reputation: 19 048

4

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.

anatolyg

Posted 8 years ago

Reputation: 10 719

4

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.

AdmBorkBork

Posted 8 years ago

Reputation: 41 581

1Nice answer! Powershell suddenly feels more golfy :) – Mr. Xcoder – 7 years ago

3

perl 5: 43, 39, 31 bytes

Needs -E flag (which is free per our consensus).

map{$,=$"x abs;say 1..9,0}-8..8

Usage:

perl -E 'map{$,=$"x abs;say 1..9,0}-8..8'

Thanks to Dada

Toto

Posted 8 years ago

Reputation: 909

That's nice! -E flag is free per our consensus. Also, you probably wanted -8..8 instead of -8..9. And you can save a few bytes by playing with $, instead of $": map{$,=$"x abs;say 1..9,0}-8..8 (31 bytes).

– Dada – 8 years ago

@Dada:You're right, thank you, 4 bytes saved! – Toto – 8 years ago

You don't even need to declare @l: just use say 1..9,0 :) – Dada – 8 years ago

3

JavaScript, 67 Bytes

f=(i=8)=>i+9?[...`1234567890
`].join(''.padEnd(i<0?-i:i))+f(i-1):''

f=(i=8)=>i+9?[...`1234567890
`].join(''.padEnd(i<0?-i:i))+f(i-1):''

console.log(f())

Craig Ayre

Posted 8 years ago

Reputation: 217

3

LOGO, 58 57 bytes

for[j 8 -8][repeat 9[type # repeat abs :j[type "\ ]]pr 0]

This should be run on new versions of FMSLogo (link above), where # is repcount in repeat loops. That is a new feature in FMSLogo, which seems to be undocumented.

user202729

Posted 8 years ago

Reputation: 14 620

3

bash (and shell utils), 69 bytes

for i in `seq 9 -1 1;seq 2 9`;do seq -f%-$i.f 9|tr -d \\n;echo 0;done

Thomas

Posted 8 years ago

Reputation: 579

3

QBIC, 36 32 bytes

[-8,8|?[|?!b%z$';space$(abs(a));

Explanation

[-8,8|     FOR a = -8; a <= 8; a++      Sets upthe number of lines
?          Kick off each line with a \n
[|         FOR b = 1; b <= 10; b++      Loop over each digit: default behaviour for a no-arg FOR declaration
?          PRINT    
 !   $     a strng cast (suppresses QBasic's tendency to space out numbers)
  b%z      of b modulo 10 (z is 10 in QBIC)
 '         Then take the next bit of code as literal QBasic
 ;         Suppress newlines and tabs
 space$    Add x spaces to the output, where X is
 (abs(a))  The absolute line number
 ;         And suppress all newlines and tabs after this too
           A closing ` to this code literal is auto added by QBIC at EOF
           Two closing NEXT statements are also auto-added.

Sample output

Just because I really like the pattern. Note that this took some fiddling in QBasic because the usual terminal output is limited to 80 chars and it wraps.

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        

steenbergh

Posted 8 years ago

Reputation: 7 772

3

PHP, 76 Bytes

Update: Thanks to Soaku for the addition.

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

Try it online !

PHP, 88, 86, 80

Thanks to Caird for suggesting the golfing tips.

for($i=-9;$i++<8;)echo join(str_repeat(' ',abs($i)),[1,2,3,4,5,6,7,8,9,0])."\r";

You can try it here!

Boian Ivanov

Posted 8 years ago

Reputation: 41

Welcome to the site, and be sure to check these tips for golfing in PHP!

– caird coinheringaahing – 7 years ago

Sorry so late, but I golfed it down to 76 bytes

– RedClover – 7 years ago

str_pad("",abs($i)) is four bytes shorter than str_repeat(' ',abs($i)). – Titus – 6 years ago

3

Perl 6, 43 37 35 bytes

Originally, I came to:

map({say join " "x abs($_-8),1..9,0},0..16)

The say function in perl 6 automatically adds a newline, and it's map works a bit different from perl 5, requiring less parens due to it's more list based approach. Try it online

Fortunately, Jo King showed how to whittle it down further to 35 bytes:

{say join " "x.abs,1..9,0}for ^17-8

Try it online

whofferbert

Posted 8 years ago

Reputation: 186

0..16 => ^17 – Jo King – 7 years ago

Or you can change to a list and use the list repetition operator for 37 bytes

– Jo King – 7 years ago

Thanks, there's always more to learn :) Interestingly, the code that runs on TIO perl6 does not run with rakudo, unless I change ++to_++ – whofferbert – 7 years ago

Huh. Well, here's 35 byter that uses a for loop

– Jo King – 7 years ago

Too good! Thank you for sharing, I'm just starting to dabble with perl 6 – whofferbert – 7 years ago

1Ah, I found the problem with ++vs_++, perl6 version 2013.12 built on parrot 5.9.0 revision 0, vs perl6 version 2015.11 built on MoarVM version 2015.11, where it behaves as on TIO. – whofferbert – 7 years ago

3

R, 51 bytes

for(i in abs(-8:8))cat(1:9,0,"
",sep=strrep(" ",i))

Try it online!

Managed to find some more bytes thanks to JayCe's suggestion in the comments.

Giuseppe

Posted 8 years ago

Reputation: 21 077

3

C, 135 128 characters

-7 characters thanks to kevin cruijssen

#define p printf
i=1,j,h=9,k;main(){for(;++i<22;i<10?h--:h++,p("\n"))for(j=0;++j<11;)for(p(j==10?"0":"%d",j),k=1;k++<h;)p(" ");}

Try it online!


Fun bonus:

On my first compile I got the logic backwards and ended up with the output in reverse

i=1,j,k,h=9;main(){for(;i++<20;){for(j=0;j++<10;){printf(j==10?"0":"%d",j);for(k=1;k++<10-h;){printf(" ");}}i<11?h--:h++;printf("\n");}}

Edit: removed missed whitespace

J.Barber

Posted 8 years ago

Reputation: 31

1Welcome to PPCG! Great first answer. – mbomb007 – 7 years ago

2

Welcome to PPCG! This is indeed a great first answer, +1 from me. 7 bytes can be saved by removing all the brackets and putting everything inside the loop declarations: i=1,j,h=9,k;main(){for(;++i<22;i<10?h--:h++,p("\n"))for(j=0;++j<11;)for(p(j==10?"0":"%d",j),k=1;k++<h;)p(" ");} 128 bytes Enjoy your stay!

– Kevin Cruijssen – 7 years ago

184 bytes by utilizing a single loop, print, and iteration variable, and switching to f() instead of main. – None – 6 years ago

169 bytes building on @Rogem – ceilingcat – 6 years ago

3

MathGolf, 11 bytes

9╤{± *♂r╫up

Try it online!

Explanation

9             push 9
 ╤            range(-n, n+1)
  {           start block or arbitrary length
   ±          absolute value
              space character
     *        pop a, b : push(a*b)
      ♂       push 10
       r      range(0, n)
        ╫     left-rotate bits in int, list/str
         u    join with separator
          p   print with newline

maxb

Posted 8 years ago

Reputation: 5 754

2

V, 18 bytes

¬19á08ñÄÓä/& 
YGpH

Try it online!

James

Posted 8 years ago

Reputation: 54 537

2

Swift 3.1, 186 182 bytes

func f(_ n:Int=0,_ u:Bool=true){let p={if n<8{f(n+1,u)}};let q={print((1...9).map{String($0)+String(repeating:" ",count:n)}.joined()+"0")};if u{q();p()}else{p();q()}};f(1,false);f()

Explanation

func f(_ n:Int=0,_ u:Bool=true){          function (recursive) that does
                                          all the heavy-lifting =) 
                                          n - number of spaces,
                                          u - go "up" or "down
let p={if n<8 {f(n+1,u)}}                 closure that runs f on higher step if can
let q={                                   closure which does the printing
print((1...9).map{                        print closed range of number mapped...
String($0)+String(repeating:" ",count:n)  ...making String from each number in range
                                          and appending n spaces to it
.joined()+"0")                            join all "1    "-like strings and append "0"
if u{q();p()}                             if go "up" - then call f before printing
else{p();q()}                             if go "down - the other way
f(1,false);f()                            run "up" then "down"

Removed some silly spaces. Thanx to Kevin Cruijssen

Sergii Martynenko Jr

Posted 8 years ago

Reputation: 213

I feel there is a room for an improvement, though – Sergii Martynenko Jr – 8 years ago

1I've never programmed in Swift, so perhaps I'm saying something stupid here, but is it possible to remove some of those spaces? Like the one here: n<8 {f(n+1; here: count:n) }; here: p()} else{p(); and/or here q()}}; f(1,false? – Kevin Cruijssen – 8 years ago

171 bytes – Tamás Sengel – 7 years ago

2

Common Lisp, 85 bytes

(dotimes(i 17)(format t(format()"~~{~~,,~aa~~}
"(abs(- i 8)))'(1 2 3 4 5 6 7 8 9 0)))

Try it online!

format “magic” of Common Lisp:

(dotimes (i 17)                     ; for i from 0 to 16
  (format t                         ; print with a format string generated from the next call
          (format ()                ; with nil as parameter generates a string instead of printing
                  "~~{~~,,~aa~~}
"                                   ; generate the format string "~{~,,na~}~%" with n given
                  (abs(- i 8)))     ;     by the value of abs(i-8) (number of spaces)
          '(1 2 3 4 5 6 7 8 9 0)))  ; the data to be printed for each line

Renzo

Posted 8 years ago

Reputation: 2 260

2

PHP, 71 bytes

while($y<17)echo chunk_split(1234567890,1,str_pad("",abs($y++-8))),"
";

Run with -nr or test it online.

Titus

Posted 8 years ago

Reputation: 13 814

Inspired by your solution, I got my solution down to 66: while($i<17)echo implode(str_pad('',abs($i++-8)),range(1,9))."\n"; – jstnthms – 8 years ago

Oops! Looks like I made an incorrect assumption about the output. I thought it was 123456789 – jstnthms – 8 years ago

2

MATL, 21 bytes

-9Zv"l4Y29YS10:q@*Q(c

Try it online!

Explanation:

-9Zv                  % Generates [9 ... 2, 1, 2, ... 9]. 
    "                 % Iterate over this vector.
                   (  % Assignment indexing. Places elements B at positions C in existing vector A.
     l                %   A: Dummy vector with numeric [1] in it. Is always overwritten by char '1'.
      4Y29YS          %   B:  '0':'9', circularly shifted 9 positions to get '1':'9','0'
            10:q@*Q   %   C: Equally spaced indexing vector, spacing based on loop variable @.
                    c % Convert to char, because A was numeric.

Golfing done:

-9Zv     -->  built-in, instead of -8:8|Q or even 8:PQ9:h| 
10:q@*Q  -->  2 bytes shorter than l@@10*3$:
l ... c  -->  1 byte shorter than 'x' (char dummy vector A)

I have attempted to get rid of the 9YS by doing the circular shift in the indexing, but this increased the byte count (10t:qwX\q@*Q instead of 9YS10:q@*Q). However, some interesting patterns were obtained in the process: Try it online!, Try it online!.

Sanchises

Posted 8 years ago

Reputation: 8 530

2

Bubblegum, 140 bytes

:P

0000000: ad92 510e c230 0c43 ff39 0547 802c f3bc  ..Q..0.C.9.G.,..
0000010: fb5f 8c10 c5d1 5a09 10b0 7d59 b1fd b4b6  ._....Z...}Y....
0000020: b95f eb33 8945 c225 5609 486c 1294 d825  ._.3.E.%V.Hl...%
0000030: 6e17 216d 02fa 84c3 04a3 5033 c906 8e0f  n.!m......P3....
0000040: 140c 0c8a 3000 ec50 f743 1987 2abb d83d  ....0..P.C..*..=
0000050: eb96 7707 dda0 f215 b70a 7b45 5141 66ac  ..w.......{EQAf.
0000060: 5296 19cf 04d2 67ba 4fd3 c2f2 3010 63c6  R.....g.O...0.c.
0000070: 3066 b6f8 8a8d fb0b fb0d eff3 2f7d 77ce  0f........../}w.
0000080: 1faf f3df 773c 7fa5 cedf f707            ....w<......

Try it online!

Do I get brownie points for having ._. two times in the dump?

totallyhuman

Posted 8 years ago

Reputation: 15 378

131 bytes – ovs – 8 years ago

1How did I get out-golfed in Bubblegum? o0 What compression method did you use? – totallyhuman – 8 years ago

I used zopfli to generate a DEFLATE stream. I got to 130 bytes with 222 iterations.

– ovs – 8 years ago

For some reason the byte count went up with more then 314 iterations. zopfli link

– ovs – 8 years ago

2

Perl 5, 31 bytes

$,=$"x abs$_,say 1..9,0for-8..8

Try it online!

Xcali

Posted 8 years ago

Reputation: 7 671

1

Cheddar, 42 bytes

-8|>8=>n->print(1|>9+[0]).join(abs(n)*' ')

Try it online!

Leaky Nun

Posted 8 years ago

Reputation: 45 011

1

Stacked, 33 bytes

9:>' '*[9~>\#`]"!:8~>#rev\,$out"!

Try it online!

Explanation

9:>' '*[9~>\#`]"!:8~>#rev\,$out"!
9:>                                 range from 0 to 9 (right-exclusive)
   ' '*                             vectorized repetition of the space
       [      ]"!                   on each repetition:
        9~>                           generate a range from 1 to 9
           \#`                        and join it by that repetition
                 :8~>#              copy all but the first element
                      rev           reverse it
                         \,         swap then concatenate
                           $out"!   output each

Conor O'Brien

Posted 8 years ago

Reputation: 36 228

1

///, 251 bytes

/B/' //A/!!//@/" //?/\/\///>/  ?=/0
1?</ 2 3 4 5 6 7 8 9 ?;/!2!3!4!5!6!7!8!9!?:/'2'3'4'5'6'7'8'9'?-/="2"3"4"5"6"7"8"9"=?,/@2@3@4@5@6@7@8@9@?'/!"?&/=>2>3>4>5>6>7>8>9>=?%/=A2A3A4A5A6A7A8A9A=?#/1B2B3B4B5B6B7B8B9B0?"/! ?!/> /#
1:%,-;&<=23456789=<&;-,%:0
#

Try it online! Or here, interactively!

Considerably long, but /// has no real way of modifying data elegantly.

Conor O'Brien

Posted 8 years ago

Reputation: 36 228

1

Delphi / Pascal 137 Bytes*

program x;{$APPTYPE CONSOLE}var i,j: Integer;begin for i:=-8 to 8do begin write(#10,1); for j:=2 to 10do Write(j mod 10:Abs(i)+1);end;end.

*The {$APPTYPE CONSOLE} is a compiler directive that can be removed for pure Pascal. or if compiled with the Delphi command line compiler using the -cc switch to give 119 bytes. Without it you get a runtime error as it tries to print to a non existent console.

Gerry Coll

Posted 8 years ago

Reputation: 111

1

q/kdb+, 37 bytes

Solution:

-1" "{raze(1_11#.Q.n),\:y#x}'8-(!)17;

Example:

q)-1" "{raze(1_11#.Q.n),\:y#x}'8-(!)17;
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        

Explanation:

q is evaluation right-to-left. Here we are taking the range of -8..0..8, and joining that many spaces with the list "1234567890". We then use -1 to print out to stdout (rather than returning the list of strings).

-1 " "{raze (1_11#.Q.n),\:y#x}'8 - til 17; / ungolfed solution
                                   til 17  / range of 0..16
                               8 -         / take 8 from each value, gives -8..0..8
   " "{                      }'            / each left/right, passes in " " and then -8, -7, etc..
                          y#x              / take from list " ", note: negatives take from 'back' of list
                       ,\:                 / \: is 'each left', , means concatenate with, so take each left and concatenate with the right
            (1_11#.Q.n)                    / 'the left'. .Q.n is range 0-9 as a string, take 11 to get 0123..90, then drop the first
       raze                                / reduce down output list into a single string
-1                                       ; / print to stdout and swallow return value (-1)

Notes:

Doing (1_11#.Q.n) is 1 byte shorter than the much more straightforward "1234567890"... but as .Q.n returns "0123456789" some manipulation is required.

streetster

Posted 8 years ago

Reputation: 3 635

1

Ruby 2.4, 40 bytes

-8.upto 8{|i|puts [*1..9,0]*(' '*i.abs)}

Ruby (lower than 2.4), 41 bytes

-8.upto(8){|i|puts [*1..9,0]*(' '*i.abs)}

Try it online!

G B

Posted 8 years ago

Reputation: 11 099

1

[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);
    }
}

Java Gonzar

Posted 8 years ago

Reputation: 173

1Declare 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. – TheLethalCoder – 8 years ago

Also it might be cheaper, especially when compiling to a lambda, to return the results as a string. – TheLethalCoder – 8 years ago

2

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.

– Kevin Cruijssen – 8 years ago

1

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" : ""));
    }
}

Matthieu Charbonnier

Posted 8 years ago

Reputation: 111

1

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.

– Notts90 supports Monica – 8 years ago

1

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. :)

– Kevin Cruijssen – 8 years ago

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.

– Kevin Cruijssen – 8 years ago

Thanks for the comments Notts90 and Kevin, I will look at your code this evening :) – Matthieu Charbonnier – 8 years ago

1

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

sergiol

Posted 8 years ago

Reputation: 3 055

Different approach with same size http://rextester.com/RGO50353

– sergiol – 8 years ago

1

/// (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):

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

Cedric Reichenbach

Posted 8 years ago

Reputation: 448

/./ //-/ //_/ / can be /_/..//-/. //./ /. Imagine the spaces being correct because Markdown doesn't like multiple spaces in inline code blocks >:( – CalculatorFeline – 8 years ago

@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). – Cedric Reichenbach – 8 years ago

1

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

Julian Zucker

Posted 8 years ago

Reputation: 129

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. :) – Kevin Cruijssen – 8 years ago

1

Cubically, 2622 bytes

U3D1R3L1F3B1U1D3+3111111@6-2111@66666666+21111@6-21111@66666666+211111@6-211111@66666666+0@6-0@66666666+01@6-01@66666666+011@6-011@66666666+0111@6-0111@66666666+4@6-4@66666666+41@6-41@66666666+211@6-511111@6+5111111@6-2111@6666666+21111@6-21111@6666666+211111@6-211111@6666666+0@6-0@6666666+01@6-01@6666666+011@6-011@6666666+0111@6-0111@6666666+4@6-4@6666666+41@6-41@6666666+211@6-511111@6+5111111@6-2111@666666+21111@6-21111@666666+211111@6-211111@666666+0@6-0@666666+01@6-01@666666+011@6-011@666666+0111@6-0111@666666+4@6-4@666666+41@6-41@666666+211@6-511111@6+5111111@6-2111@66666+21111@6-21111@66666+211111@6-211111@66666+0@6-0@66666+01@6-01@66666+011@6-011@66666+0111@6-0111@66666+4@6-4@66666+41@6-41@66666+211@6-511111@6+5111111@6-2111@6666+21111@6-21111@6666+211111@6-211111@6666+0@6-0@6666+01@6-01@6666+011@6-011@6666+0111@6-0111@6666+4@6-4@6666+41@6-41@6666+211@6-511111@6+5111111@6-2111@666+21111@6-21111@666+211111@6-211111@666+0@6-0@666+01@6-01@666+011@6-011@666+0111@6-0111@666+4@6-4@666+41@6-41@666+211@6-511111@6+5111111@6-2111@66+21111@6-21111@66+211111@6-211111@66+0@6-0@66+01@6-01@66+011@6-011@66+0111@6-0111@66+4@6-4@66+41@6-41@66+211@6-511111@6+5111111@6-2111@6+21111@6-21111@6+211111@6-211111@6+0@6-0@6+01@6-01@6+011@6-011@6+0111@6-0111@6+4@6-4@6+41@6-41@6+211@6-511111@6+5111111@6+1@6+1@6+1@6+1@6+1@6+1@6+1@6+1@6-111111111@6-511111@6+5111111@6-2111@6+21111@6-21111@6+211111@6-211111@6+0@6-0@6+01@6-01@6+011@6-011@6+0111@6-0111@6+4@6-4@6+41@6-41@6+211@6-511111@6+5111111@6-2111@66+21111@6-21111@66+211111@6-211111@66+0@6-0@66+01@6-01@66+011@6-011@66+0111@6-0111@66+4@6-4@66+41@6-41@66+211@6-511111@6+5111111@6-2111@666+21111@6-21111@666+211111@6-211111@666+0@6-0@666+01@6-01@666+011@6-011@666+0111@6-0111@666+4@6-4@666+41@6-41@666+211@6-511111@6+5111111@6-2111@6666+21111@6-21111@6666+211111@6-211111@6666+0@6-0@6666+01@6-01@6666+011@6-011@6666+0111@6-0111@6666+4@6-4@6666+41@6-41@6666+211@6-511111@6+5111111@6-2111@66666+21111@6-21111@66666+211111@6-211111@66666+0@6-0@66666+01@6-01@66666+011@6-011@66666+0111@6-0111@66666+4@6-4@66666+41@6-41@66666+211@6-511111@6+5111111@6-2111@666666+21111@6-21111@666666+211111@6-211111@666666+0@6-0@666666+01@6-01@666666+011@6-011@666666+0111@6-0111@666666+4@6-4@666666+41@6-41@666666+211@6-511111@6+5111111@6-2111@6666666+21111@6-21111@6666666+211111@6-211111@6666666+0@6-0@6666666+01@6-01@6666666+011@6-011@6666666+0111@6-0111@6666666+4@6-4@6666666+41@6-41@6666666+211@6-511111@6+5111111@6-2111@66666666+21111@6-21111@66666666+211111@6-211111@66666666+0@6-0@66666666+01@6-01@66666666+011@6-011@66666666+0111@6-0111@66666666+4@6-4@66666666+41@6-41@66666666+211@6

Pretty simple, turns the cube to get it into this:

   242
   202
   242
000131555313
010121535343
000131555313
   424
   454
   424

Now the LEFT face sums up to 1. So we use the other faces to get as close to the desired ASCII values as possible, then just increment/decrement by 1.

This also works:

Cubically, 2938 bytes

:4/1+5@6/1+3@66666666+2@6-2@66666666:5+1/1+5@6/1+3@66666666:5+2/1+5@6/1+3@66666666:5+3/1+5@6/1+3@66666666:5+1@6:5/1+3@66666666:1/1+51@6:5/1+3@66666666:2/1+51@6:5/1+3@66666666/1+51@6:5/1+3@66666666/1+5@6:1/1+1@6:4/1+5@6/1+3@6666666+2@6-2@6666666:5+1/1+5@6/1+3@6666666:5+2/1+5@6/1+3@6666666:5+3/1+5@6/1+3@6666666:5+1@6:5/1+3@6666666:1/1+51@6:5/1+3@6666666:2/1+51@6:5/1+3@6666666/1+51@6:5/1+3@6666666/1+5@6:1/1+1@6:4/1+5@6/1+3@666666+2@6-2@666666:5+1/1+5@6/1+3@666666:5+2/1+5@6/1+3@666666:5+3/1+5@6/1+3@666666:5+1@6:5/1+3@666666:1/1+51@6:5/1+3@666666:2/1+51@6:5/1+3@666666/1+51@6:5/1+3@666666/1+5@6:1/1+1@6:4/1+5@6/1+3@66666+2@6-2@66666:5+1/1+5@6/1+3@66666:5+2/1+5@6/1+3@66666:5+3/1+5@6/1+3@66666:5+1@6:5/1+3@66666:1/1+51@6:5/1+3@66666:2/1+51@6:5/1+3@66666/1+51@6:5/1+3@66666/1+5@6:1/1+1@6:4/1+5@6/1+3@6666+2@6-2@6666:5+1/1+5@6/1+3@6666:5+2/1+5@6/1+3@6666:5+3/1+5@6/1+3@6666:5+1@6:5/1+3@6666:1/1+51@6:5/1+3@6666:2/1+51@6:5/1+3@6666/1+51@6:5/1+3@6666/1+5@6:1/1+1@6:4/1+5@6/1+3@666+2@6-2@666:5+1/1+5@6/1+3@666:5+2/1+5@6/1+3@666:5+3/1+5@6/1+3@666:5+1@6:5/1+3@666:1/1+51@6:5/1+3@666:2/1+51@6:5/1+3@666/1+51@6:5/1+3@666/1+5@6:1/1+1@6:4/1+5@6/1+3@66+2@6-2@66:5+1/1+5@6/1+3@66:5+2/1+5@6/1+3@66:5+3/1+5@6/1+3@66:5+1@6:5/1+3@66:1/1+51@6:5/1+3@66:2/1+51@6:5/1+3@66/1+51@6:5/1+3@66/1+5@6:1/1+1@6:4/1+5@6/1+3@6+2@6-2@6:5+1/1+5@6/1+3@6:5+2/1+5@6/1+3@6:5+3/1+5@6/1+3@6:5+1@6:5/1+3@6:1/1+51@6:5/1+3@6:2/1+51@6:5/1+3@6/1+51@6:5/1+3@6/1+5@6:1/1+1@6:4/1+5@6/1+5@6:5+1/1+5@6:5+2/1+5@6:5+3/1+5@6:5+1@6:1/1+51@6:2/1+51@6:3/1+51@6-1@6:1/1+1@6:4/1+5@6/1+3@6+2@6-2@6:5+1/1+5@6/1+3@6:5+2/1+5@6/1+3@6:5+3/1+5@6/1+3@6:5+1@6:5/1+3@6:1/1+51@6:5/1+3@6:2/1+51@6:5/1+3@6/1+51@6:5/1+3@6/1+5@6:1/1+1@6:4/1+5@6/1+3@66+2@6-2@66:5+1/1+5@6/1+3@66:5+2/1+5@6/1+3@66:5+3/1+5@6/1+3@66:5+1@6:5/1+3@66:1/1+51@6:5/1+3@66:2/1+51@6:5/1+3@66/1+51@6:5/1+3@66/1+5@6:1/1+1@6:4/1+5@6/1+3@666+2@6-2@666:5+1/1+5@6/1+3@666:5+2/1+5@6/1+3@666:5+3/1+5@6/1+3@666:5+1@6:5/1+3@666:1/1+51@6:5/1+3@666:2/1+51@6:5/1+3@666/1+51@6:5/1+3@666/1+5@6:1/1+1@6:4/1+5@6/1+3@6666+2@6-2@6666:5+1/1+5@6/1+3@6666:5+2/1+5@6/1+3@6666:5+3/1+5@6/1+3@6666:5+1@6:5/1+3@6666:1/1+51@6:5/1+3@6666:2/1+51@6:5/1+3@6666/1+51@6:5/1+3@6666/1+5@6:1/1+1@6:4/1+5@6/1+3@66666+2@6-2@66666:5+1/1+5@6/1+3@66666:5+2/1+5@6/1+3@66666:5+3/1+5@6/1+3@66666:5+1@6:5/1+3@66666:1/1+51@6:5/1+3@66666:2/1+51@6:5/1+3@66666/1+51@6:5/1+3@66666/1+5@6:1/1+1@6:4/1+5@6/1+3@666666+2@6-2@666666:5+1/1+5@6/1+3@666666:5+2/1+5@6/1+3@666666:5+3/1+5@6/1+3@666666:5+1@6:5/1+3@666666:1/1+51@6:5/1+3@666666:2/1+51@6:5/1+3@666666/1+51@6:5/1+3@666666/1+5@6:1/1+1@6:4/1+5@6/1+3@6666666+2@6-2@6666666:5+1/1+5@6/1+3@6666666:5+2/1+5@6/1+3@6666666:5+3/1+5@6/1+3@6666666:5+1@6:5/1+3@6666666:1/1+51@6:5/1+3@6666666:2/1+51@6:5/1+3@6666666/1+51@6:5/1+3@6666666/1+5@6:1/1+1@6:4/1+5@6/1+3@66666666+2@6-2@66666666:5+1/1+5@6/1+3@66666666:5+2/1+5@6/1+3@66666666:5+3/1+5@6/1+3@66666666:5+1@6:5/1+3@66666666:1/1+51@6:5/1+3@66666666:2/1+51@6:5/1+3@66666666/1+51@6:5/1+3@66666666/1+5@6

Uses the existing cube and division to get the required ASCII values.

Found using these answers.

MD XF

Posted 8 years ago

Reputation: 11 605

1

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

dragonite44

Posted 8 years ago

Reputation: 91

Hi there. Would you mind adding a TIO-link with test code? Lua should be available on TIO as well.

– Kevin Cruijssen – 7 years ago

You can save 5 bytes by using (" "):rep. – user202729 – 7 years ago

You can also get it down to 82 bytes with pattern. Hint: %1. – user202729 – 7 years ago

1

J, 25 bytes

'1',.(1+|i:8)":"{0,~2+i.8

Try it online!

FrownyFrog

Posted 8 years ago

Reputation: 3 112

1

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.

X1M4L

Posted 8 years ago

Reputation: 1 586

1

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

hakr14

Posted 8 years ago

Reputation: 1 295

1

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

Taylor Scott

Posted 8 years ago

Reputation: 6 709

1

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        

Delioth

Posted 8 years ago

Reputation: 221

1

Pip -l, 18 bytes

(\,t)%tJsXAB_M-8,9

The -l flag outputs the list of results one per line. Try it online!

DLosc

Posted 8 years ago

Reputation: 21 213

1

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)

DLosc

Posted 8 years ago

Reputation: 21 213

Hmm, never seen or heard about the programming language SIsi. Weird how those leading line numbering are mandatory. Nice answer though! – Kevin Cruijssen – 6 years ago

1

@KevinCruijssen Not surprised that you haven't heard of it--it's a toy language I wrote for an old popularity contest here. :)

– DLosc – 6 years ago

1

///, 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!

Erik the Outgolfer

Posted 8 years ago

Reputation: 38 134

1

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

FlipTack

Posted 8 years ago

Reputation: 13 242

Would you mind adding an explanation? – Kevin Cruijssen – 6 years ago

1

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!

david

Posted 8 years ago

Reputation: 479

0

Python 2, 72 bytes

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

Try it online!

ovs

Posted 8 years ago

Reputation: 21 408

0

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

bioweasel

Posted 8 years ago

Reputation: 307

0

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

Евгений Новиков

Posted 8 years ago

Reputation: 987

0

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`

Taylor Scott

Posted 8 years ago

Reputation: 6 709

0

JavaScript, 71 bytes

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

MattH

Posted 8 years ago

Reputation: 171