78
\$\begingroup\$

Given no input, your task is to generate the following:

a
 b
  c
   d
    e
     f
      g
       h
        i
         j
          k
           l
            m
             n
              o
               p
                q
                 r
                  s
                   t
                    u
                     v
                      w
                       x
                        y
                         z

Nonvisually, your task is to generate each letter in the alphabet, with spaces before it equal to its position in the alphabet minus one.

If you print this, it must appear like the above. Extraneous whitespace that does not affect appearance, as well as a trailing newline, is allowed. You can use all lowercase, or all uppercase.

You may also return this from a function as per usual rules, either as a string with newlines, or a list of strings.

This is , so shortest answer in bytes wins!

\$\endgroup\$
6
  • \$\begingroup\$ Do the spaces need to be real ASCII spaces, or can I give output like a<VERTICAL-TAB>b<VERTICAL-TAB>c...? How about if there are some backspace characters in there too? As long as the visual result is the same? \$\endgroup\$ Commented Jun 8, 2017 at 23:30
  • \$\begingroup\$ @DigitalTrauma as long as it appears the same, I don't care what kind of whitespace you use. \$\endgroup\$
    – Stephen
    Commented Jun 8, 2017 at 23:31
  • \$\begingroup\$ Can I use tabs instead of spaces? \$\endgroup\$
    – user69335
    Commented Jun 9, 2017 at 23:28
  • \$\begingroup\$ @yamboy1 hmm, probably not. Most tabs are set to a large number of spaces - if your diagonal looks like it has 4 spaces before the b, it won't look very diagonal. If it looks like the slope is ~-1 then it's fine. \$\endgroup\$
    – Stephen
    Commented Jun 9, 2017 at 23:32
  • \$\begingroup\$ does not affecting appearance include having an extra leading space or 2? \$\endgroup\$ Commented Sep 11, 2017 at 17:08

170 Answers 170

1
2 3 4 5 6
93
\$\begingroup\$

Charcoal, 2 bytes

↘β

Try it online!

How?

 β - the lowercase alphabet
↘  - direction

Exactly the kind of challenge for which Charcoal was originally designed.

\$\endgroup\$
8
  • 7
    \$\begingroup\$ The right language :) \$\endgroup\$
    – Stephen
    Commented Jun 8, 2017 at 1:44
  • 2
    \$\begingroup\$ This reminds me, I should probably work on Crayon some more... I believe ↘"abc ... xyz"q would be the shortest working program. (Try it online!) ↘``26O;)q should work (start with a backtick; for each I in 0...25, pop the implicit I, increment the backtick and output), but it throws an "empty stack" error for some reason... \$\endgroup\$ Commented Jun 8, 2017 at 1:51
  • 3
    \$\begingroup\$ 2 bytes?! In what encoding is the SOUTH EAST ARROW a single byte? \$\endgroup\$
    – Wyck
    Commented Jun 8, 2017 at 13:00
  • 7
    \$\begingroup\$ @Wyck Charcoal (note: speculation) uses a custom code page, which can be compressed to 1 byte instructions. That's legitimate for Code Golf. codegolf.meta.stackexchange.com/questions/9428/… \$\endgroup\$ Commented Jun 8, 2017 at 13:12
  • 17
    \$\begingroup\$ @StephenS, I think you mean the bottom-right language :) \$\endgroup\$
    – Wossname
    Commented Jun 9, 2017 at 21:29
20
\$\begingroup\$

C, 45 bytes

f(i){for(i=0;++i<27;)printf("%*c\n",i,i+96);}

Thanks to @Dennis for saving 5 bytes!

\$\endgroup\$
13
  • 10
    \$\begingroup\$ Works on my machine™ \$\endgroup\$ Commented Jun 8, 2017 at 2:08
  • \$\begingroup\$ I think you'd have to initialize or reset i at some point. At least on TIO, f() only works once. \$\endgroup\$
    – Dennis
    Commented Jun 8, 2017 at 2:37
  • \$\begingroup\$ @Dennis Ah, you're right. Fixed that. \$\endgroup\$
    – Doorknob
    Commented Jun 8, 2017 at 2:46
  • \$\begingroup\$ f(i){for(i=0;++i<27;printf("%*c\n",i,i+96));} saves a few bytes. \$\endgroup\$
    – Dennis
    Commented Jun 8, 2017 at 3:38
  • 3
    \$\begingroup\$ f(i){for(i=96;i<122;)printf("%c\v",++i);} for 41 bytes - make sure to run this on an actual terminal (yes, this is allowed) \$\endgroup\$
    – Maya
    Commented Jan 15, 2018 at 16:39
15
\$\begingroup\$

Python 2, 36 bytes

n=65;exec"print'%*c'%(n,n);n+=1;"*26

This takes advantage of the extraneous whitespace that does not affect appearance rule.

Try it online!

Alternate version, 38 bytes

n=1;exec"print'%*c'%(n,n+96);n+=1;"*26

This produces the exact output from the challenge spec.

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ How does %*c even work? \$\endgroup\$
    – Leaky Nun
    Commented Jun 8, 2017 at 4:22
  • \$\begingroup\$ %*<identifier> takes two arguments: the length to pad it to and the actual thing to substitute. Some printf implementations have even more obscure features, such as the %1$<identifier> I used here. \$\endgroup\$
    – Dennis
    Commented Jun 8, 2017 at 4:32
