77
\$\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\$
  • \$\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\$ – Kevin Cruijssen 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\$ – Kevin Cruijssen Jul 3 '17 at 11:23
  • 8
    \$\begingroup\$ Ha, that's awesome. I was wondering why that answer suddenly got so much attention. Thanks! \$\endgroup\$ – Carcigenicate Jul 3 '17 at 19:41

75 Answers 75

3
\$\begingroup\$

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

\$\endgroup\$
3
\$\begingroup\$

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.

\$\endgroup\$
3
\$\begingroup\$

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

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

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

\$\endgroup\$
  • \$\begingroup\$ 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). \$\endgroup\$ – Dada Jul 3 '17 at 9:11
  • \$\begingroup\$ @Dada:You're right, thank you, 4 bytes saved! \$\endgroup\$ – Toto Jul 3 '17 at 9:16
  • \$\begingroup\$ You don't even need to declare @l: just use say 1..9,0 :) \$\endgroup\$ – Dada Jul 3 '17 at 9:17
3
\$\begingroup\$

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!

\$\endgroup\$
  • \$\begingroup\$ Welcome to the site, and be sure to check these tips for golfing in PHP! \$\endgroup\$ – caird coinheringaahing Apr 5 '18 at 10:16
  • \$\begingroup\$ Sorry so late, but I golfed it down to 76 bytes \$\endgroup\$ – RedClover Jun 15 '18 at 19:37
  • \$\begingroup\$ str_pad("",abs($i)) is four bytes shorter than str_repeat(' ',abs($i)). \$\endgroup\$ – Titus Oct 28 '18 at 9:56
3
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ 0..16 => ^17 \$\endgroup\$ – Jo King Jul 26 '18 at 1:08
  • \$\begingroup\$ Or you can change to a list and use the list repetition operator for 37 bytes \$\endgroup\$ – Jo King Jul 26 '18 at 1:11
  • \$\begingroup\$ Thanks, there's always more to learn :) Interestingly, the code that runs on TIO perl6 does not run with rakudo, unless I change $++ to $_++ \$\endgroup\$ – whofferbert Jul 26 '18 at 1:20
  • \$\begingroup\$ Huh. Well, here's 35 byter that uses a for loop \$\endgroup\$ – Jo King Jul 26 '18 at 1:24
  • 1
    \$\begingroup\$ Ah, 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. \$\endgroup\$ – whofferbert Jul 26 '18 at 1:37
3
\$\begingroup\$

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.

\$\endgroup\$
3
\$\begingroup\$

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

\$\endgroup\$
3
\$\begingroup\$

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

V, 18 bytes

¬19á08ñÄÓä/& 
YGpH

Try it online!

\$\endgroup\$
2
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ I feel there is a room for an improvement, though \$\endgroup\$ – Sergii Martynenko Jr Jul 4 '17 at 13:50
  • 1
    \$\begingroup\$ I'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? \$\endgroup\$ – Kevin Cruijssen Jul 4 '17 at 14:24
  • \$\begingroup\$ 171 bytes \$\endgroup\$ – Tamás Sengel Apr 5 '18 at 16:52
2
\$\begingroup\$

PHP, 71 bytes

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

Run with -nr or test it online.

\$\endgroup\$
  • \$\begingroup\$ 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"; \$\endgroup\$ – jstnthms Jul 20 '17 at 17:48
  • \$\begingroup\$ Oops! Looks like I made an incorrect assumption about the output. I thought it was 123456789 \$\endgroup\$ – jstnthms Jul 20 '17 at 17:51
2
\$\begingroup\$

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

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?

\$\endgroup\$
  • \$\begingroup\$ 131 bytes \$\endgroup\$ – ovs Jul 20 '17 at 18:05
  • 1
    \$\begingroup\$ How did I get out-golfed in Bubblegum? o0 What compression method did you use? \$\endgroup\$ – totallyhuman Jul 20 '17 at 18:07
  • \$\begingroup\$ I used zopfli to generate a DEFLATE stream. I got to 130 bytes with 222 iterations. \$\endgroup\$ – ovs Jul 20 '17 at 18:09
  • \$\begingroup\$ For some reason the byte count went up with more then 314 iterations. zopfli link \$\endgroup\$ – ovs Jul 20 '17 at 18:10
2
\$\begingroup\$

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

\$\endgroup\$
2
\$\begingroup\$

Perl 5, 31 bytes

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

Try it online!

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

Cheddar, 42 bytes

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

Try it online!

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

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

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

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

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.

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

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.

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

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!

\$\endgroup\$
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\$
  • 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\$ – TheLethalCoder 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\$ – TheLethalCoder 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\$ – Kevin Cruijssen 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\$
  • 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\$ – Notts90 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\$ – Kevin Cruijssen 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\$ – Kevin Cruijssen Jul 6 '17 at 11:47
  • \$\begingroup\$ Thanks for the comments Notts90 and Kevin, I will look at your code this evening :) \$\endgroup\$ – Matthieu Charbonnier 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
\$\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\$
  • \$\begingroup\$ /./ //-/ //_/ / can be /_/..//-/. //./ /. Imagine the spaces being correct because Markdown doesn't like multiple spaces in inline code blocks >:( \$\endgroup\$ – CalculatorFeline 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\$ – Cedric Reichenbach Jul 10 '17 at 7:07
1
\$\begingroup\$

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.

\$\endgroup\$
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\$
  • \$\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\$ – Kevin Cruijssen Jul 8 '17 at 7:44
1
\$\begingroup\$

J, 25 bytes

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

Try it online!

\$\endgroup\$

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.