93
\$\begingroup\$

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

Print this exact text:

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

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

Challenge rules:

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

General rules:

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

86 Answers 86

4
\$\begingroup\$

PHP, 69 bytes

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

Try it online!

\$\endgroup\$
4
\$\begingroup\$

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.

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

jq -nr, 50 46 45 bytes

[range(9)+1,0|@sh]|join(range(17)-8|" "*fabs) 

Try it on jqplay!

[range(9)+1,0|@sh] generates the array ["1", "2", ..., "9", "0"]. This list is then joined by each of the results from:

range(17)-8: -8, -7, ..., 7, 8
" "*fabs a string of absolute value spaces

\$\endgroup\$
2
  • \$\begingroup\$ Sorry... \$\endgroup\$
    – emanresu A
    Sep 4 at 11:00
  • \$\begingroup\$ @emanresuA Yeah I've seen that before writing the answer. I will let you know when I posted an answer to a challenge you haven't \$\endgroup\$
    – ovs
    Sep 4 at 11:43
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\$

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\$
3
  • \$\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\$

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\$
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\$
3
  • \$\begingroup\$ Welcome to the site, and be sure to check these tips for golfing in PHP! \$\endgroup\$ 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\$
6
  • \$\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\$ 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\$ 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\$
4
3
\$\begingroup\$

J, 25 22 bytes

(1 j.|i:8)#"{1|.Num_j_

Try it online!

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

Perl 5, 31 29 bytes

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

Try it online!

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

Vyxal j, 15 bytes

8N8ṡȧƛð$ẋ9ʀ1Ǔ$j

Try it Online!

-1 byte thanks to Aaron Miller

8N                 -8
  8                 8
   ṡ                inclusive range; -8, -7, ..., 7, 8
    ȧ               abs; 8, 7, ..., 1, 0, 1, ..., 7, 8
     ƛ---------     for each
      ð$            push space and swap it underneath
        ẋ           repeat the space N times
         9ʀ         [0, 1, ..., 8, 9]
           1Ǔ       rotate left once
             $j     swap and join

j (flag)            join on newlines
\$\endgroup\$
3
3
\$\begingroup\$

Dash*, 69 bytes

seq -- -8 8|xargs -I: sh -c 'seq -s"`printf "%:s_"`" 10'|sed s/_1*//g

Hopefully this iteration is fairly self explanatory -- pretty much a straight swap of for to xargs.

Try it online!

Dash*, 87, 86, 73 bytes

for p in `seq -- -8 8`;do seq -s"`printf "%${p}s_"`" 10;done|sed s/_1*//g

Try it online!

Explanation (for method)

for p in `seq -- -8 8`

Produce -8 to 8, used to create separator in next seq. NB BusyBox’s* seq barfs on the -8 without the -- but TIO’s Dash env does not.

;do seq -s"`printf "%${p}s_"`" 10

Print 1-10, separated with p × spaces, with an extra _ appended (because seq won't accept an empty separator).

;done|sed s/_1*//g

Remove the _ as well as the 1 from trailing 10.

EDIT: removed a silly space (thanks Kevin Cruijssen)

EDIT: saved many bytes because negative padding printf doesn't matter

EDIT: scraped off another few bytes by ditching the for in favour of xargs.

*Actually this is aimed at Busybox 1.31.1 ash, sed, seq and printf, but TIO didn't have that environment. NB available seq options are limited to -w and -s.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Welcome to Code Golf, and nice first answer! Be sure to check out our Tips for golfing in Bash page for ways you can golf your program (they're likely to be applicable to Dash as well) \$\endgroup\$
    – pxeger
    Sep 7 at 8:46
  • 1
    \$\begingroup\$ Nice first answer, welcome to CGCC! I think you can remove the space between 10 ;? \$\endgroup\$ Sep 7 at 9:36
  • \$\begingroup\$ Not sure how that sneaked in there, thanks @KevinCruijssen \$\endgroup\$
    – bxm
    Sep 7 at 11:40
2
\$\begingroup\$

V, 18 bytes

¬19á08ñÄÓä/& 
YGpH

Try it online!

\$\endgroup\$
2
\$\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\$
2
\$\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\$
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\$
3
  • \$\begingroup\$ I feel there is a room for an improvement, though \$\endgroup\$ 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\$ Jul 4 '17 at 14:24
  • \$\begingroup\$ 171 bytes \$\endgroup\$ 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\$
2
  • \$\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\$

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\$
4
  • \$\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\$ 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\$

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

Zsh, 61 57 49 bytes

-4, -8 thanks to @pxeger

for 1 ({9..1} {2..9}){printf %-$1s {1..9} 0;echo}

Try it online! 61 bytes 57 bytes

Similar to the Spaceship Maw! solution.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ 57: Try it online! \$\endgroup\$
    – pxeger
    Jan 25 at 19:26
  • \$\begingroup\$ wow. i didn't know you could set $1 and $2 and use $@ like that. \$\endgroup\$
    – roblogic
    Mar 27 at 14:20
  • 1
    \$\begingroup\$ 49: Try it online! \$\endgroup\$
    – pxeger
    Mar 27 at 15:27
2
\$\begingroup\$

Deadfish~, 2959 bytes

