Diagonal Alphabet To the Input

26

Inspired by this post. For those marking this question as a duplicate I urge you to actually read the question to see that mine is a modification of the one linked. The one linked does not ask for an input and is to just print the alphabet diagonally.

The Challenge

Given an input between 1-26 inclusively, print the alphabet diagonally, but begin printing vertically at the index of the given input.

Examples

Given the input:

16

Your program should output:

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

Input:

4

Output:

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

Input:

1

Output:

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

Input:

26

Output:

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

Scoring

This is , so the shortest answer in each language wins.

Good luck!

SpookyGengar

Posted 2017-08-19T01:58:31.023

Reputation: 1 617

6May we choose to use either 0- or 1-indexing? – notjagan – 2017-08-19T03:45:51.860

Is a consistent leading space acceptable? – Giuseppe – 2017-08-19T06:26:50.473

Are trailing spaces acceptable? – Dom Hastings – 2017-08-19T13:20:39.367

May we use uppercase? – Adám – 2017-08-20T22:29:46.283

May we return a list of strings? – Adám – 2017-08-21T11:15:34.797

@Giuseppe sure, no problem! – SpookyGengar – 2017-08-22T17:33:38.420

@DomHastings yes, they are! – SpookyGengar – 2017-08-22T17:34:07.387

@Adám yes to both of your questions! – SpookyGengar – 2017-08-22T17:34:24.000

Answers

13

Charcoal, 9 bytes

↘✂β⁰N↓✂βη

Try it online!

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θ.

notjagan

Posted 2017-08-19T01:58:31.023

Reputation: 4 011

2I'm not sure why that works; it may be a bug that was introduced a couple of weeks ago. (You'd normally have to use Iθ instead of η.) – Neil – 2017-08-19T10:07:38.507

@Neil It seem broken today. Using Iθ solves it. – JP de la Torre – 2017-08-19T21:56:50.280

Save 1 byte by using …βN instead of ✂β⁰N. – Neil – 2017-12-21T15:31:24.950

7

05AB1E, 11 bytes

AvNI<‚Wysú,

First time trying 05AB1E, so I'm open to tips.

Try it online!

If a zero-indexed input from 0 to 25 is allowed, this can be 10 bytes by omitting the <.

Justin Mariner

Posted 2017-08-19T01:58:31.023

Reputation: 4 746

Niiice! Exactly what I got. I tried "lift" but it's not working as planned. I think that's pretty optimal :). – Magic Octopus Urn – 2017-08-22T19:22:48.773

4

Python 2, 61 58 57 bytes

n=input()-1
for i in range(26):print(' '*i)[:n]+chr(i+97)

-3 bytes thanks to Rod

-1 more byte thanks to Mr. Xcoder

pppery

Posted 2017-08-19T01:58:31.023

Reputation: 3 987

1same answer, but with input/print to save few bytes – Rod – 2017-08-19T02:08:24.423

@Pavel That wouldn't work since then input would be called every time the for loop iterates, even though there's only one line of input. – notjagan – 2017-08-19T02:54:05.163

57 bytes using exec – officialaimm – 2017-08-19T02:56:43.853

57 bytes using subscripting. – Mr. Xcoder – 2017-08-19T07:13:33.787

56 bytes – Mr. Xcoder – 2017-08-19T21:57:20.080

4

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)+`
`:''

ETHproductions

Posted 2017-08-19T01:58:31.023

Reputation: 47 880

1

This adds a 10 after z at the end due to having ++x before x.toString(). Bugfixed and golfed to 68 bytes using padStart: TIO

– Justin Mariner – 2017-08-19T02:29:02.657

@JustinMariner Thanks, I think I might switch to ES8 for that... – ETHproductions – 2017-08-19T02:45:42.633

Can you save anything by currying? n=>g=(x=26)=>x?f(x-1)+(x+9).toString(36).padStart(x<n?x:n)+'\n':"" – Shaggy – 2017-08-19T10:07:08.427

