34
\$\begingroup\$

Given a letter of the English alphabet, your task is to build a semi-diagonal alphabet to the input.

How to build a Semi-Diagonal alphabet?

Brief Description: First, you take the position of the letter in the alphabet, P (P is 1-indexed here). Then, you print each letter until the input (inclusive) on a line, preceded by P-1 and repeat that letter P times, interleaving with spaces.

Examples:

  • Given F, your program should output:

    A 
     B B 
      C C C 
       D D D D 
        E E E E E 
         F F F F F F 
    
  • Given K, your program should output:

    A
     B B 
      C C C 
       D D D D 
        E E E E E 
         F F F F F F 
          G G G G G G G 
           H H H H H H H H 
            I I I I I I I I I 
             J J J J J J J J J J 
              K K K K K K K K K K K 
    
  • Given A, your program should output:

    A
    

Rules

  • You may choose either lowercase or uppercase characters, but that should be consistent.

  • You may have extraneous spaces as follows:

    • One consistent leading space (on each line).
    • A trailing or leading newline(s).
    • Trailing spaces.
  • Input and output can be taken by any standard mean, and default loopholes apply.

  • You are allowed to output a list of lines instead, as long as you also provide the version.

  • This is , so the shortest code in bytes wins!

Inspired by this challenge.

\$\endgroup\$
  • \$\begingroup\$ Is output as list of strings ok? \$\endgroup\$ – Adám Aug 23 '17 at 15:16
  • 2
    \$\begingroup\$ Why the downvote? What can i improve? \$\endgroup\$ – user70974 Aug 23 '17 at 15:45
  • 1
    \$\begingroup\$ When you say "P is 1-indexed here", does here refer to the challenge or the example? \$\endgroup\$ – Dave Aug 23 '17 at 15:48
  • 3
    \$\begingroup\$ @pizzakingme No, you may not. \$\endgroup\$ – user70974 Aug 23 '17 at 16:05
  • 1
    \$\begingroup\$ I accidentlly got an interesting pattern while golfing my answer: tio.run/##K0nO@f@/… \$\endgroup\$ – sergiol Oct 19 '17 at 19:19

67 Answers 67

0
\$\begingroup\$

SNOBOL4 (CSNOBOL4), 115 bytes

	U =&UCASE
	U INPUT @L
N	U POS(X) LEN(1) . R
	OUTPUT =DUPL(' ',X) DUPL(R ' ',X + 1)
	X =LT(X,L - 1) X + 1	:S(N)
END

Try it online!

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

Swift, 133 bytes

func f(c:String){for i in 9..<Int(c,radix:36)!{var s=""
for _ in 9..<i{s+=" "}
for _ in 9...i{s+=String(i+1,radix:36)+" "}
print(s)}}

Try it online!

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

Julia 0.4, 48 bytes

It should work the same in more recent versions of Julia as well.

x->[" "^i*"$c "^i for (i,c) in enumerate('A':x)]

Try it online!

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

Excel VBA, 78 71 Bytes

Anonymous VBE immediate window function that takes input from range [A1] and outputs to the VBE immediate window

For i=1To[Code(A1)-64]:?:?Spc(i-1);:For j=1To i:?Chr(i+64)" ";:Next j,i

-1 Byte for switching to leading newline over trailing, and condensing Next statements

-6 bytes for using Spc() over String()

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

Burlesque - 39 bytes

-]'Ajr@id?i?*m{' []}zim{p^' j?*j_+}unsh

This is not fully golfed yet and (trivially at least the sh can be replaced with Q) but it's a first start. m{}un can probably be replaced by a version of map that unlines and zim[ is a good candidate for a shortcut in the near future. The two maps can also probably be merged together into a single map.

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

Common Lisp, 89 bytes

(dotimes(m(-(char-code(read))63))(format t"~va~v@{~c ~:*~}~%"m #\  m(code-char(+ m 64))))

Try it online!

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

SmileBASIC, 58 57 bytes

INPUT E$WHILE L$<E$L=L+1L$=CHR$(L+#X)+" "?" "*L;L$*L
WEND
\$\endgroup\$

Your Answer

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