{iiiii}dc{dd}iiicccccccc{ii}ddc{dd}iicccccccc{ii}dc{dd}icccccccc{ii}c{dd}cccccccc{ii}ic{dd}dcccccccc{ii}iic{dd}ddcccccccc{ii}iiic{dd}dddcccccccc{ii}iiiic{dd}ddddcccccccc{ii}iiiiic{dd}dddddcccccccc{i}iiiiiic{dddd}iic{iiii}dc{dd}iiiccccccc{ii}ddc{dd}iiccccccc{ii}dc{dd}iccccccc{ii}c{dd}ccccccc{ii}ic{dd}dccccccc{ii}iic{dd}ddccccccc{ii}iiic{dd}dddccccccc{ii}iiiic{dd}ddddccccccc{ii}iiiiic{dd}dddddccccccc{i}iiiiiic{dddd}iic{iiii}dc{dd}iiicccccc{ii}ddc{dd}iicccccc{ii}dc{dd}icccccc{ii}c{dd}cccccc{ii}ic{dd}dcccccc{ii}iic{dd}ddcccccc{ii}iiic{dd}dddcccccc{ii}iiiic{dd}ddddcccccc{ii}iiiiic{dd}dddddcccccc{i}iiiiiic{dddd}iic{iiii}dc{dd}iiiccccc{ii}ddc{dd}iiccccc{ii}dc{dd}iccccc{ii}c{dd}ccccc{ii}ic{dd}dccccc{ii}iic{dd}ddccccc{ii}iiic{dd}dddccccc{ii}iiiic{dd}ddddccccc{ii}iiiiic{dd}dddddccccc{i}iiiiiic{dddd}iic{iiii}dc{dd}iiicccc{ii}ddc{dd}iicccc{ii}dc{dd}icccc{ii}c{dd}cccc{ii}ic{dd}dcccc{ii}iic{dd}ddcccc{ii}iiic{dd}dddcccc{ii}iiiic{dd}ddddcccc{ii}iiiiic{dd}dddddcccc{i}iiiiiic{dddd}iic{iiii}dc{dd}iiiccc{ii}ddc{dd}iiccc{ii}dc{dd}iccc{ii}c{dd}ccc{ii}ic{dd}dccc{ii}iic{dd}ddccc{ii}iiic{dd}dddccc{ii}iiiic{dd}ddddccc{ii}iiiiic{dd}dddddccc{i}iiiiiic{dddd}iic{iiii}dc{dd}iiicc{ii}ddc{dd}iicc{ii}dc{dd}icc{ii}c{dd}cc{ii}ic{dd}dcc{ii}iic{dd}ddcc{ii}iiic{dd}dddcc{ii}iiiic{dd}ddddcc{ii}iiiiic{dd}dddddcc{i}iiiiiic{dddd}iic{iiii}dc{dd}iiic{ii}ddc{dd}iic{ii}dc{dd}ic{ii}c{dd}c{ii}ic{dd}dc{ii}iic{dd}ddc{ii}iiic{dd}dddc{ii}iiiic{dd}ddddc{ii}iiiiic{dd}dddddc{i}iiiiiic{dddd}iic{iiii}dcicicicicicicicic{d}ic{dddd}iic{iiii}dc{dd}iiic{ii}ddc{dd}iic{ii}dc{dd}ic{ii}c{dd}c{ii}ic{dd}dc{ii}iic{dd}ddc{ii}iiic{dd}dddc{ii}iiiic{dd}ddddc{ii}iiiiic{dd}dddddc{i}iiiiiic{dddd}iic{iiii}dc{dd}iiicc{ii}ddc{dd}iicc{ii}dc{dd}icc{ii}c{dd}cc{ii}ic{dd}dcc{ii}iic{dd}ddcc{ii}iiic{dd}dddcc{ii}iiiic{dd}ddddcc{ii}iiiiic{dd}dddddcc{i}iiiiiic{dddd}iic{iiii}dc{dd}iiiccc{ii}ddc{dd}iiccc{ii}dc{dd}iccc{ii}c{dd}ccc{ii}ic{dd}dccc{ii}iic{dd}ddccc{ii}iiic{dd}dddccc{ii}iiiic{dd}ddddccc{ii}iiiiic{dd}dddddccc{i}iiiiiic{dddd}iic{iiii}dc{dd}iiicccc{ii}ddc{dd}iicccc{ii}dc{dd}icccc{ii}c{dd}cccc{ii}ic{dd}dcccc{ii}iic{dd}ddcccc{ii}iiic{dd}dddcccc{ii}iiiic{dd}ddddcccc{ii}iiiiic{dd}dddddcccc{i}iiiiiic{dddd}iic{iiii}dc{dd}iiiccccc{ii}ddc{dd}iiccccc{ii}dc{dd}iccccc{ii}c{dd}ccccc{ii}ic{dd}dccccc{ii}iic{dd}ddccccc{ii}iiic{dd}dddccccc{ii}iiiic{dd}ddddccccc{ii}iiiiic{dd}dddddccccc{i}iiiiiic{dddd}iic{iiii}dc{dd}iiicccccc{ii}ddc{dd}iicccccc{ii}dc{dd}icccccc{ii}c{dd}cccccc{ii}ic{dd}dcccccc{ii}iic{dd}ddcccccc{ii}iiic{dd}dddcccccc{ii}iiiic{dd}ddddcccccc{ii}iiiiic{dd}dddddcccccc{i}iiiiiic{dddd}iic{iiii}dc{dd}iiiccccccc{ii}ddc{dd}iiccccccc{ii}dc{dd}iccccccc{ii}c{dd}ccccccc{ii}ic{dd}dccccccc{ii}iic{dd}ddccccccc{ii}iiic{dd}dddccccccc{ii}iiiic{dd}ddddccccccc{ii}iiiiic{dd}dddddccccccc{i}iiiiiic{dddd}iic{iiii}dc{dd}iiicccccccc{ii}ddc{dd}iicccccccc{ii}dc{dd}icccccccc{ii}c{dd}cccccccc{ii}ic{dd}dcccccccc{ii}iic{dd}ddcccccccc{ii}iiic{dd}dddcccccccc{ii}iiiic{dd}ddddcccccccc{ii}iiiiic{dd}dddddcccccccc{i}iiiiiic{dddd}iic
\$\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\$

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.