14
\$\begingroup\$

Ruby, 28 bytes

26.times{|a|puts" "*a<<97+a}

Try it online!

Explanation:

The << operator on a string in Ruby does the trick, as explained in the Documentation

  • str << integer → str

  • str << obj → str

Append—Concatenates the given object to str. If the object is a Integer, it is considered as a codepoint, and is converted to a character before concatenation.

\$\endgroup\$
14
\$\begingroup\$

05AB1E, 14 8 6 bytes

-2 bytes thanks to @Emigna

AvyNú»

How it works

A      # lowercase alphabet
 v     # for letter in alphabet
  y    # push letter
   N   # push index of letter
    ú  # Pad letter with index of letter spaces
     » # Join with stack on newline.

Try it online!

Original version, 14 bytes

26FNð×N65+ç«}»
\$\endgroup\$
8
  • \$\begingroup\$ You can save another 2 bytes with AvyNú». \$\endgroup\$
    – Emigna
    Commented Jun 8, 2017 at 6:09
  • \$\begingroup\$ @Emigna: Thanks! Will edit that in. \$\endgroup\$
    – Neil A.
    Commented Jun 8, 2017 at 6:37
  • \$\begingroup\$ ƶ seems so perfect, but it's not :(. \$\endgroup\$ Commented Jun 8, 2017 at 14:28
  • \$\begingroup\$ Λ probably wasn't available yet at the time, but 26A3Λ saves a byte. \$\endgroup\$ Commented May 8, 2018 at 8:35
  • 1
    \$\begingroup\$ @MagicOctopusUrn ₂A3Λ would have been even shorter. \$\endgroup\$ Commented Aug 12, 2018 at 14:45
13
\$\begingroup\$

Vim, 29 bytes

