| Bytes | Lang | Time | Link |
|---|---|---|---|
| 049 | AWK | 250905T164618Z | xrs |
| 015 | Pyth | 170819T021749Z | Stan Str |
| 014 | MATL | 170819T124701Z | Suever |
| 057 | Python 3 | 220602T050609Z | Sapherey |
| 009 | Vyxal j | 220602T010840Z | naffetS |
| 101 | Python 3 | 211209T184232Z | Alan Bag |
| 053 | Forth gforth | 201110T152312Z | Razetime |
| 009 | 05AB1E | 201110T150325Z | Kevin Cr |
| 009 | Japt R | 201110T124756Z | Shaggy |
| 056 | Python 2 | 170819T020336Z | The Fift |
| 107 | SNOBOL4 CSNOBOL4 | 171219T144901Z | Giuseppe |
| 050 | Excel VBA | 170820T172501Z | Taylor R |
| 051 | VBA Excel | 171110T101729Z | remoel |
| 067 | PHP | 171110T071558Z | Jo. |
| 145 | Elixir | 171110T062253Z | Shashidh |
| 068 | Retina | 170819T102003Z | Neil |
| 070 | SimpleTemplate | 170820T123707Z | Ismael M |
| 050 | Bash | 170823T202127Z | Justin M |
| 006 | Pyke | 170823T135331Z | Blue |
| 060 | PowerShell | 170821T134206Z | AdmBorkB |
| 048 | Röda | 170823T092957Z | fergusq |
| 036 | Perl 5 | 170819T132519Z | Dom Hast |
| 039 | Perl 5 | 170819T040850Z | Xcali |
| 011 | APL Dyalog | 170821T112314Z | Adá |
| 012 | Gaia | 170819T125109Z | Business |
| 098 | Java 1.8 without Lambda | 170819T142636Z | Douglas |
| 098 | Brainbash | 170821T112230Z | Conor O& |
| 089 | R | 170820T171424Z | SlowLori |
| 069 | Java OpenJDK 8 | 170820T224258Z | Olivier |
| 054 | Haskell | 170820T174822Z | nimi |
| 031 | q/kdb+ | 170819T180035Z | mkst |
| 009 | Charcoal | 170819T020748Z | notjagan |
| 043 | Ruby | 170819T022437Z | m-chrzan |
| 013 | Japt | 170819T020720Z | ETHprodu |
| 512 | ><> v | 170819T153302Z | Sasha |
| 060 | Haskell | 170819T132852Z | Cristian |
| 012 | Pyth | 170819T072133Z | Mr. Xcod |
| 6618 | C# .NET Core | 170819T100916Z | Grzegorz |
| 040 | Proton | 170819T082251Z | Mr. Xcod |
| 052 | Python | 170819T070025Z | Mr. Xcod |
| 084 | Common Lisp | 170819T055130Z | Renzo |
| 011 | 05AB1E | 170819T041655Z | Justin M |
| 050 | C gcc | 170819T050845Z | Justin M |
| 052 | Python 3 | 170819T050637Z | Leaky Nu |
| 011 | Jelly | 170819T045550Z | Leaky Nu |
| 012 | SOGL V0.12 | 170819T034524Z | dzaima |
| 052 | Python 2 | 170819T030844Z | totallyh |
| 067 | Mathematica | 170819T030012Z | JungHwan |
| 066 | JavaScript ES2017 | 170819T021400Z | ETHprodu |
| 072 | JavaScript Node.js | 170819T023729Z | Conor O& |
| 103 | Mathematica | 170819T021424Z | ZaMoC |
| 057 | Python 2 | 170819T020636Z | Stephen |
Pyth, 21 17 15 bytes
VlG+*d?>QNNQ@GN
Explanation:
VlG For each character in the alphabet (G)
+ Concatenate...
*d Space (d) times...
?>QNNQ Ternary; if Q (input) is less than N, return N, else Q
@GN The Nth character of the alphabet (G)
MATL, 14 bytes
26:tiXl2Y2oZ?c
Try it at MATL Online
Explanation
26 % number literal
: % range; vector of equally spaced values [1...26]
t % duplicate
i % explicitly grab the input
Xl % clamp the array to have a maximum value of the input
2Y2 % predefined literal: ['a'...'z']
o % convert to a numeric array
Z? % create sparse matrix using the first two inputs as the rows/columns
% and the letters 'a'...'z' as the values
c % convert back to character and implicitly display
Python 3, 57 bytes
lambda n:[f"{chr(65+i):>{min(i+1,n)}}"for i in range(26)]
Used python formatting to automatically put spaces in output i.e. {'a':>5} will give a
Python 3, 101 bytes
def f(n,a=0):
b="abcdefghijklmnopqrstuvwxyz"
for l in range(len(b)):print(" "*a,b[l]);a+=[0,1][l<n]
Forth (gforth), 53 bytes
: f 1- 26. do dup i min spaces i 97 + emit cr loop ;
Pretty standard answer.
05AB1E, 9 bytes
27α‚A34SΛ
A golfed version of the existing 05AB1E answer in the new 05AB1E version is 9 bytes as well:
Av<N‚ßyú,
Explanation:
27α # Take the absolute difference of 27 with the (implicit) input
‚ # Pair it to the (implicit) input
A # Push the lowercase alphabet
34S # Push 34 as a list of digits: [3,4]
Λ # Use the Canvas builtin with these three as arguments:
# Direction [3,4], which translates to [↘,↓]
# Characters to draw: the lowercase alphabet
# Length of each part to draw: [input,|input-27|]
# (after which the result is output immediately afterwards)
See this 05AB1E tip of mine for an in-depth explanation of how the canvas builtin works.
A # Push the lowercase alphabet
v # Pop and loop over each of its characters `y`:
< # Decrease the (implicit) input by 1
N‚ # Pair it with the 0-based loop index
ß # Pop and push the minimum of this pair
y # Push the current character
ú # Pop both, and pad the character with leading spaces equal to the integer
, # Pop and print this string with trailing newline
Japt -R, 9 bytes
;C¬ËùUm°E
;C¬ËùUm°E :Implicit input of integer U
;C :Lowercase alphabet
¬ :Split
Ë :Map each character at 0-based index E
ù :Left pad with spaces to length
Um : Minimum of U and
°E : E incremented
:Implicit output joined with newlines
Python 2, 61 58 57 56 bytes
def f(i,j=0):exec"print(' '*~-i)[:j]+chr(97+j);j+=1;"*26
-3 bytes thanks to Rod
-2 more bytes thanks to Mr. Xcoder
SNOBOL4 (CSNOBOL4), 107 bytes
N =INPUT
I &LCASE POS(R) LEN(1) . L
OUTPUT =DUPL(' ',X) L
R =R + 1
X =LT(R,N) X + 1
LT(R,26) :S(I)
END
Excel VBA, 53 50 Bytes
Anonymous VBE immediate window function that takes input of expected type Integer in the domain of [1,26] from range [A1] and outputs to the VBE immediate window
For i=0To 25:[B1]=i:?Spc([Min(1:1)])Chr(97+i):Next
VBA Excel, 51 bytes
using Immediate Window and [a1] as input
for x=1to 26:?spc(iif(x<[a1],x,[a1]))chr(96+x):next
Elixir, 145 bytes
{n,_}=IO.gets("")|>Integer.parse;for x<-?a..?z,do: if x-97<n,do: IO.puts String.pad_leading(<<x>>,x-96),else: IO.puts String.pad_leading(<<x>>,n)
Retina, 72 68 bytes
^
z
{2=`
$`
}T`l`_l`^.
\D
$.`$* $&¶
\d+
$*
s`( *)( +)(?=.*¶\1 $)
$1
Try it online! Output includes trailing whitespace. Save 1 byte by deleting the space before the $ if zero-indexing is allowed. Edit: Saved 4 bytes by using @MartinEnder's alphabet generator. Explanation:
^
z
{2=`
$`
}T`l`_l`^.
Insert the alphabet.
\D
$.`$* $&¶
Diagonalise it.
\d+
$*
Convert the input to unary as spaces.
s`( *)( +)(?=.*¶\1 $)
$1
Trim overlong lines so that no line is longer than the blank line at the end.
SimpleTemplate, 79 70 bytes
The code outputs the required text and a trailing newline.
{@forfrom"a"to"z"}{@echols,_}{@inca}{@ifa is lowerargv.0}{@sets s," "}
Ungolfed:
{@for letter from "a" to "z"}
{@echo spaces, letter, EOL} {@// same as echol}
{@inc by 1 index} {@// sets to 1 if it doesn't exist}
{@if index is lower than argv.0}
{@// creates an array like [[[...], " "], " "]}
{@set spaces spaces, " "}
{@/} {@//not required}
{@/} {@// not required}
You can try it on http://sandbox.onlinephpfunctions.com/code/a0ee99464f463d23072ff5d5be7dbd3a532f9c7c
(Old version: http://sandbox.onlinephpfunctions.com/code/a60e11b9dd2dcd54a84c11937f1918f26e0adcfa)
Bash, 50 bytes
for c in {A..Z};{ printf "%$[++i<$1?i:$1]s\n" $c;}
Takes input as a command-line argument.
Pyke, 6 bytes
G\xb1oh->
- o = 0
G - alphabet
\xb1 - for i in ^: (1 byte, pretty prints)
oh - (o++)+1
- - " "*^ + i
> - ^[input:]
PowerShell, 66 60 bytes
param($a)65..90|%{" "*(($b=$_-65),($a-1))[$b-ge$a]+[char]$_}
Loops through the alphabet, each iteration using string multiplication to prepend the appropriate number of spaces (chosen using a pesudo-ternary (,)[]), then string-concatenates with the current character.
Röda, 48 bytes
f n{seq 1,26|min([n,_])<>chr 96+_1|print" "*_,_}
Each output line has one leading space.
Explanation:
f n{
seq 1,26| /* push numbers 1..26 to the stream (inclusive) */
/* for each number in the stream: */
min([n,_])<> /* push min(n, _1) */
chr 96+_1| /* push string containing _1 as a letter */
/* for each number _1 and letter _2 in the stream: */
print" "*_,_ /* print _1 spaces and _2 */
}
Perl 5, 36 bytes
31 bytes code + 5 for -i# -l.
Note: this takes input via -i, if that is unacceptable (since it's non-standard) I can remove.
$\.=$"x(--$^I>0),print for a..z
Explanation
For this I'm abusing the special variable $\ which is automatically printed after each call to print, to store the next line's indentation. Using the flag -l (which enables line ending processing), $\ is pre-initialised to "\n" so we append a space each time we process an element in the range a..z, as long as --$^I isn't less than 0. Using $^I (via the -i commandline flag) means I don't need to store input separately, but it's bit of a stretch as its not the usual way to accept input in Perl. Since the postfix for loop stores the current item in $_, we don't need any arguments to print ($_ is automatically printed and $\ is automatically appended) so we just call it each iteration, appending spaces as we go to get the desired output. This does append trailing spaces though, which @SpookyGengar has allowed.
Thanks to @Xcali for pointing out an oversight!
APL (Dyalog), 12 11 bytes
-1 as OP has now clarified that returning a list of strings is fine.
Prompts for input.
⎕A↑¨⍨-⎕⌊⍳26
⍳26 first 26 strictly positive ɩntegers
⎕⌊ minimum of input and those
- negate those
⎕A↑⍨¨ for each letter of the Alphabet, take that many characters (from the rear, as all numbers are negative), padding with spaces as necessary
↑ convert list of strings into matrix (only in TIO link to enable readable output)
Gaia, 12 bytes
…26⊃§×¦₵a+†ṣ
Explanation
… Range 0..input-1
26⊃ Repeat the last number enough times to make it have length 26
§×¦ Turn each number into a string of that many spaces
₵a+† Add the corresponding letter to each
ṣ Join with newlines
Java 1.8 (without Lambda), 98 Bytes
void m(int i){int c=0,o=97;String s="";for(;c++<26;s+=c<i?" ":"")System.out.println(s+(char)o++);}
The logic is straightforward. Provides no input data validation, very bad!
- Update: Function only! Thank you to @Olivier Grégoire
Brainbash, 98 bytes
+[-[---<]>>-]<-~++++++++[>++++>+++>+<<<-]>>++>++>#-<<[>>>[-<<<<.>>>>>+<]>[-<+>]<<{->+<}<<-~.+~>.<]
Explanation
The code can be split into two parts:
+[-[---<]>>-]<-~++++++++[>++++>+++>+<<<-]>>++>++>#
-<<[>>>[-<<<<.>>>>>+<]>[-<+>]<<{->+<}<<-~.+~>.<]
Basically, generate the constants 97, 32, and 26. Then, takes a number N as input. After input (#) the tape looks like:
[ ] 0 0 >97 0
[*] 0 32 26 10 >0
The second part executes 26 times, each time decrementing the input. Every time the input is decremented, the prefix length is incremented. After the input reaches zero, the prefix length remain constant. After each loop, the spaces, the letter, and a newline are printed.
R, 99 89 bytes
@MickeyT saved 10 bytes
function
function(x)for(i in 1:26)cat(paste(c(rep(" ",min(x,i)),letters[i]),collapse=""),sep="\n")
demo
f <- function(x)for(i in 1:26)cat(paste(c(rep(" ",min(x,i)),letters[i]),collapse=""),sep="\n")
f(1)
f(10)
f(15)
f(26)
Java (OpenJDK 8), 69 bytes
n->{for(int a=0;a++<26;)System.out.printf("%"+(a<n?a:n)+"c%n",a+96);}
Haskell, 58 54 bytes
f n=do m<-[1..26];([2..min n m]>>" ")++['`'..]!!m:"\n"
How it works
f n= -- input number is n
do m<-[1..26] -- for each m from [1..26], construct a string and concatenate
-- them into a single string. The string is:
[2..min n m]>>" " -- min(n,m)-1 spaces,
++ -- followed by
['`'..]!!m -- the m-th char after `
: -- followed by
"\n" -- a newline
Edit: @Lynn saved 4 bytes. Thanks!
q/kdb+, 33 31 bytes
Solution:
-1{(&[x-1;til 26]#'" "),'.Q.a};
Example:
q)-1{(&[x-1;til 26]#'" "),'.Q.a}16;
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
Explanation:
Create a list of spaces (26) up to the length of the minimum of the input and the range of 0..25), join with each letter of the alphabet, print to stdout.
-1{(&[x-1;til 26]#'" "),'.Q.a}; / solution
-1 ; / print result to stdout and swallow return
{ } / lambda function
.Q.a / "abcd..xyz"
,' / concatenate (,) each
( ) / do all this together
&[ ; ] / minimum of each
x-1 / implicit input (e.g. 10) minus 1 (e.g. 9)
til 26 / 0 1 2 ... 23 24 25
'#" " / take " " each number of times (0 1 2 )
Notes:
- -2 bytes by rejigging the brackets
Charcoal, 9 bytes
↘✂β⁰N↓✂βη
How it works
↘✂β⁰N↓✂βη
✂β⁰N the alphabet from position 0 to the input
↘ print diagonally, down and to the right
✂βη the alphabet starting from the position of the input
↓ print downwards
This solution no longer works in the current version of Charcoal (most likely due to a bug fix), but the issue is resolved for 10 bytes with ↘✂β⁰N↓✂βIθ.
Ruby, 51 46 43 bytes
->n{(0..25).map{|x|(' '*x)[0,n-1]<<(x+97)}}
Returns a list of strings.
Looks like the Python guys were on to something with their subscripts. -5 bytes by taking inspiration from Mr. Xcoder's improvement of ppperry's solution.
Previous solution with rjust (51 bytes):
->n{i=0;(?a..?z).map{|c|c.rjust i+=n>c.ord-97?1:0}}
><> (-v), 51+2 Bytes
'a'$1-0\ /' 'o1-81.
'z')?;}>::?/~$:@@:@)+{:oao1+:
equivalent pseudo code
char = 'a'
input = read_number
input -= 1
tabCount = 0
while true
for i from 0 to tabCount
print ' '
if tabCount < input
++tabCount
print char
print '\n'
++char
if char > 'z'
exit
Haskell, 60 bytes
f n=unlines$scanl(\p c->take(n-1)(p>>" ")++[c])"a"['b'..'z']
This is a function that returns the output as a String.
Pyth, 12 bytes
j.e+<*kdtQbG
If lists of Strings are allowed, this can be shortened to 11 bytes:
.e+<*kdtQbG
Pyth, 12 bytes
VG+<*dxGNtQN
Pyth, 14 bytes
jm+<*d;tQ@Gd26
If lists of Strings are allowed, this can be shortened to 13 bytes:
m+<*d;tQ@Gd26
How do these work?
Unlike most of the other answers, this maps / loops over the lowercase alphabet in all 3 solutions.
Explanation #1
j.e+<*kdtQbG - Full program.
.e G - Enumerated map over "abcdefghijklmnopqrstuvwxyz", with indexes k and values b.
*kd - Repeat a space a number of times equal to the letter's index.
< tQ - Crop the spaces after the input.
+ b - Concatenate with the letter.
j - (Optional): Join by newlines.
Explanation #2
VG+<*dxGNtQN - Full program.
VG - For N in "abcdefghijklmnopqrstuvwxyz".
xGN - Index of the letter in the alphabet.
*d - Repeat the space a number of times equal to the index above.
< tQ - But crop anything higher than the input.
+ N - Append the letter (at the end)
Explanation #3
jm+<*d;tQ@Gd26 - Full program.
m 26 - Map over [0...26) with a variable d.
*d; - Space repeated d times.
< tQ - Crop anything whose length is higher than the input.
+ @Gd - Concatenate with the letter at that index in the alphabet.
j - (Optional): Join by newlines.
C# (.NET Core), 66 + 18 bytes
n=>new int[26].Select((x,i)=>$"{(char)(i+97)}".PadLeft(i<n?i+1:n))
Byte count also includes
using System.Linq;
This returns a collection of strings, one for each line. If it's not allowed, the answer will swell by 17 bytes for string.Concat() and \n inside string
Explanation:
n =>
new int[26] // Create a new collection of size 26
.Select((x, i) => // Replace its members with:
$"{(char)(i + 97)}" // String of an alphabet character corresponding to the index
.PadLeft(i < n ? i + 1 : n) // Add spaces to the left
)
Proton, 40 bytes
Assuming that a list of Strings is fine.
k=>[(i*" ")[to~-k]+chr(i+97)for i:0..26]
Proton, 49 bytes
As ASCII-art instead:
k=>'\n'.join((i*" ")[to~-k]+chr(i+97)for i:0..26)
Python, 52 bytes
Quite surprised nobody noticed the obvious approach was also as short as the others.
lambda k:[(i*" ")[:k-1]+chr(i+97)for i in range(26)]
Python, 53 bytes
lambda k:[min(k-1,i)*" "+chr(i+97)for i in range(26)]
Common Lisp, 84 bytes
(lambda(x)(dotimes(i 26)(format t"~v,,,@a~%"(if(< i x)(1+ i)x)(code-char(+ i 97)))))
05AB1E, 11 bytes
AvNI<‚Wysú,
First time trying 05AB1E, so I'm open to tips.
If a zero-indexed input from 0 to 25 is allowed, this can be 10 bytes by omitting the <.
Python 2, 52 bytes
lambda n:['%*c'%(min(i+1,n),i+97)for i in range(26)]
I'm assuming a list of strings is fine...
Shortest I could get with recursion:
f=lambda n,i=0:i<26and['%*c'%(min(i+1,n),i+97)]+f(n,i+1)or[]
Mathematica, 67 bytes
SparseArray[x=#;{#,#~Min~x}->Alphabet[][[#]]&~Array~26,{26,#}," "]&
Returns a SparseArray of strings. To visualize, append Grid@ in front.
Usage
Grid@SparseArray[x=#;{#,#~Min~x}->Alphabet[][[#]]&~Array~26,{26,#}," "]&[5]
a b c d e f g ⋮ z
JavaScript (ES2017), 73 72 71 66 bytes
Saved some bytes thanks to @JustinMariner
f=(n,x=26)=>x?f(n,x-1)+(x+9).toString(36).padStart(x<n?x:n)+`
`:''
JavaScript (Node.js), 72 bytes
n=>[..."abcdefghijklmnopqrstuvwxyz"].map((e,i)=>" ".repeat(i<n?i:n-1)+e)
Returns a list of strings.
Mathematica, 103 bytes
(T=Table;a=Alphabet[];c=Column)[c/@{T[""<>{T[" ",i],a[[i]]},{i,#}],T[""<>{T[" ",#],a[[i]]},{i,#,26}]}]&
Python 2, 62 50 57 bytes
x=input();n=m=1
exec"print'%*c'%(m,n+96);n+=1;m+=x>m;"*26
Steals heavily from this answer by Dennis.