@Shaggy Perhaps, I don't know if that type of currying is allowed though. – ETHproductions – 2017-08-19T17:06:17.103

Ah, nuts, looks like your proposal to allow this is no longer a consensus :(

– Shaggy – 2017-08-21T08:59:25.257

4

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}}

m-chrzan

Posted 2017-08-19T01:58:31.023

Reputation: 1 390

3

Python 2, 62 50 57 bytes

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

Try it online!

Steals heavily from this answer by Dennis.

Stephen

Posted 2017-08-19T01:58:31.023

Reputation: 12 293

3

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.

Neil

Posted 2017-08-19T01:58:31.023

Reputation: 95 035

3

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)

Slow loris

Posted 2017-08-19T01:58:31.023

Reputation: 211

1A couple of little savings. Rather then the ifelse try min. print.noquote can be replaced with cat with a '\n' in the paste. The \n can be a straight carriage return. Curly braces for the function body can be dropped. – MickyT – 2017-08-21T00:02:30.617

You can save some more by using write rather than cat and paste: write(c(rep(" ",min(x,i)),letters[i]),"",26,,"") – user2390246 – 2017-08-21T10:18:49.263

2

Mathematica, 103 bytes

(T=Table;a=Alphabet[];c=Column)[c/@{T[""<>{T[" ",i],a[[i]]},{i,#}],T[""<>{T[" ",#],a[[i]]},{i,#,26}]}]&

J42161217

Posted 2017-08-19T01:58:31.023

Reputation: 15 931

2

Pyth, 21 17 15 bytes

Done on a phone with 3% battery.

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)

Try it online!

Stan Strum

Posted 2017-08-19T01:58:31.023

Reputation: 436

1@totallyhuman I just had some amazing pizza in Las Vegas, New Mexico – Stan Strum – 2017-08-19T04:36:09.273

Found some considerably shorter approaches, and I decided to post my own answer.

– Mr. Xcoder – 2017-08-19T08:10:15.750

@Mr.Xcoder Yeah, good job on that. – Stan Strum – 2017-08-19T14:29:41.177

2

Jelly, 11 bytes

26Ḷ«’⁶ẋżØaY

Try it online!

Leaky Nun

Posted 2017-08-19T01:58:31.023

Reputation: 45 011

2

Common Lisp, 84 bytes

(lambda(x)(dotimes(i 26)(format t"~v,,,@a~%"(if(< i x)(1+ i)x)(code-char(+ i 97)))))

Try it online!

Renzo

Posted 2017-08-19T01:58:31.023

Reputation: 2 260

2

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)]

Try it online!

Python, 53 bytes

lambda k:[min(k-1,i)*" "+chr(i+97)for i in range(26)]

Try it online!

Mr. Xcoder

Posted 2017-08-19T01:58:31.023

Reputation: 39 774

2

Gaia, 12 bytes

…26⊃§×¦₵a+†ṣ

Try it online!

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

Business Cat

Posted 2017-08-19T01:58:31.023

Reputation: 8 927

2

Haskell, 58 54 bytes

f n=do m<-[1..26];([2..min n m]>>" ")++['`'..]!!m:"\n"

Try it online!

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!

nimi

Posted 2017-08-19T01:58:31.023

Reputation: 34 639

@Lynn; Thanks! I always forget about do notation for lists. – nimi – 2017-08-20T18:48:11.553

2

Java (OpenJDK 8), 69 bytes

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

Try it online!

Olivier Grégoire

Posted 2017-08-19T01:58:31.023

Reputation: 10 647

1

Japt, 16 13 bytes

Saved 3 bytes thanks to @Oliver

;C£RiXiYmUÉ î

Test it online!

ETHproductions

Posted 2017-08-19T01:58:31.023

Reputation: 47 880

@Oliver Dang, I was tired... – ETHproductions – 2017-08-19T17:04:50.583

1

JavaScript (Node.js), 72 bytes

n=>[..."abcdefghijklmnopqrstuvwxyz"].map((e,i)=>" ".repeat(i<n?i:n-1)+e)

Returns a list of strings.

Try it online!

Conor O'Brien

Posted 2017-08-19T01:58:31.023

Reputation: 36 228

May I ask why node.js? seems like valid normal JS – Downgoat – 2017-08-19T02:47:25.697

@Downgoat It's the TIO auto formatting – Conor O'Brien – 2017-08-19T02:48:01.757

btw you can save bytes using .padStart – Downgoat – 2017-08-19T02:49:36.700

Wait nvm the way I was thinking basically makes it into ETH's answer – Downgoat – 2017-08-19T02:50:53.123

Switch to ES8 and save a byte with padEnd instead of repeat. – Shaggy – 2017-08-19T08:41:21.190

1

Mathematica, 67 bytes

SparseArray[x=#;{#,#~Min~x}->Alphabet[][[#]]&~Array~26,{26,#}," "]&

Returns a SparseArray of strings. To visualize, append Grid@ in front.

Try it on Wolfram Sandbox

Usage

Grid@SparseArray[x=#;{#,#~Min~x}->Alphabet[][[#]]&~Array~26,{26,#}," "]&[5]
a
 b
  c
   d
    e
    f
    g

    ⋮

    z 

JungHwan Min

Posted 2017-08-19T01:58:31.023

Reputation: 13 290

1

Python 2, 52 bytes

lambda n:['%*c'%(min(i+1,n),i+97)for i in range(26)]

Try it online!

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[]

totallyhuman

Posted 2017-08-19T01:58:31.023

Reputation: 15 378

1

SOGL V0.12, 12 bytes

z{ē.-.Hχ@*Ot

Try it Here!

dzaima

Posted 2017-08-19T01:58:31.023

Reputation: 19 048

1

Perl 5, 47 39 bytes

$l=<>;say$"x($#i+=$#i<$l-1).$_ for a..z

Try it online!

Xcali

Posted 2017-08-19T01:58:31.023

Reputation: 7 671

Nuce use of $#i. That might even be worth adding as a separate tip!

– Dom Hastings – 2017-08-23T04:44:16.780

1

Python 3, 52 bytes

lambda n:[('%*c'%(i,i+96))[-n:]for i in range(1,27)]

Try it online!

Leaky Nun

Posted 2017-08-19T01:58:31.023

Reputation: 45 011

1

C (gcc), 50 bytes

i;f(n){for(;i<26;printf("%*c\n",i++<n?i:n,i+97));}

Try it online!

Justin Mariner

Posted 2017-08-19T01:58:31.023

Reputation: 4 746

1

Pyth, 12 bytes

j.e+<*kdtQbG

Try it here!

If lists of Strings are allowed, this can be shortened to 11 bytes:

.e+<*kdtQbG

Pyth, 12 bytes

VG+<*dxGNtQN

Try it here!

Pyth, 14 bytes

jm+<*d;tQ@Gd26

Try it here.

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.

Mr. Xcoder

Posted 2017-08-19T01:58:31.023

Reputation: 39 774

1

Proton, 40 bytes

Assuming that a list of Strings is fine.

k=>[(i*" ")[to~-k]+chr(i+97)for i:0..26]

Try it online!

Proton, 49 bytes

As ASCII-art instead:

k=>'\n'.join((i*" ")[to~-k]+chr(i+97)for i:0..26)

Try it online!

Mr. Xcoder

Posted 2017-08-19T01:58:31.023

Reputation: 39 774

1

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;

Try it online!

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
    )

Grzegorz Puławski

Posted 2017-08-19T01:58:31.023

Reputation: 781

1

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

Suever

Posted 2017-08-19T01:58:31.023

Reputation: 10 257

1

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

Try it online!

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!

Dom Hastings

Posted 2017-08-19T01:58:31.023

Reputation: 16 415

Are you off by one here? Based on the examples, it looks like an input of 4 should have d and e vertically aligned. – Xcali – 2017-08-22T22:53:07.850

@Xcali Oops! Yeah! Change to pre-decrement instead, thank you! – Dom Hastings – 2017-08-23T04:41:31.453

1

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.

Try it online.

Cristian Lupascu

Posted 2017-08-19T01:58:31.023

Reputation: 8 369

1

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

Douglas Held

Posted 2017-08-19T01:58:31.023

Reputation: 111

1To spare some bytes, use for(;c++<26;s+=c<i?" ":"")System.out.println(s+(char)o++); Also, you can write only a function, or a lambda instead of a full program. – Olivier Grégoire – 2017-08-20T23:18:43.520

If I were to include only the body of a function, then how would the reader know what a[0] refers to? I think snippets are not fair if they do not compile; the challenge is just as interesting with a language rich in constructs. – Douglas Held – 2017-08-21T16:10:56.070

1

Hello! I did say a function or a lambda, not a snippet. ;-) So you can write void f(int i){...} (no static needed) or i->{...} instead of your whole program. See all Java tips. See my answer for this same challenge, as example. Have fun on the site! :-)

– Olivier Grégoire – 2017-08-21T18:31:00.407

1

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

streetster

Posted 2017-08-19T01:58:31.023

Reputation: 3 635

1

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)

