17
\$\begingroup\$

Output this exact text:

1                i
12              hi
123            ghi
1234          fghi
12345        efghi
123456      defghi
1234567    cdefghi
12345678  bcdefghi
123456789abcdefghi
12345678  bcdefghi
1234567    cdefghi
123456      defghi
12345        efghi
1234          fghi
123            ghi
12              hi
1                i

A single trailing newline is acceptable, but no other formatting changes are allowed.

Rules and I/O

  • No input
  • Output can be given by any convenient method.
  • Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
  • Standard loopholes are forbidden.
  • This is so all usual golfing rules apply, and the shortest code (in bytes) wins.
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Can we use the uppercase alphabet instead? \$\endgroup\$
    – user41805
    Jun 25, 2018 at 15:47
  • 3
    \$\begingroup\$ @Cowsquack That would be a rule change. It says Output this exact text. \$\endgroup\$
    – Dennis
    Jun 25, 2018 at 15:52
  • \$\begingroup\$ @Cowsquack Nope - lowercase is required. \$\endgroup\$ Jun 25, 2018 at 15:57

40 Answers 40

1
2
0
\$\begingroup\$

Jelly, 22 21 bytes

9R€z⁶Zµạ106Ọ$Ṡ¡€Uṭ)ŒḄ

Try it online!

Relies on the (likely) unintended behavior that when (sign) acts on a character it yields Python's None. Because of this, is a one byte check for whether it's argument is a nonzero integer since None is falsey in Python. If this behavior is changed then works as well for one more byte.

Function that returns a list of lines.

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

Python 2, 97 94 bytes

i=o="123456789abcdefghi";c=8
while c:i=i[:c]+' '*(9-c)*2+i[-c:];o=i+'\n'+o+'\n'+i;c-=1
print o

Try it online!

Only posted as an alternative to using eval() and because I finally got it under 100. Basically starts with the middle row then works both up and down at the same time.

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

Yabasic, 103 bytes

a$="123456789abcdefghi"
For y=-8To 8
z=Abs(y)
?Mid$(a$,1,9-z);
For i=1To z?"  ";Next
?Mid$(a$,10+z)Next

Try it online!

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

Pascal (FPC), 110 105 bytes

var i:int32;begin for i:=-8to 8do writeln('123456789'[1..9-abs(i)],'abcdefghi'[abs(i)+1..9]:abs(i)+9)end.

Try it online!

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

PHP, 116 bytes

for(;++$i<18;)echo substr($s='123456789abcdefghi',0,$j=~-10-($k=abs(9-$i))).str_repeat(' ',$k*2).substr($s,-$j)."
";

Output

1                i
12              hi
123            ghi
1234          fghi
12345        efghi
123456      defghi
1234567    cdefghi
12345678  bcdefghi
123456789abcdefghi
12345678  bcdefghi
1234567    cdefghi
123456      defghi
12345        efghi
1234          fghi
123            ghi
12              hi
1                i

Sanbox

Cheers

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

Java 8, 107 102 bytes

v->{for(int i=1,j;++i<19;)for(j=19;j-->0;)System.out.printf("%c",j>0?j<i^j<20-i?32:106-j-j/10*39:10);}

Port of @Pietu1998's C answer, so make sure to upvote him!
-5 bytes thanks to @ceilingcat.

Try it online.

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

Lua, 103 bytes

for i=-8,8 do m=math.abs(i)print(("123456789"):sub(1,9-m)..(" "):rep(2*m)..("abcdefghi"):sub(m+1,9))end

Try it online!

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

C (gcc), 143 142 127+10=137 136+10=146 113+10=123 (compiler flags) bytes

-1 byte by replacing logical OR with bitwise operator.

-5 bytes thanks to Logern.

+9 bytes to fix the median line, that was output twice.

-23 bytes thanks to ceilingcat

char*s="123456789abcdefghi";G{for(;j<18;++j)putchar(i>j|j>17-i?s[j]:32);puts("");}f(){int i=0,j=0;for(;i++<8;)G;g(i+1,j);for(;i-->1;)G;}

Compiler flag:

-DG=g(i,j)

This macro factorizes the occurences of g(i,j): function declaration and calls.

Try it online!

Different approach than Pietu1998's great answer, more straightforward (and readable), but higher score.

Entry point is function f(); function g() handles the printing of each consecutive line.

Could be made a full program by renaming f to main, but it would yet increase the score.

Pretty version, macro G expanded:

g(i, j) {
    for(; j < 18;++j)
        putchar(i > j | j > 17 - i ? "123456789abcdefghi"[j] : 32);
    puts(""); // Break the line; shorter than putchar(10) or printf("\n")
}
f(i, j) {
    for (i = j = 0; i++ < 8;) // Upper half of the tie
        g(i, j);
    for(; i; --i) // Median line and lower half
        g(i, j);
}
\$\endgroup\$
6
  • \$\begingroup\$ 137 bytes - Try it online! \$\endgroup\$
    – user36046
    Sep 24, 2018 at 23:28
  • \$\begingroup\$ 137 but +10 for the compiler flags though \$\endgroup\$
    – joH1
    Sep 25, 2018 at 15:38
  • \$\begingroup\$ 137 is the total, 127 bytes of code and 10 bytes of compiler flags. \$\endgroup\$
    – user36046
    Sep 25, 2018 at 16:50
  • \$\begingroup\$ Oops sorry, my bad. Updating now! \$\endgroup\$
    – joH1
    Sep 25, 2018 at 19:34
  • \$\begingroup\$ @Logern I took the liberty to rename the macro to G, to match the function name. \$\endgroup\$
    – joH1
    Sep 25, 2018 at 19:51
0
\$\begingroup\$

Raku, 81 bytes

for -8..8 {my \a=(.abs-9).abs;say (1..a).join~' 'x.abs*2~'abcdefghi'.substr(*-a)}

Try it online!

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

///, 163 148 bytes

/w/lm//q/  //j/qqq//k/fghi
1234//l/qqq//m/q//n/dek567//o/i
12/1lwmolwho3llgho34wmk5wek56lnmmcn8mbcn89abcn8mbcnmmcdek56ldek5wekwmfgho3llgholwhi
1lwmi

Try it online!

\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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