:h<_↵↵↵y$ZZ25o <Esc>{qqpblD+q25@q

Try it online!

↵ means press the return key

< Esc> means press the escape key

How does this work?

:h<_↵↵↵                             Open the help and navigate to the alphabet
       y$ZZ                         Copy the alphabet and close the help
           25o <Esc>                Abuse auto-indent and create a whitespace diagonal
                    gg              Go to the beginning of the file
                      qq            Record a macro
                        pb          Paste the alphabet and go to the first letter
                          lD        Go to the second letter and cut the rest of the alphabet
                            +       Go to the first non-blank character in the next line
                             q      Stop recording the macro
                              25@q  Run the macro for the remaining letters
\$\endgroup\$
9
  • 1
    \$\begingroup\$ Try it online! You can use this to demonstrate it (V is based on Vim and mostly backwards compatible except apparently autoindent defaults to off). Also, less important, you missed the + in your explanation which threw me for a second. \$\endgroup\$
    – nmjcman101
    Commented Jun 8, 2017 at 11:36
  • \$\begingroup\$ Thanks @nmjcman101! I was trying to find some way to try vim online and never knew that about V \$\endgroup\$
    – jmriego
    Commented Jun 8, 2017 at 12:26
  • \$\begingroup\$ You can use instead of <Esc>. It looks a little better in my opinion. \$\endgroup\$
    – Wheat Wizard
    Commented Jun 8, 2017 at 14:05
  • \$\begingroup\$ You can save one byte if you do { instead of gg \$\endgroup\$
    – DJMcMayhem
    Commented Jun 8, 2017 at 21:24
  • \$\begingroup\$ You could use 2↵ instead of ↵↵↵ and maybe Y instead of y$ \$\endgroup\$
    – G B
    Commented Jun 9, 2017 at 6:08
13
\$\begingroup\$

R, 38 37 36 bytes

write(intToUtf8(diag(65:90),T),1,26)

(The use of write is inspired by @Giuseppe's answer.)

\$\endgroup\$
4
  • 3
    \$\begingroup\$ I swear I tried that but couldn't get it to work! Well done. You can save 1 byte by using 65:90, since upper case is allowed. \$\endgroup\$ Commented Jun 8, 2017 at 13:56
  • \$\begingroup\$ @user2390246 Thanks for pointing out! \$\endgroup\$ Commented Jun 8, 2017 at 14:13
  • \$\begingroup\$ you can use 1 rather than "" to shave off another byte. \$\endgroup\$
    – Giuseppe
    Commented Apr 12, 2018 at 23:22
  • \$\begingroup\$ @Giuseppe Thanks for pointing out! \$\endgroup\$ Commented Apr 13, 2018 at 4:40
12
\$\begingroup\$

JavaScript (ES6), 60 59 bytes

f=(n=10)=>n-36?" ".repeat(n-10)+n.toString(++n)+`
`+f(n):""

A recursive function which returns a string with a trailing newline.

\$\endgroup\$
12
  • 1
    \$\begingroup\$ Whoa, that's so sneaky. Converting a number in the range 10 to 36 to a number in a weird base. Don't understand yet why the base has to increase too though. \$\endgroup\$ Commented Jun 8, 2017 at 2:22
  • 2
    \$\begingroup\$ @SteveBennett Correct, but n.toString(++n)+f(n) is a byte shorter than n.toString(36)+f(n+1). \$\endgroup\$ Commented Jun 8, 2017 at 2:27
  • 1
    \$\begingroup\$ You could do f=(n=10,s='')=>n-36?s+n.toString(++n)+'\n'+f(n,s+' '):"" for 55. \$\endgroup\$
    – Arnauld
    Commented Jun 8, 2017 at 6:39
  • 1
    \$\begingroup\$ Save a byte with some ES8: "".padEnd(n-10)+n.toString(++n). \$\endgroup\$
    – Shaggy
    Commented Jun 8, 2017 at 8:09
  • 1
    \$\begingroup\$ @Arnauld, f=(n=10,s='')=>n-36?s+n.toString(++n)+'\n'+f(n,s+' '):s would seem to be permissible. \$\endgroup\$
    – Shaggy
    Commented Jun 8, 2017 at 8:37
10
\$\begingroup\$

PHP, 39 bytes

for($s=a;!$s[26];$s=" ".++$s)echo"$s
";
\$\endgroup\$
1
  • 1
    \$\begingroup\$ This is rather verbose :) Here's mine \$\endgroup\$
    – aross
    Commented Jun 28, 2017 at 15:55
9
\$\begingroup\$

Pure Bash, 13

echo {a..z}^K^H

Here ^K and ^H are literal vertical tab and backspace ASCII control characters. The xxd dump of this script is as follows - use xxd -r to regenerate the actual script:

00000000: 6563 686f 207b 612e 2e7a 7d0b 08         echo {a..z}..
  • {a..z} is a standard bash brace expansion to produce a b c ... z (space separated)
  • the ^K vertical tab drops the cursor down one line to the same position
  • the ^H backspace moves the cursor back one to erase the separator space

Try it online. col and tac are used in the footer to get this to render correctly in a browser window, but this is unnecessary in a regular terminal.


If the above unorthodox control characters in the output are too much of a stretch for you, then you can do this:

Bash + common utilities, 24

echo {a..z}^K^H|col -x|tac

Here ^K and ^H are literal vertical tab and backspace ASCII control characters. The xxd dump of this script is as follows - use xxd -r to regenerate the actual script:

00000000: 6563 686f 207b 612e 2e7a 7d0b 087c 636f  echo {a..z}..|co
00000010: 6c20 2d78 7c74 6163                      l -x|tac

Try it online. The vertical tab and backspace may be rendered invisible by your browser, but they are there (invisible on chrome, visible on firefox).

  • col -x re-renders the input such that funny control characters are replaced with spaces and newlines to give the same visual result
  • for some reason col outputs lines in reverse order. tac corrects that.
\$\endgroup\$
3
  • \$\begingroup\$ That is very cool :) (and thanks to meta and @Dennis for suggesting sorting answers on codegolf by activity instead of score, to have better answers come up instead of the (very boring) codegolf langages builtins ones : codegolf.meta.stackexchange.com/questions/10127/…) \$\endgroup\$ Commented Jun 9, 2017 at 13:35
  • \$\begingroup\$ Many terminals render ^K as cursor up, which is the behaviour that col must be emulating here. \$\endgroup\$
    – Neil
    Commented Jun 12, 2017 at 15:24
  • \$\begingroup\$ @Neil yes, that makes sense - the col manpage calls a VT a "reverse line feed". xterm, gnome-terminal and OSX terminal all drop down a line though... \$\endgroup\$ Commented Jun 12, 2017 at 18:04
8
\$\begingroup\$

V, 15 13 11 bytes

¬azòÙr klDj

Try it online!

Explanation

¬az         ' Insert a-z
   ò        ' Recursively
    Ù       ' Duplicate current line down
     r      ' Replace the first character with a ' '
       kl   ' Move up a line and right
         D  ' Delete from here to the end
          j ' Move back down
\$\endgroup\$
8
\$\begingroup\$

Brain-Flak, 124, 116, 106 bytes

((((()))))(((([][]){}){})[[]()]<>){(({})<(({})<({}<>({})({})<>)>)
{({}<(<>({})<>)>[()])}{}(<>[][]<>)>[()])}

Try it online!

Explanation:

This answer abuses the Stack Height Nilad, but in a new way that I've never used before, which I'm pretty proud of. Other than that, the answer's not too clever.

So analyzing the characters used in this ASCII art, there are really three values that are frequently used:

  • 32 (space),

  • 64 (add 64 to N to get the N'th letter of the alphabet), and

  • 10 (newline)

As well as 26. (number of loops) And these numbers are pushed in different locations, so we can't really reuses intermediate values to make the large numbers smaller. And pushing all for of these numbers is a whopping 86 bytes alone:

10:
((()()()()()){})

26:
((((()()()){}){}()){})

32:
((((()()()()){}){}){})

64:
(((((()()()()){}){}){}){})

This is horrible. So here's how we make it more convenient. The obvious approach is to push a 32 onto the alternate stack, which makes our 32 snippet become: (<>({})<>) and our 64 snippet become (<>({})({})<>). If we combine our initial push 32 with our initial push 26, we can save 8 bytes roughly. (my first golf).

But here is where the trick I'm really proud of comes in. Since we're not using the alternate stack for anything else, we might as well golf down the 10 also. To do this, we'll push 4 arbitrary numbers onto the stack right at the start of the program. Since we also push 32, this increases the value of the [] nilad, to 5, which makes our 10 snippet much more convenient. And lucky for us, it actually lets us golf the push 32 and 26 snippet down too!

#Push 32, 26
(((((()()()()){}){}){})<>[(()()()){}])

#Push 10
((()()()()()){})

Becomes

#Push 32, 26 (-2 bytes)
(((((())))))((([][][]){}()())[[]]<>)

#Push 10 (-6 bytes)
(<>[][]<>)

So here is a detailed explanation:

# Push 1 four times
((((()))))

# Push 32 to main stack (to reuse later)...
((([][][]){}()())

# And then 26 to the alternate stack
[[]()]<>)

#While true
{

    # Keep track of the current TOS
    (({})<

        # Push [TOS, TOS + 64] (To get uppercase characters)
        (({})<({}<>({})({})<>)>)

        # TOS times...
        {
            # Decrement the loop counter, while pushing a space underneath it
            ({}<(<>({})<>)>[()])

        # Endwhile, pop zeroed counter
        }{}

        # Push 10 (newline)
        (<>[][]<>)

    # Push TOS - 1 back one
    >[()])

# Endwhile
}
\$\endgroup\$
7
\$\begingroup\$

Google Sheets, 67 65 bytes

=ArrayFormula(IF(ROW(A1:Z)=COLUMN(A1:Z26),CHAR(96+ROW(A1:Z26)),))

=ArrayFormula(IF(ROW(A1:Z)=COLUMN(A1:Z26),CHAR(96+ROW(A1:Z26)),""))

Going off the clarification that any whitespace will do, I've used visibly empty cells

Output

Let me know if this doesn't count, if I've misunderstood the byte count or if I've screwed up some etiquette as this is my first post here.

Edit: It turns out I can save 2 bytes by leaving out the "" as Google sheets will accept an empty if value.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Welcome to PPCG :) Looks good! Good job beating the other Google Sheets answer! \$\endgroup\$
    – Stephen
    Commented Jun 9, 2017 at 15:45
7
\$\begingroup\$

APL (Dyalog), 9 7 bytesSBCS

-2 bytes thanks to ngn's hint.

↑⍨∘-⌸⎕A

[Try it online!][TIO-j3o0ipjy]

⎕A the uppercase Alphabet

 between each (element,list of indices) pair, insert the following tacit function:

↑⍨ from the element (the letter) take…

 the…

- negated-index number of characters, i.e. that many characters from the back, padding on the front with spaces.

Try it online!

\$\endgroup\$
6
  • \$\begingroup\$ Nice. My J attempt was quite a bit more verbose. Is there a translation of these verbs into J? \$\endgroup\$
    – Jonah
    Commented Jun 8, 2017 at 7:27
  • \$\begingroup\$ @Jonah Verbs: is {. and is i. Adverbs: ¨ is "0 and is ~. \$\endgroup\$
    – Adám
    Commented Jun 8, 2017 at 8:28
  • \$\begingroup\$ Thanks. Looks like the J translation loses some brevity: (a.{~97+i.26){."0~-1+i.26 \$\endgroup\$
    – Jonah
    Commented Jun 8, 2017 at 15:08
  • \$\begingroup\$ @Adám the output doesn't look as required; hint: use to output a proper matrix and save 2 bytes \$\endgroup\$
    – ngn
    Commented Feb 26, 2018 at 21:41
  • \$\begingroup\$ @ngn You may also return (…) a list of strings. But I'll investigate. Edit: Oh yes, of course! \$\endgroup\$
    – Adám
    Commented Feb 26, 2018 at 21:43
6
\$\begingroup\$

PowerShell, 29 bytes

0..25|%{' '*$_+[char]($_+97)}
\$\endgroup\$
1
  • 1
    \$\begingroup\$ I like how you add 97 to $_ as you go, nice. \$\endgroup\$
    – root
    Commented Feb 26, 2018 at 21:14
6
\$\begingroup\$

Octave, 25 19 or 12? bytes

[diag(65:90)+32 '']

Try it online!

Other solution proposed by @LuisMendo (12 bytes) that I tested it in windows version of Octave:

diag('a':'z')

Explanation:

Generates diagonal matrix of a:z.

\$\endgroup\$
3
  • \$\begingroup\$ @LuisMendo In tio I can not produce the same result. It is an expression ,that can be evaluated ,that produce the desired result:) \$\endgroup\$
    – rahnema1
    Commented Jun 8, 2017 at 9:46
  • \$\begingroup\$ The solution proposed by Luis seems to work on TIO now... New version of Octave maybe? \$\endgroup\$ Commented Jun 1, 2018 at 21:08
  • \$\begingroup\$ Or new version of tio!? \$\endgroup\$
    – rahnema1
    Commented Jun 2, 2018 at 0:44
6
\$\begingroup\$

Java 8, 72 71 70 61 bytes

o->{for(int a=0;a++<26;)System.out.printf("%"+a+"c%n",a+96);}

-1 byte by outputting the uppercase alphabet instead of lowercase.
-1 byte by printing directly, instead of returning a multiline String.
-8 bytes thanks to @OliverGrégoire by using printf directly to get rid of String s="";. And also -1 byte by changing ()-> to o->.

Try it here.

\$\endgroup\$
10
  • \$\begingroup\$ The naive implementation is shorter than I would have thought. You can save a byte with c=65 (or 64 actually) so you don't need the 3 digit number. Can returning an array instead of the string save you any bytes as you can remove the +"\n"? \$\endgroup\$ Commented Jun 8, 2017 at 8:37
  • \$\begingroup\$ @TheLethalCoder Ah, didn't knew we were allowed to output the uppercase alphabet. Skimmed over that. Thanks. And what do you mean by outputting an array? Like an array of arrays? \$\endgroup\$ Commented Jun 8, 2017 at 8:42
  • 1
    \$\begingroup\$ @TheLethalCoder Any tip is welcome, so thanks. But in this case it won't be shorter. :) \$\endgroup\$ Commented Jun 8, 2017 at 8:47
  • 1
    \$\begingroup\$ @Winter About your first suggestion, that's still being discussed in this meta-post, but judging by the votes I guess it's indeed allowed from now on. As for the second I'm not sure.. It kinda feels like cheating/bending the rules, especially after these heated discussions in the comments of this meta post and answers. \$\endgroup\$ Commented Jun 10, 2017 at 10:12
  • 1
    \$\begingroup\$ 62 bytes: ()->{for(int a=0;a++<26;)System.out.printf("%"+a+"c%n",a+96);} using the same idea as in another challenge. \$\endgroup\$ Commented Aug 20, 2017 at 22:58
6
\$\begingroup\$

shortC, 33 bytes

AOI_=0;++_<27;R"%*c\n",_,_+96));}