Ismael Miguel

Posted 2017-08-19T01:58:31.023

Reputation: 6 797

1

APL (Dyalog), 12 11 bytes

-1 as OP has now clarified that returning a list of strings is fine.

Prompts for input.

⎕A↑¨⍨-⎕⌊⍳26

Try it online!

⍳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)

Adám

Posted 2017-08-19T01:58:31.023

Reputation: 37 779

1

PowerShell, 66 60 bytes

param($a)65..90|%{" "*(($b=$_-65),($a-1))[$b-ge$a]+[char]$_}

Try it online!

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.

AdmBorkBork

Posted 2017-08-19T01:58:31.023

Reputation: 41 581

1

Pyke, 6 bytes

G\xb1oh->

Try it here!

          - o = 0
G         -  alphabet
 \xb1     - for i in ^: (1 byte, pretty prints)
     oh   -    (o++)+1
       -  -   " "*^ + i
        > -  ^[input:]

Blue

Posted 2017-08-19T01:58:31.023

Reputation: 26 661

0

><> (-v), 51+2 Bytes

'a'$1-0\   /' 'o1-81.
'z')?;}>::?/~$:@@:@)+{:oao1+:

Try it online

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

Sasha

Posted 2017-08-19T01:58:31.023

Reputation: 431

0

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

Taylor Scott

Posted 2017-08-19T01:58:31.023

Reputation: 6 709

0

Brainbash, 98 bytes

+[-[---<]>>-]<-~++++++++[>++++>+++>+<<<-]>>++>++>#-<<[>>>[-<<<<.>>>>>+<]>[-<+>]<<{->+<}<<-~.+~>.<]

Try it online!

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.

Conor O'Brien

Posted 2017-08-19T01:58:31.023

Reputation: 36 228

0

Röda, 48 bytes

f n{seq 1,26|min([n,_])<>chr 96+_1|print" "*_,_}

Try it online!

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 */
}

fergusq

Posted 2017-08-19T01:58:31.023

Reputation: 4 867

0

Bash, 50 bytes

for c in {A..Z};{ printf "%$[++i<$1?i:$1]s\n" $c;}

Try it online!

Takes input as a command-line argument.

Justin Mariner

Posted 2017-08-19T01:58:31.023

Reputation: 4 746

0

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)

Try online

Shashidhar Mayannavar

Posted 2017-08-19T01:58:31.023

Reputation: 121

0

PHP, 67 bytes

<?for($l=a;$l!=aa;)echo str_pad($l++,min($argv[1],++$x)," ",0)."
";

Try it online!

Jo.

Posted 2017-08-19T01:58:31.023

Reputation: 974

0

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

remoel

Posted 2017-08-19T01:58:31.023

Reputation: 511

0

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

Try it online!

Giuseppe

Posted 2017-08-19T01:58:31.023

Reputation: 21 077