Try it online!

\$\endgroup\$
5
\$\begingroup\$

Jelly,  10  9 bytes

-1 byte thanks to Dennis (avoid decrementing J by using a lowered range, 26Ḷ, directly)

26Ḷ⁶ẋżØaY

A full program that prints the result.

Try it online!

(ØaJ’⁶ẋż for 7 is a monadic link that returns a list of lists of lists of characters, but that is like [["a"],[" ","b"],[" ","c"],...] which is probably unacceptable.)

I would, however, not be surprised if there was a shorter way I have not thought about!

How?

26Ḷ⁶ẋżØaY - Main link: no arguments
26        - literal 26
  Ḷ       - lowered range = [0,1,2,...,26]
   ⁶      - literal space character
    ẋ     - repeat          [ [],      [' '],      [' ',' '],    ...,  [' ',' ',...,' ']]
      Øa  - yield lowercase alphabet
     ż    - zip             [[[],'a'],[[' '],'b'],[[' ',' '],'c'],...,[[' ',' ',...,' '],'z']]
        Y - join with newlines  [[],'a','\n',[' '],'b',\n',[' ',' '],'c','\n',...,'\n',[' ',' ',...,' '],'z']
          - implicit print (smashes the above together, printing the desired output)
\$\endgroup\$
7
  • \$\begingroup\$ I'd even allow [["a"],[" ","b"],[" "," ","c"],...] since a list of chars is an alternative definition for a string, but a tuple doesn't seem to fit :) \$\endgroup\$
    – Stephen
    Commented Jun 8, 2017 at 2:00
  • \$\begingroup\$ Yeah that's what I thought. \$\endgroup\$ Commented Jun 8, 2017 at 2:01
  • 1
    \$\begingroup\$ ...note that in the above each "..." is a list of chars, so really it's [[['a']],[[[' '],['b']],[[' ',' '],['c']],...] since Jelly has no strings, just lists. \$\endgroup\$ Commented Jun 8, 2017 at 2:14
  • \$\begingroup\$ 26Ḷ⁶ẋżØaY saves a byte. \$\endgroup\$
    – Dennis
    Commented Jun 8, 2017 at 2:33
  • \$\begingroup\$ ØaJ’⁶ẋż for 7, for your alternative version. \$\endgroup\$
    – Leaky Nun
    Commented Jun 8, 2017 at 2:50
5
\$\begingroup\$

Alice, 22 20 bytes

52E&waq'a+q&' d&o]k@

Try it online!

Even though the output is a string, it turns out ordinal mode is not the way to go for this challenge.

Explanation

52E&w             k@     do 26 times
     a                   push 10 (LF)
      q                  push current tape position (initially zero)
       'a+               add the ASCII code for "a"
          q&'            push 32 (space) a number of times equal to tape position
              d&o        output entire stack
                 ]       move tape position one space to the right

Previous solution

["za/?rO&
' !]\"ohkw@/

Try it online!

I went through about ten 23-byte solutions before I was able to find this one.

Explanation

This program uses the tape to track the number of spaces to output. Cardinal and ordinal modes use the same tape, but they have separate tape heads. The two modes have different interpretations of what they see on the tape, and the program fully exploits that difference.

The commands are executed in the following order:

[                   move cardinal tape position left
 "za"               push this string (as a string, since the final " is in ordinal mode)
     r              interpolate to entire range (i.e., the lowercase alphabet backward)
      h             split first character from string
       &            for each character in string: push that character and...
        w                                         push current address onto return address stack
         ' !        (cardinal mode) place 32 (space) at current cardinal tape position
            ]       (cardinal mode) move cardinal tape position right
             ?      (back to ordinal mode) read string from tape starting at ordinal tape position
                    this string will consist of n-1 spaces.
              o     output string of spaces
               O    output top of stack (current letter) followed by newline
                k   return to pushed return address. 
                    after 26 times through this loop, the return address stack will be empty and this is a no-op.
                 @  terminate
\$\endgroup\$
5
\$\begingroup\$

Brainfuck, 103 bytes

>-<-----[[<+>->>+++>-<<<]>++]<<<<<<<<<[-]>>>-[<[-]<[-]<[>+>+<<-]>>[<<+>>-]<[>>>>.<<<<-]<+>>>>.+>>.<<<-]

Try it online!

The location of the variables is somehow improvable.

Explanation

>-<-----[[<+>->>+++>-<<<]>++]   Initializes the tape.
<<<<<<<<<[-]>[-]>>-             Resets variables that
                                need to be at 0.
[                               For loop (25 to 0).
 <[-]<<[>+>+<<-]>>[<<+>>-]      Copy the spaces count in
                                order to use it in a loop.
 <[>>>>.<<<<-]                  Prints the spaces.
                                Prints the character followed
 <+>>>>.+>>.<<<-                by a new line. Also decrements
                                the main loop counter.
]
\$\endgroup\$
5
\$\begingroup\$

Google Sheets, 69 bytes

=ArrayFormula(JOIN("
",REPT(" ",ROW(A1:A26)-1)&CHAR(96+ROW(A1:A26))))

Nothing complicated here. The only trick is using ArrayFormula and ROW(A1:A26) to return 26 different values for the JOIN function. Output looks like this:

Output


I think Excel 2016 can do the same thing with TEXTJOIN but I can't enter array formulas in the online version and only have 2013 myself. The formula should be this:

=TEXTJOIN("
",FALSE,REPT(" ",ROW(A1:A26)-1)&CHAR(96+ROW(A1:A26)))

Entering it as an array formula (Ctrl+Shift+Enter) adds curly brackets { } on both sides, bringing it to 67 bytes. Anyone who can verify it works is welcome to use it as their own answer.

\$\endgroup\$
5
\$\begingroup\$

Seed, 6014 bytes

I don't think this will win any awards, but just for fun, here's a solution in Seed.

86 11103250503694729158762257823050815521568836599011209889044745493166180250197633623839266491438081837290079379263402288506775397211362446108152606095635373134468715450376738199004596861532212810083090232034321755895588102701453625219810339758989366211308223221344886043229936009486687653111291562495367476364760255760906228050130847228170228716790260998430434027546345063918859356161024202180254514539438087787769611000320430464740566450402368450792375043801526494811596087812709169139468697779440918934518195843690439213251884693846598754642076364755341359062651237754916053099089619667382845958005035392458577634784453744876558142057256976895330859887974064083588368087014591508237946214519271550243549214199679364098489146944338807874570414584343165070707969101892779772740177526390597395955859236589308394889243501541206981604661264930842784772121710695027991351718061777696274815931123342985242351444203296855501870888626347939456384376808446806093364176576945969539054970975848477876079897476093353730443488664472826635815956526890935049081522728044807877072639829234224838977148057506785320443165975265560224605597481381188291535996775480326796788286452216432605854564432262547835415260058472165825285438444435690700488258778785613363062417500848996527077259315494936037544655054620369560227407957368700650031346856230643646273909094915618471799926504192999361174763592054723307855670381682927214117502862645460031555724588536036895597768493827964819026940533784490457441244859937078155137620826821294513857153097135094397278852300032685608169642137925241118197368192392427097109982751185030229544527638686131131545529690698706313745703838144933923021851042677941879847025167921010148923860660695145106913052517930707522151230705792709484338746351589089180137363986003757314611932324492978098101655359729841878862276799317010824753645947659706175083519817734448003718088115457982394423932136760435046136644679525408371158980833993157988971884061469882136904103033944270884697456159261033500286722891139158500027351042265757431184139617566089023339480051231776345929815102059539844917563709940188668873305602146506284075271989710388430531233185164106985265575418252638186398535149202928422854319253947591044830747981534342833040219194969504971457701296402664807369043224201667623773161453335066484102800249947322601702575025462427139266561015140950621152993027466758026351218924607290766894274223554418125824416921899080393405328694235821466034161071834073874727856768719898425047229002772806527172294625623026601313091815217479540688812203850300478145319935479599086534606210099372526810614742385909275512758349679098012967475393301857434507012875239092688018536028125644341148882858752275129016876257290205949225918496182271679312996010157634568807332616541938310641844258434083838017690572891417189135014450484203635258935943095637185443145042430274553211816422809756194554145177421779800554334935224073734034988935790096239926730047370699006392111034056662661567902477446646680125183082979598538506383502737734442490068661537425714549752783861222862366340979663873475326752237893690641570287341027097775099918958849864419430754493042534812120486345363285167685811903366691676146427476942948696624274431993989133835880516551024369474029197791751838810883302415448112237526350703063618171739262753474029252659418383385834751808940073804107171146665382663467460066719556797639176747423279761528061219482681051780434845070421974558638870988408449698678976622755518024906714421419806347234183574860655249471877105716127767795785164699804819127058322715857697491583787449703283625085118896433923054087238479453964363805045497229148813441732912067120594705269402106426011497763749556561398150139686331615167139081591537739333533146667211063179804707883556569241294269430626179579760506971066676011512530066694518309930078451295032445835025178124213221937594928472509588116557231122849491576207720183829735710200290762251904109318007206980645946249679357907549498615310165588678201768095297568708803842208357473777731751349499510116345704811971207818719582793964185192140178454948686109674659005978400204479072321714207828018696339659886683414074211823497880135255138161141724546221354224299071581607979907417508104234534779573666933024250229754952685174194168516481670999039048675109878524061868078078216337487277443941946961426121900907734301692962783139932352047932263834773963592317279425421954035566305805348109175553209815893678595198155962166838761859540063188209014774346841267440789072833797121217961797443744676162541668802226500817146368372390178287945076657776275930590173768326046610094573983886099504933977126798348879838826160714899283593774855907724617352862079916515034033299006419237012240730789008999523238851913897908225482003661109026061857228300111070725651744312468140016983078297938157227595743419983763920290850801438187869169473456288283458163865462359588316419331445070232596307970490434468929587726795603069137946085898481642595124580643542063564880389350236902538522311931690905858973696558714577085714396738993556273941292496636824719451697631982422926675238248502170501569627556395875619564600587531422890212003952929325067813498958390095519100963598626450443103780781917045489137526377521695121594716424797216910752252094749957224424042047863869830458287114846161217532552045343745235776511344577755412402833175338541217548987687334493461236111032661075185714361252784989689657180878190058132112701323898697673356854132286586129946906160482715702618768869398700713988301485421822519104930442450343377920756456344715552821899659777521739288202633751258303637433110490141551780764889912485271829265224821750882760152112536985349681370761157202793523201156381835717321637420939424473215237574260806475544972321933149796156065126465186203580256364372579422208318560608817806013462242728082475787319168695978160861791054731154820533251279706873332364894538291172324730671914083193733203570060223897442373172904974570329139578763294810924815364789498523721281918680145538278976651264

It translates to the following Befunge program:

vaa{       @>
v#      g02<v
>30g20g`   |
10g-:!v!: < >#<
v,:g02_40g,1- ^
>1+20p$91+, v
\$\endgroup\$
5
\$\begingroup\$

brainfuck, 80 bytes

++++++++[>+>++++>++++++++>+++<<<<-]>++>>+>++[->[<<<.>>>->+<]>+[-<+>]<<<.+<<.>>>]

Try it online!

Formatted:

++++++++[>+>++++
>++++++++>+++<<<
<-]>++>>+>++[->[
<<<.>>>->+<]>+[-
<+>]<<<.+<<.>>>]

Uses a simple multiplicative generation function to put some constants in memory, then repeats the process of printing N spaces then 'A' + N for N = 0..25.

Annotated:

INITIALIZE TAPE: 10 32 65 >26< 0 0
C_NEWLINE: 10
C_SPACE: 32
V_ALPHA: 65
V_COUNTER: 26
V_PREFIX: 0
V_PREFIX_TEMP: 0
++++++++[>+>++++>++++++++>+++<<<<-]>++>>+>++

WHILE V_COUNTER != 0  [-
   "PRINT C_SPACE REPEATED V_PREFIX TIMES"
   "V_PREFIX_TEMP = V_PREFIX"
     V_PREFIX TIMES  >[-
       PRINT C_SPACE <<<.>>>
       INCREMENT V_PREFIX_TEMP >+<
     ]
   "V_PREFIX = V_PREFIX_TEMP PLUS 1"
     V_PREFIX_TEMP PLUS 1 TIMES  >+[-
       INCREMENT V_PREFIX <+>
     ]
   PRINT C_ALPHA <<<.
   INCREMENT C_ALPHA +
   PRINT C_NEWLINE <<.
>>>]
\$\endgroup\$
5
\$\begingroup\$

brainfuck, 121 bytes

+++++++++++++[>+++++>++<<-]+++++[>>>++<<<-]++++[>>>>++++++++<<<<-]>>>>>-<<<[>>>+[>+>+<<-]>[<<.>>-]>[<<+>>-]<<<<<<.+>>.<-]

Try It Online!

I'm new to golfing and I know this is extremely golfable but I just learned brainfuck and wanted to see if I could actually do something with it, so I'm sorry that this isn't an impressive answer.

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

Add++, 1069 bytes

+97
&
-87
&
+22
&
+66
&
-88
&
+22
&
&
+67
&
-89
&
+22
&
&
&
+68
&
-90
&
+22
&
&
&
&
+69
&
-91
&
+22
&
&
&
&
&
+70
&
-92
&
+22
&
&
&
&
&
&
+71
&
-93
&
+22
&
&
&
&
&
&
&
+72
&
-94
&
+22
&
&
&
&
&
&
&
&
+73
&
-95
&
+22
&
&
&
&
&
&
&
&
&
+74
&
-96
&
+22
&
&
&
&
&
&
&
&
&
&
+75
&
-97
&
+22
&
&
&
&
&
&
&
&
&
&
&
+76
&
-98
&
+22
&
&
&
&
&
&
&
&
&
&
&
&
+77
&
-99
&
+22
&
&
&
&
&
&
&
&
&
&
&
&
&
+78
&
-100
&
+22
&
&
&
&
&
&
&
&
&
&
&
&
&
&
+79
&
-101
&
+22
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
+80
&
-102
&
+22
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
+81
&
-103
&
+22
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
+82
&
-104
&
+22
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
+83
&
-105
&
+22
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
+84
&
-106
&
+22
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
+85
&
-107
&
+22
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
+86
&
-108
&
+22
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
+87
&
-109
&
+22
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
+88
&
-110
&
+22
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
+89
&
-111
&
+22
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
&
+90
&
P

Try it online!

Yep. That is hardcoded. I'm sure there is a better way, and if you want to find it, go ahead, but this way seems to work the best as Add++ is difficult to work with memory.

\$\endgroup\$
2
  • \$\begingroup\$ The TIO link does not work (interpreter says Fatal error: InvalidSyntaxError line 2: '&' InvalidSyntax) \$\endgroup\$
    – astroide
    Commented Jul 29, 2021 at 16:20
  • \$\begingroup\$ @astroide This was written in Add++ v0.1, and so no longer works (or is the shortest) in the current version. To run it as it was: Try it online! Thanks for reminding me about this post tho, I'll update it at some point \$\endgroup\$ Commented Jul 29, 2021 at 16:21
4
\$\begingroup\$

R, 59 49 47 bytes

-10 bytes thanks to djhurio

-2 bytes thanks to Sven Hohenstein

write("diag<-"(matrix("",26,26),letters),"",26)

Prints to stdout. Outgolfed by user2390246

Try it online!

\$\endgroup\$
11
  • \$\begingroup\$ You can replace 26^2 with 676 to save a byte. \$\endgroup\$
    – Doorknob
    Commented Jun 8, 2017 at 2:57
  • 2
    \$\begingroup\$ m=matrix("",26,26);diag(m)=letters;write(m,'',26) (49 bytes) \$\endgroup\$
    – djhurio
    Commented Jun 8, 2017 at 7:20
  • \$\begingroup\$ For the same amount of bytes, you can print the matrix using cat(m,fill=27) \$\endgroup\$
    – JAD
    Commented Jun 8, 2017 at 7:56
  • 1
    \$\begingroup\$ @djhurio "For the same amount of bytes" \$\endgroup\$
    – JAD
    Commented Jun 8, 2017 at 10:21
  • 1
    \$\begingroup\$ @Giuseppe The command "diag<-"(x, y) is similar to diag(x) <- y. The value is not assigned to a variable but returned. \$\endgroup\$ Commented Jun 8, 2017 at 14:46
4
\$\begingroup\$

><>, 46 44 42 bytes

"A"0::?!v" "o1-40.
*(?!;30.>~$:oao1+$1+:d2

Try it online!

Explanation

Line 1:
"a"0::?!v" "o1-40.
"a"0                       :Initialize the stack items (print char and space count)
    ::?!v                  :Duplicate the space count, check if 0, go down if 0
         " "o1-            :Print a space then take 1 from the space count
               40.         :Jump to codepoint row 0 col 4 (this restarts the loop)
Line 2:
*(?!;30.>~$:oao1+$1+:d2
        >~                 :Remove the zeroed space counter off the stack
          $:oao1+          :Place our print char on the top of the stack, duplicate and print it, print a new line, increase it by 1; a->b->c etc
                 $1+       :Place our space count on the top of the stack and increase it by 1
*                   :d2    :Duplicate the space counter, add 26 to the stack
 (?!;                      :Add 0 to the stack, less than compare 0, if the counter is above 0 it terminates
     30.                   :Jump to the first line, (back to printing spaces)

This is a completely different take from my previous 46 bytes so I've included the TIO to the only one as well. 46 bytes Try it online!

Below is a link to Emigna's submissions, it was the first ><> answer but I believe mine is different enough (and saves a few bytes) to warrant a second one.

Emigna's answer

\$\endgroup\$
2
  • \$\begingroup\$ And now we're tied. Best if you golf off a byte or two to be sure ;) \$\endgroup\$
    – Emigna
    Commented Jun 8, 2017 at 13:12
  • \$\begingroup\$ @Emigna, I thought 3 saved bytes would be enough :o guess I have some more work to do :) \$\endgroup\$ Commented Jun 8, 2017 at 13:31
4
\$\begingroup\$

Haskell, 66 65 58 57 45 43 bytes

Thanks to @nimi and @maple_shaft for saving 12 14 bytes.

unlines[(' '<$['b'..n])++[n]|n<-['a'..'z']]

Try it online!

\$\endgroup\$
4
  • 1
    \$\begingroup\$ You would get the same score but sometimes you can use <$ instead of replicate: (' '<$[1..(fromEnum n-97)]) \$\endgroup\$ Commented Jun 8, 2017 at 17:02
  • 2
    \$\begingroup\$ You can change @maple_shaft's suggestion to (' '<$['b'..n]). \$\endgroup\$
    – nimi
    Commented Jun 8, 2017 at 17:36
  • \$\begingroup\$ As unnamed functions are allowed, there's no need for the f=. \$\endgroup\$
    – nimi
    Commented Jun 8, 2017 at 17:52
  • 2
    \$\begingroup\$ Btw, same byte count: ['a'..'z']>>= \n->(' '<$['b'..n])++[n,'\n']. \$\endgroup\$
    – nimi
    Commented Jun 8, 2017 at 17:59
4
\$\begingroup\$

PHP, 23 bytes

Note: uses IBM-850 encoding.

<?=join(~¶,range(a,z));

Run like this:

echo '<?=join(~¶,range(a,z));' | php -n;echo
# With default (utf8) terminal:
echo '<?=join("\v",range(a,z));' | php -n;echo

Explanation

Create an array of all characters of the alphabet, join it with a vertical tab as glue.

\$\endgroup\$
1
2 3 4 5 6

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.