Semi-Diagonal Alphabet

35

3

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.

user70974

Posted 2017-08-23T14:21:56.990

Reputation:

Is output as list of strings ok? – Adám – 2017-08-23T15:16:53.067

It says under the rules that a list of lines is ok. I would assume this would mean yes @Adám – jkelm – 2017-08-23T15:19:33.067

Ah, I can't read. – Adám – 2017-08-23T15:20:23.767

2Why the downvote? What can i improve? – None – 2017-08-23T15:45:53.993

1When you say "P is 1-indexed here", does here refer to the challenge or the example? – Dave – 2017-08-23T15:48:39.610

@pizzakingme The example, of course. P has no relevance overall – Mr. Xcoder – 2017-08-23T15:49:36.423

To rephrase, can we index from 0 and exclude the inputted character from the output? – Dave – 2017-08-23T16:00:59.717

3@pizzakingme No, you may not. – None – 2017-08-23T16:05:08.267

1

I accidentlly got an interesting pattern while golfing my answer: https://tio.run/##K0nO@f@/OLVEIVGhupYLxMhUMDPlKsnMTVWohohHp@UX5SaWKMQoqCYrqGTGqiRaF5SWFMPFVaNTKwqKQDLFCiqJsdaZeclFCpm1CkZm//8DAA

– sergiol – 2017-10-19T19:19:52.177

Answers

10

Python 3, 59 bytes

lambda l:[' '*i+'%c '%(i+65)*-~i for i in range(ord(l)-64)]

Try it online!

Python 3, 61 bytes

lambda l:[' '*i+-~i*(chr(i+65)+' ')for i in range(ord(l)-64)]

Try it online! (link to pretty-print version)

Mr. Xcoder

Posted 2017-08-23T14:21:56.990

Reputation: 39 774

8I see absolutely no reason for a downvote. Can the @downvoter explain? – Mr. Xcoder – 2017-08-23T14:59:02.763

1I'd imagine it's just a misclick, or perhaps someone not liking a lack of explanation (the latter is quite unlikely IMO) – Conor O'Brien – 2017-08-23T19:14:42.880

I dislike Python and I can't implement with Python, so the answer is not useful for me? Just kidding, but the button tooltips probably do not fit the rules of this site – Thomas Weller – 2017-08-25T12:20:31.897

Is it just me or does it say Mr. Xcoder has 1 rep...? – Stan Strum – 2017-09-25T02:34:50.407

9

Python 2, 63 61 59 bytes

-2 bytes thanks to Rod. -2 bytes thanks to Felipe Nardi Batista.

i=1
exec"print' '*i+'%c '%(i+64)*i;i+=1;"*(ord(input())-64)

Try it online!

totallyhuman

Posted 2017-08-23T14:21:56.990

Reputation: 15 378

8

C, 89 bytes

i,j;f(l){for(i=64;i++<l&&printf("%*c ",i-64,i);puts(""))for(j=i-65;j--;)printf("%c ",i);}

Try it online!

Steadybox

Posted 2017-08-23T14:21:56.990

Reputation: 15 798

7

PowerShell, 45 42 bytes

65..$args[0]|%{" "*$i+++"$([char]$_) "*$i}

Try it online!

Takes input as a literal char, then loops up through the capitals to that point, each iteration prepending the appropriate number of spaces and then the char\space hybrid.

Saved 3 bytes thanks to TessellatingHeckler.

AdmBorkBork

Posted 2017-08-23T14:21:56.990

Reputation: 41 581

@TessellatingHeckler Indeed. I've been golfing that to "$args" so much, which wouldn't work here, I forgot about the [0] method. Haha. – AdmBorkBork – 2017-08-25T12:22:37.557

5

JavaScript (ES6), 85 bytes

Works in lower case for both input and output. Outputs a leading space and a trailing space on each line.

f=(c,k=10,C=k.toString(36),r=s=>`${s} `.repeat(k-9))=>r``+r(C)+(C==c?'':`
`+f(c,k+1))

Demo

f=(c,k=10,C=k.toString(36),r=s=>`${s} `.repeat(k-9))=>r``+r(C)+(C==c?'':`
`+f(c,k+1))

O.innerText = f('m')
<pre id=O>

Arnauld

Posted 2017-08-23T14:21:56.990

Reputation: 111 334

\${s} `` can be replaced by (s+"") for one byte saving – Luke – 2017-08-24T07:07:19.347

@Luke I need this space. It can be replaced by (s+" "), but that's just as long. – Arnauld – 2017-08-24T09:18:48.030

5

APL (Dyalog), 26 bytes

Prompts for scalar character. Prints list of lines.

(∊⍴∘'',' ',¨⍨⊢⍴⊃∘⎕A)¨⍳⎕A⍳⎕

Try it online! (has ASCII art version at one additional byte)

 prompt for input

⎕A⍳ find ɩndex in Alphabet

 first that many ɩntegers

( apply the following tacit function to each :

⊃∘⎕A pick the argument'th letter letter from the Alphabet

⊢⍴ cyclically reshape it to the argument length

' ',¨⍨ append a space to each

⍴∘'', prepend a string of argument length (padded with spaces)

ϵnlist (flatten)


The ASCII art version just has a on the very left; mix list of strings into table of characters.

Adám

Posted 2017-08-23T14:21:56.990

Reputation: 37 779

4

Perl 5, 31 bytes

30 bytes code + 1 for -l.

print$"x$-,"$_ "x++$-for A..<>

Try it online!

Dom Hastings

Posted 2017-08-23T14:21:56.990

Reputation: 16 415

You can cut this down by using say instead of the -l flag: Try it online!

– Xcali – 2017-08-23T21:03:09.240

@Xcali I'm torn on -E/-M5.01, I've used say considerably in the past, and would probably abuse the fact that say is an alternative to print in a restricted source challenge or similar perhaps, but for the sake of -3, I'll keep as-is for now. See this meta post for a fair argument. Appreciate the input though!

– Dom Hastings – 2017-08-24T05:22:20.453

3

Dyalog APL, 38 bytes

{↑{(y/' '),(2×y←⎕A⍳⍵)⍴⍵,' '}¨⎕A↑⍨⎕A⍳⍵}

Try it online!

How?

⎕A↑⍨ - take the alphabet until

⎕A⍳⍵ - the input character

¨ - for each char

    ⍵,' ' - take the char and a space

    (...)⍴ - reshape to

    2×y←⎕A⍳⍵ - twice the index of the char in the alphabet

    (y/' ') - and prepend index-of-char spaces

- then flatten

Uriel

Posted 2017-08-23T14:21:56.990

Reputation: 11 708

3

05AB1E, 10 bytes

A¹¡н«ðâƶāú

Try it online!

-2 thanks to Adnan.

Append » to make it print in separate lines.

Erik the Outgolfer

Posted 2017-08-23T14:21:56.990

Reputation: 38 134

You could omit the < as one consistent leading space is okay. – Emigna – 2017-08-23T14:53:57.993

@Emigna Thanks! – Erik the Outgolfer – 2017-08-23T14:54:21.540

A¹¡н«ðâƶāú should work for 10 bytes – Adnan – 2017-08-23T18:56:40.683

@Adnan I think that ¹¡ will make it not work...oh so that's why there's a « in there. :p – Erik the Outgolfer – 2017-08-24T09:03:34.620

3

V, 28, 26, 25, 23 bytes (Competing)

¬A[/a
lDÓ./& ò
ò-Ûä$Û>

Try it online!

Note that although I have been planning on adding certain features for a long time, this challenge was what convinced me to finally do it.

The output contains one leading space on each line and one trailing newline.

Hexdump:

00000000: ac41 5b2f 1261 0a6c 44d3 2e2f 2620 f20a  .A[/.a.lD../& ..
00000010: f22d dbe4 24db 3e                        .-..$.>

Explanation:

¬A[         " Insert 'ABCDEFGHIJKLMNOPQRSTUVWXYZ['
   /        " Search for...
    <C-r>a  "   The input
l           " Move one character to the right
 D          " And delete every character after the cursor
  Ó         " Search for...
   .        "   Any character
    /       " And replace it with...
     & ò    "   That character followed by a space and a newline
ò           " Recursively...
 -          "   Move to the beginning of the next line up
  Ûä$       "   Make *line number* copies of the current line
     Û>     "   And indent this line by *line number* spaces

James

Posted 2017-08-23T14:21:56.990

Reputation: 54 537

1This is competing. You may remove the title remark. – None – 2017-08-23T15:32:11.807

It's useful for those who weren't aware of the new meta, such as myself – Conor O'Brien – 2017-08-23T22:05:31.890

3

APL (Dyalog Classic), 26 bytes

{↑{(≠\⍵<⍳3×⍵)\⍵⊃⎕A}¨⍳⎕A⍳⍵}

Try it online!

Explanation

                      ⍳⎕A⍳⍵  generate indexes up to position of right arg ⍵
{                   }¨       on each index apply function
   (≠\⍵<⍳3×⍵)                generate boolean mask for expansion (each line has a length 3 times its index ⍵, starting with ⍵ blanks and then alternating letter blank)
             \⍵⊃⎕A          expand character in position ⍵
 ↑                            mix result into text matrix

Gil

Posted 2017-08-23T14:21:56.990

Reputation: 141

Goodness... 4 APL-er solving the same problem at the same time! :) I think in codegolf you're allowed to remove the outer {}, replace with , and claim it's a "complete program" rather than a function. That would make your solution the best (so far). – ngn – 2017-08-24T06:40:55.043

Must be a good sign :) Thanks for the suggestion. I've seen it done but wasn't sure where to draw the line. I guess that I can save 3 bytes if I remove curlies and mix. – Gil – 2017-08-24T10:33:09.960

3

R, 94 88 bytes

-6 bytes thanks to Giuseppe

function(x,l=LETTERS)for(i in 1:match(x,l))cat(rep(' ',i-1),rep(paste(l[i],' '),i),'\n')}

Ungolfed:

f=function(x,l=letters){
  for(i in 1:which(l==x)){
    A=paste(l[i],' ')
    cat(rep(' ',i-1),rep(A,i),'\n')
  }
}

Andrew Haynes

Posted 2017-08-23T14:21:56.990

Reputation: 311

88 bytes : returning an anonymous function is fine, you can get rid of the braces since f is a one-liner, and using match instead of which saves a byte. – Giuseppe – 2017-08-24T14:39:17.037

71 bytes – Giuseppe – 2017-11-10T13:27:32.497

68 bytes taking input from stdin. – Giuseppe – 2018-11-24T14:35:13.873

3

Haskell, 52 44 bytes

f k=[[" ",s:" "]>>=(['A'..s]>>)|s<-['A'..k]]

Returns a list of lines.

Try it online!

f k=                  -- main function is f, input parameter k
  [   |s<-['A'..k]]   -- for each s from ['A'..k]
     >>=              -- map (and collect the results in a single string) the function: 
         (['A'..s]>>) --  replace each element in ['A'..s] with
    [  ,  ]           --  over the list, containing
     " "              --   a single space to get the indent
        s:" "         --   s followed by space to get the letter sequence

Edit: @jferard: saved three bytes. Thanks!

nimi

Posted 2017-08-23T14:21:56.990

Reputation: 34 639

49 bytes:f k=[tail$[" ",s:" "]>>=(['A'..s]>>)|s<-['A'..k]] – jferard – 2017-08-25T16:50:47.810

@jferard: Thanks a lot. Rereading the challenge I noticed that a leading space per line is allowed, so we don't need the tail$. – nimi – 2017-08-25T18:08:47.427

2

Japt -R, 24 23 17 15 bytes

Outputs an array, includes a leading newline and a leading & trailing space on each line.

IòUc ÏçSiXd¹iYç

Test it

  • 1 byte saved with help from Oliver and a further 6 thanks to him pointing out a better way to generate the initial array.

Shaggy

Posted 2017-08-23T14:21:56.990

Reputation: 24 623

2

05AB1E, 15 14 13 bytes

Saved 1 byte thanks to Adnan

A¹¡н«ƶ€S»¶¡āú»

Try it online! or the Ascii art version

Explanation

A                # push lowercase alphabet
 ¹¡              # split at input
   н             # get the first part
    «            # append the input
     ƶ           # repeat each a number of times corresponding to its 1-based index
      €S         # split each to a list of chars
        »        # join on spaces and newlines
         ¶¡      # split on newlines
           āú    # prepend spaces to each corresponding to its 1-based index
             »   # join on newlines

Emigna

Posted 2017-08-23T14:21:56.990

Reputation: 50 798

It looks like we handled it a bit differently :D

– Erik the Outgolfer – 2017-08-23T14:52:11.210

@EriktheOutgolfer: We did it quite similarly, but your very nice idea to append a space before lifting, removing the need for the join made yours shorter. I hadn't read that leading/trailing spaces nor output as list was okay, so that'll hopefully teach me to read the whole challenge before implementing :P – Emigna – 2017-08-23T15:01:49.310

tl;dr: vectorization :p – Erik the Outgolfer – 2017-08-23T15:05:38.523

A¹¡н« instead of ADIk>£ should work – Adnan – 2017-08-23T18:54:26.917

@Adnan: Thanks! I did have A¹¡н but didn't consider « to get the last letter so it wasn't good enough :P – Emigna – 2017-08-23T20:02:25.773

You might have the links to the TIO and ASCII art version swapped – Graviton – 2017-08-23T20:11:58.497

@Graviton: Indeed I do. Meaning since I switched them to this order, I actually had them correct the first time and then messed it up. Thanks for the heads up :) – Emigna – 2017-08-23T20:20:41.940

2

JavaScript (ES8), 92 bytes

c=>(g=n=>n>9?[...g(n-1),`${n.toString(36)} `.repeat(n-=9).padStart(n*3)]:[])(parseInt(c,36))

Uses lowercase letters. Lines have one leading and one trailing space. Returns an array of lines.

Test Snippet

let f=

c=>(g=n=>n>9?[...g(n-1),`${n.toString(36)} `.repeat(n-=9).padStart(n*3)]:[])(parseInt(c,36))

;O.innerText=f("k").join`\n`
<pre id=O></pre>

Justin Mariner

Posted 2017-08-23T14:21:56.990

Reputation: 4 746

2

APL (Dyalog Unicode), 22 bytesSBCS

⍕⍪⊢∘⊂\2,.↑⍉⍴⍨⌸⎕a↑⍨⎕a⍳⍞

Try it online!

Uses ⎕io←1. Prints a leading space, which is allowed.

ngn

Posted 2017-08-23T14:21:56.990

Reputation: 11 449

2

Husk, 13 bytes

z+ḣ∞øzRNC1…'A

Takes a character in single quotes as command line argument, prints result to STDOUT. Try it online!

Explanation

I'm exploiting the way Husk prints lists of lists of strings: join inner lists with spaces and outer lists with newlines.

z+ḣ∞øzRNC1…'A  Implicit input, say 'C'
          …'A  Range from A: "ABC"
        C1     Cut into strings of length 1: ["A","B","C"]
     z N       Zip with positive integers
      R        using repetition: x = [["A"],["B","B"],["C","C","C"]]
   ∞ø          The empty string repeated infinitely: ["","","",...
  ḣ            Prefixes: [[],[""],["",""],["","",""],...
z+             Zip with x using concatenation: [["A"],["","B","B"],["","","C","C","C"]]
               Implicitly join each inner list with spaces, join the resulting strings with newlines and print.

Zgarb

Posted 2017-08-23T14:21:56.990

Reputation: 39 083

2

QBasic, 79 74 72 bytes

Thanks to Taylor Scott for byte savings (twice!)

FOR i=1TO ASC(INPUT$(1))-64
?TAB(i)
FOR j=1TO i
?CHR$(64+i)" ";
NEXT j,i

Uses uppercase. The input is by keypress and is not echoed to the screen.

Explanation

We loop i from 1 up to the limiting letter's position in the alphabet (1-based). For each i, we move to column i of the screen using TAB; then, i times, we print the ith letter of the alphabet followed by a space.

DLosc

Posted 2017-08-23T14:21:56.990

Reputation: 21 213

As it turns out you can use the INPUT$(1) command as a direct replacement for the variable z$ for a delta of -2 bytes – Taylor Scott – 2018-06-29T20:14:45.307

@TaylorScott Good idea, thanks! – DLosc – 2018-06-29T20:22:17.430

1

Charcoal, 18 bytes

F⁺⌕αθ¹«P×⁺§αι ⁺ι¹↘

Try it online!

Erik the Outgolfer

Posted 2017-08-23T14:21:56.990

Reputation: 38 134

Nah, you can't let 05AB1E beat Charcoal... :P – totallyhuman – 2017-08-23T14:52:25.323

@totallyhuman the revenge :p

– Erik the Outgolfer – 2017-08-23T14:55:33.070

Sadly arbitrary leading whitespace isn't allowed otherwise E…·?θ⁺× κ⪫× κι would do the job in 14 bytes. – Neil – 2017-08-23T15:29:04.300

@Neil One leading whitespace is allowed, but I'm not sure how ? got in there. It should be A instead I think. Oh wait, ohhhhh I see what you mean. – Erik the Outgolfer – 2017-08-23T15:30:34.690

1

Pyth, 17 bytes

.e+*kd*+bdhk<GhxG

Try it here (pretty print version).


How does this work?

  • hxG - Takes the index of the input in the lowercase alphabet.

  • <G - Trims every character after the input from the alphabet.

  • .e - Enumerated Map. Maps over the trimmed alphabet with the indexes as k and the letters as b.

  • *kd - Append k spaces.

  • +bd - b + a space (the current letter + space).

  • *...hk - Repeat k+1 times.

  • +(...)(...) - Concatenate.

Mr. Xcoder

Posted 2017-08-23T14:21:56.990

Reputation: 39 774

1One of my favorite things about Pyth is writing an answer and finding that someone wrote the same answer, character for character. It hits that Python "there is a best answer" spot perfectly! – Dave – 2017-08-23T15:08:32.110

@pizzakingme Yeah, I wonder if I can do better – Mr. Xcoder – 2017-08-23T15:09:10.457

the space addition feels wrong, I think better is possible – Dave – 2017-08-23T15:14:20.717

@pizzakingme I could get .e+*kdjd*bhk<GhxG as 17 bytes as well – Mr. Xcoder – 2017-08-23T15:17:02.287

16 bytes: .e+*kd*+bdhkhcGQ – Dave – 2017-08-23T15:22:40.397

Oh actually that doesn't include Q – Dave – 2017-08-23T15:23:08.740

1

Braingolf, 65 bytes

a#a-# 7-,-~vc<!?>[$_]:$_|&,(.#a-!?.>[# M]1+>[.M# M]:$_!@|v#
&@R);

Try it online!

Lowercase.

Contains 1 trailing space on each line, and a trailing newline at the end of output.

Skidsdev

Posted 2017-08-23T14:21:56.990

Reputation: 9 656

1

Mathematica, 70 bytes

(T=Table)[""<>{" "~T~i,T[Alphabet[][[i]]<>" ",i]},{i,LetterNumber@#}]&

lowercase

outputs a list

thanx @ngenisis for corrections

For version place Column@ at the beginning

J42161217

Posted 2017-08-23T14:21:56.990

Reputation: 15 931

1

JavaScript, 102 94 bytes

2 bytes saved thanks to Neil

f=
a=>[...Array(parseInt(a,36)-9)].map((a,b)=>''.padEnd(b).padEnd(b*3+1,(b+10).toString(36)+' '))

console.log(f('k').join`\n`)

user72349

Posted 2017-08-23T14:21:56.990

Reputation:

1

C# (.NET Core), 103 bytes

n=>{var i='`';var l="";for(;i<n;l+='\n'){l+="".PadLeft(i++-96);for(int s=96;s++<i;)l+=i+" ";}return l;}

Try it online!

jkelm

Posted 2017-08-23T14:21:56.990

Reputation: 441

1

Retina, 51 bytes

^.
$&$&
}T`L`_L`^.
.
$.`$* $&$.`$* ¶
+`(\w) \B
$&$1

Try it online! Explanation:

^.
$&$&

Duplicate the (first) letter.

}T`L`_L`^.

Rotate it back 1 in the alphabet, or delete it if it's a duplicate A. Keep duplicating and rotating until we duplicate A, at which point the deletion undoes the duplication and the loop completes.

.
$.`$* $&$.`$* ¶

Replace each letter with a line with the letter padded on both sides.

+`(\w) \B
$&$1

Insert duplicate letters between all pairs of padding spaces to the right of existing letters.

Neil

Posted 2017-08-23T14:21:56.990

Reputation: 95 035

1

Haskell, 57 bytes

x!'@'=x
x!e=([e]:[' ':r++' ':[last r]|r<-x])!pred e
([]!)

Try it online!

Post Rock Garf Hunter

Posted 2017-08-23T14:21:56.990

Reputation: 55 382

1

Charcoal, 15 bytes

F…·AS«P⪫E…@ιι ↘

Try it online! Link is to verbose version of code. Explanation:

 …·AS           Inclusive character range from A to the input
F    «          Loop over each character
         …@ι    Exclusive range from @ to the current character
        E   ι   Replace each element with the current character
       ⪫        Join with spaces
      P         Print without moving the cursor.
              ↘ Move the cursor down and right.

If extra padding was legal, this would work for 14 bytes:

E…·?θ⁺× κ⪫× κι

Try it online! Link is to verbose version of code.

Neil

Posted 2017-08-23T14:21:56.990

Reputation: 95 035

1

Excel VBA, 72 Bytes

Anonymous VBE immediate window function that takes input from cell A1 and outputs to the VBE immediate window

For i=1To Asc([A1])-64:[B1]=i:?Space(i-1)[REPT(CHAR(B1+64)&" ",B1)]:Next

Taylor Scott

Posted 2017-08-23T14:21:56.990

Reputation: 6 709

1

Very naïve approach.

Tcl, 100 bytes

time {puts [format %[incr i]s \ ][string repe [format %c\  [expr $i+64]] $i]} [expr [scan $c %c]-64]

Try it online!

Tcl, 106 bytes

set i 0;while \$i<[scan $c %c]-64 {puts [format %$i.s \ ][string repe [format %2c [expr $i+65]] [incr i]]}

Try it online!


Below approahes do not have a leading space

Tcl, 107 bytes

set i 0;while \$i<[scan $c %c]-64 {puts [format %$i.s \ ][string repe [format %c [expr $i+65]]\  [incr i]]}

Try it online!

Tcl, 109 bytes

set i 0;time {puts [format %$i.s \ ][string repe [format %c [expr $i+65]]\  [incr i]]} [expr [scan $c %c]-64]

Try it online!

Tcl, 111 bytes

set i 0;time {puts [string repe \  $i][string repe [format %c [expr $i+65]]\  [incr i]]} [expr [scan $c %c]-64]

Try it online!

sergiol

Posted 2017-08-23T14:21:56.990

Reputation: 3 055

1

C++ (gcc), 164 bytes

#include<iostream>
#define f for(int i=0;i<o-'`';i++)
using namespace std;int main(){char c;cin>>c;for(char o='a';o<=c;o++){f cout<<' ';f cout<<o<<' ';cout<<'\n';}}

My first attempt after a long time lurking!

Ungolfed code below:

#include <iostream>

using namespace std;
#define f for (auto i = 0; i < output - '`'; i++)

int main()
{
  char input;

  cin >> input;

  for (char output = 'a'; output <= input; output++)
  {
    f cout << ' ';

    f cout << output << ' ';

    cout << endl;
  }
}

Try it online!

Drise

Posted 2017-08-23T14:21:56.990

Reputation: 111

I know there has to be a bunch of golfing things to do, but so far, that's the smallest I've gotten. – Drise – 2017-08-23T20:38:05.527

1

brainfuck, 111 bytes

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

Try it online!

Surprising how the Turing Tarpit itself can out-golf some other languages.

The breakdown:

Section A

>+[+[<]>>+<+]                                                       create character 'A'
             ,                                                      take input
              >>++++++++++                                          create '\n' character
                          >++++[>++++++++<-]                        create ' ' character
                                            ----[<<<->>>----]<<<-   map input to (1->26)

Section B

[<[-<+>>>>>.<<<<]+                                 print N spaces, then increment N
                  <[->+>>.>>.<<<<<]                print (N-1) of the Nth letter and spaces
                                   >>>.+>.<<-]     print additional letter, and newline

Graviton

Posted 2017-08-23T14:21:56.990

Reputation: 2 295

1

><>, 85 Bytes

i1-&0\1o*84\      \o*84o:$\
@)?;&>:> :?/~1+:88*+$:@>:?/~ao&:
     /-/          /$1- /

Try it online

Sasha

Posted 2017-08-23T14:21:56.990

Reputation: 431

This is almost a four-finned fish... coincidence? – Neil – 2017-08-25T13:45:05.140

1

Java (OpenJDK 8), 81 bytes

c->{String s="";for(int d=64;d++<c;)System.out.printf((s=" "+s+"%1$c ")+"%n",d);}

Try it online!

Olivier Grégoire

Posted 2017-08-23T14:21:56.990

Reputation: 10 647

1

Brain-Flak, 179 bytes

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

This is 178 bytes of code, and +1 for the -c flag.

Try it online!

(Semi-)Readable version:

({}[((((()()()()){}){}){}){}])

{

    ((({}[()])()))

    {
        ({}<

            (({})<>((((()()()()){}){}){}){})
            ((((()()()()){}){}){})<>

        >[()])
    }{}

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

    <>{}

    ((()()()()()){})

    <>

}

Fun fact: This will work with arbitrary characters above Z! Try it online!

James

Posted 2017-08-23T14:21:56.990

Reputation: 54 537

1

Bash, 93 90 bytes

for c in {A..Z}
{
printf "%$[i++*3+2]s\n" "$(echo `yes $c|head -$i`)"
[ $c = $1 ]&&break
}

Try it online!

Takes input as, and outputs as, uppercase letters.

Still getting the hang of golfing in Bash, so I'm open to tips.

Justin Mariner

Posted 2017-08-23T14:21:56.990

Reputation: 4 746

1

C (GCC), 115 109 Bytes

f(a,n,k,s,i){if(k){for(;i<s;i++)printf(" ");for(i=0;i<s+1;i++)printf("%c ",a);puts();f(++a,++n,--k,++s,0);}}

Usage

f(65,5,5,0,0)

Where the two 5's are the given K value, the rest are constants used later for recursive calls.

Ungolfed

f(a,n,k,s,i){
    if(k){
        for (; i<s; i++) printf(" ");
        for (i=0; i<s+1; i++) printf("%c ",a);
        puts();
        f(++a,++n,--k,++s,0);
    }
}

Output

enter image description here

Asleepace

Posted 2017-08-23T14:21:56.990

Reputation: 311

1

C (gcc), 77 bytes

i,j;f(c){for(j=64;i||j++<c&&printf("\n%*c ",i=j-64,j);--i&&printf("%c ",j));}

Try it online!

Contains unsequenced access to possibly incremented j, so very likely to break with a different compiler :)

fixed with identical byte count

Felix Palmen

Posted 2017-08-23T14:21:56.990

Reputation: 3 866

1

Alice, 31 bytes

/A''*?h~w0O~
\I"AxrS&..r!y"kx@/

Try it online!

Explanation

Linearized and with relevant spaces included, the program is as follows:

I'A*rh&w.O!" x A"'x?S~.0r~yk@

I                                   take input
 'A*                                append the letter A
    r                               expand to range (e.g., if input was D, string is now DCBA)
     h&w                            split string into characters, and repeat the main loop that number of times
        .O                          output copy of top string on stack with newline
          !                         move top string (last printed row) to tape
           " x A"                   push " x A"
                 'x S               replace the occurrence of "x" with
                   ?                  the string on the tape
                     ~              swap to get next letter
                      .             copy this letter
                       0r           get entire range from that letter down to "0"
                         ~          swap again to put letter on top of stack
                          y         replace all characters in this range (effectively, all non-space characters) with the next letter
                           k        repeat (end of main loop)
                            @       exit

Nitrodon

Posted 2017-08-23T14:21:56.990

Reputation: 9 181

1

PHP, 69+1 bytes

A<?for($c=A;$c<$argn;)echo($p=str_pad)($p("
",++$i+1),$i*3,++$c." ");

Run as pipe with -nF or try it online.


The Z case cost 4 bytes. for($c=A;$c<=$argn;)echo($p=str_pad)($p(" ",++$i),$i*3,$c++." "); (with -nR) works for A to Y.

Printing a list of underscore-separated lines would save two bytes, but that´d feel like cheating.

Titus

Posted 2017-08-23T14:21:56.990

Reputation: 13 814

1

C (gcc), 76 bytes

i,j;f(c){for(i=0;i++<c-64;puts(""))for(j=0;j<i;)printf("%*c",j++?2:i,i+64);}

Try it online!

gastropner

Posted 2017-08-23T14:21:56.990

Reputation: 3 264

1

Ruby, 62 Bytes

Assumes input as a string (e.g., 'A'). Wasn't clear from the rules whether this was allowed. Will update if not.

Lots of room for improvement, I'm sure.

->n{a=[*'A'..n];a.map{|x|' '*a.index(x)+(x+' ')*-~a.index(x)}}

displayname

Posted 2017-08-23T14:21:56.990

Reputation: 151

BTW This is definitely a valid way to take input. +1 – HyperNeutrino – 2017-11-10T17:02:06.353

1

Julia 0.6, 40 bytes

c->[" "^i*"$('A'+i) "^-~i for i=0:c-'A']

Try it online!

Returns an array of strings containing the output. (Pretty printed on TIO using just map (println, f(c)).)

^ applied to strings repeats the string that many times. $() executes its content and pastes the result into the string (here, the correct letter for the line). Finally, the space repetition and the letter repetition are concatenated with *.

sundar - Reinstate Monica

Posted 2017-08-23T14:21:56.990

Reputation: 5 296

1

Kotlin, 57 bytes

{('A'..it).map{" ".repeat(it-'A')+"$it ".repeat(it-'@')}}

Try it online!

snail_

Posted 2017-08-23T14:21:56.990

Reputation: 1 982

0

Röda, 53 bytes

f L{seq 0,ord(L)-65|[" "*_..`${chr(_1+65)} `*(_1+1)]}

Try it online!

fergusq

Posted 2017-08-23T14:21:56.990

Reputation: 4 867

0

SOGL V0.12, 15 14 12 bytes

ZZ,Wm{ē@Ο}¹¾

Try it Here!

dzaima

Posted 2017-08-23T14:21:56.990

Reputation: 19 048

0

CJam, 22 21 20 bytes

This is the "list of lines" version. Just add an "N" before the close bracket to make it look nice. (Thanks to @Erik)

rc'@-{)_S*\_'@+*S*}%

Try it Online (nice version).

geokavel

Posted 2017-08-23T14:21:56.990

Reputation: 6 352

i64 can be '@ – Erik the Outgolfer – 2017-08-23T16:42:19.593

Oh, and you can re-order your code like this to avoid leading spaces: rc'@-{_S*\)_'@+*S*N}% – Erik the Outgolfer – 2017-08-23T16:49:08.333

0

Charcoal, 19 bytes

F⁻℅S⁶³«×⁺℅⁺ι⁶⁴ ιJιι

Try it online! Link is to verbose version.

A bit of a different approach from the other answer, let's see if it's golfable...

totallyhuman

Posted 2017-08-23T14:21:56.990

Reputation: 15 378

0

Proton, 47 bytes

c=>[' '*i+-~i*('%c '%(i+65))for i:0..ord(c)-64]

Not unlike the Python answers.

Try it online!

Business Cat

Posted 2017-08-23T14:21:56.990

Reputation: 8 927

0

J, 39 bytes

[:(#\([' '&,1j1##)"0])i.@>:&.(65-~3&u:)

Try it online!

miles

Posted 2017-08-23T14:21:56.990

Reputation: 15 654

0

Jelly, 19 bytes

ḢØAḣi¥p⁶ẋ"J$µLḶ⁶ẋ;"

Try it online!

Function that returns a list. Append ⁸Y to print in separate lines. Erase the footer to show actual output instead of string representation.

Erik the Outgolfer

Posted 2017-08-23T14:21:56.990

Reputation: 38 134

0

Shnap, 97 96 bytes

-1 byte because I remembered that the parser reads strings through newlines, so a literal newline is shorter than \n

$c{n=65s=""for k:range(n,c+1){for range(n,k)s+=" "for range(n,k+1)s+=char(k)+" "s+="
"}return:s}

This is an anonymous function (actually, all functions in Shnap are anonymous...).

Try it online!

Alternative version that uses the fact that blocks return the last instruction's value

Ungolfed/explanation:

$ (c) {                  //Function with 1 parameter
    n=65                    //Value of 'A'
    s=""                    //The result
    for k:range(n,c+1) {    //Inclusive range from n to c, range(n,c,1,1) also works, as third arg is step and fourth is inclusive (bool).
                            //For loop variable is k
        for range(n,k)      //Exclusive range from n to k
            s+=" "          //Add a space
        for range(n,k+1)    //Inclusive range from n to k
            s+=char(k)+" "  //Add k and a space
        s+="\n"             //Add a newline

    }
    return:s                //Return the result
}

I really should implement string multiplication and eval...

Socratic Phoenix

Posted 2017-08-23T14:21:56.990

Reputation: 1 629

0

TXR Lisp, 77 bytes

(do mapdo(op pprinl`@{""@2}@{(take(inc @2)(gun @1))}`)(range #\A@1)(range 0))

Run:

This is the TXR Lisp interactive listener of TXR 184.
Quit with :quit or Ctrl-D on empty line. Ctrl-X ? for cheatsheet.
1> (do mapdo(op pprinl`@{""@2}@{(take(inc @2)(gun @1))}`)(range #\A@1)(range 0))
#<interpreted fun: lambda (#:arg-01-0173 . #:rest-0172)>
2> [*1 #\F]
A
 B B
  C C C
   D D D D
    E E E E E
     F F F F F F

Kaz

Posted 2017-08-23T14:21:56.990

Reputation: 372

0

Pyth, 26 bytes

Should meet OPs specs.

VhxrG1w++*dNr@GN1*+dr@GN1N

Try it online!

Stan Strum

Posted 2017-08-23T14:21:56.990

Reputation: 436

I am afraid you misunderstood. You must have exactly one space between the characters, not many. See my answer for clarifications. – Mr. Xcoder – 2017-08-24T09:40:47.713

Ah, sorry. I'll fix that – Stan Strum – 2017-08-24T16:08:10.043

0

C++ (gcc), 179 bytes

Well, someone ought to post the most un-original method, I might as well be that someone.

#include <iostream>
using namespace std;
int main(){char n;cin>>n;for(char i='A';i<=n;i++){for(char k='A';k<i;k++){cout<<" ";}for(int j=0;j<=i-'A';j++){cout<<i<<" ";}cout<<endl;}}

An easier-to-read version of the code:

#include <iostream>
using namespace std;
int main()
{
    char n;
    cin>>n;
    for (char i='A';i<=n;i++)
    {
        for (int k=0;k<n-i;k++)
        {
            cout<<" ";
        }
        for (int j=0; j<n-'A'+1;j++)
        {
            cout<<i<<" ";
        }
        cout<<endl;
    }
}

Try it online!

Chady

Posted 2017-08-23T14:21:56.990

Reputation: 1

0

Java, 363 bytes

public class MyClass {
    public static void main(String args[]) {
        char x='A';
        int count=0;
      for(x='A';x<='Z';x++){
        for(int x1=count;x1>0;x1--) {
            System.out.print(" ");
        }
        for(int y=count;y>=1;y--) {
            System.out.print(x);
        }
        System.out.print(x+"\n");
       count++;
    }
    }
}

gani

Posted 2017-08-23T14:21:56.990

Reputation: 1

1make sure your answer is consistent with the other answers by using a title and a byte count – Michthan – 2017-08-24T11:10:29.110

Welcome to Programming Puzzles and Code Golf! Notice that you can remove a lot of the whitespace to shorten your code. Also, your code should print a space between the letters on each line. Changing System.out.print(x); to System.out.print(x+" "); will do the trick. – Steadybox – 2017-08-24T11:20:02.870

How do we enter any parameter? Like that limits where we stop? This is present in the question, I don't see it in this answer. – Olivier Grégoire – 2017-08-24T12:59:20.973

0

Pyth, 18 17 bytes

-1 thanks to @TheIOSCoder because you are apparently allowed to surround the input in quotes

j.b+*dYjd*NhYGhxG

Try it online!

Explanation

j.b+*dYjd*NhYGhxG    accepts a token as input, must be lowercase and in quotes

j                    joins on new line
 .b   Y   N Y        maps A (lambdas NY) over B and C in parallel
   +                 joins two strings on same line
    *    *           repeats A B times
     d  d            " " or space
       j             joins B on A
           h  h      A + 1
             G  G    lowercase alphabet
               x     returns position of B in A
                     implicit input

chromaticiT

Posted 2017-08-23T14:21:56.990

Reputation: 211

You can use the input with quotes around to save 1 byte through implicit input (Q) - 17 bytes

– None – 2017-08-25T12:07:39.743

0

Recursiva, 28 bytes

{B-Oa64"P+*' '~}J' '*}C+64}"

Try it online!

officialaimm

Posted 2017-08-23T14:21:56.990

Reputation: 2 739

0

K (oK), 35 bytes

Solution:

`c${,/(x#32),(x+1)#,65+x,-33}'!-64+

Returns list of strings. prepend `0: to write to stdout instead.

Try it online!

Example:

`c${,/(x#32),(x+1)#,65+x,-33}'!-64+"F"
("A "
 " B B "
 "  C C C "
 "   D D D D "
 "    E E E E E "
 "     F F F F F F ")

Explanation:

Struggled to golf this down any further... K is interpretted right-to-left:

`c${,/(x#32),(x+1)#,65+x,-33}'!-64+ / the solution
                               -64+ / subtract 64 from input, "F"=>6 (implicit ascii)
                              !     / til, !6 => 0 1 2 3 4 5
   {                        }'      / lambda function with each input
                         -33        / negative 33
                       x,           / x concatenated, e.g. 0 -33
                    65+             / add 65, 0 -33 => 65 32 (aka "A ")
                   ,                / enlist, wraps "A " into a list ("A ")
             (x+1)#                 / take (#) x+1 instances of this list
            ,                       / concatenate with
      (x#32)                        / x instances of the number 32 (aka " ")
    ,/                              / raze, flattens this list down
`c$                                 / cast to characters

streetster

Posted 2017-08-23T14:21:56.990

Reputation: 3 635

0

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

Taylor Scott

Posted 2017-08-23T14:21:56.990

Reputation: 6 709

0

Pip, 22 bytes

Wz@iLEaPsXi.Yz@iX++iJs

Uses lowercase and takes input from the command line. Try it online!

Explanation

Implicit: a is 1st cmdline arg; z is lowercase alphabet; i is 0; s is space.

W                        While
 z@i                     i'th character in lowercase alphabet
    LEa                  is less than or equal to a:
       P                  Print
        sXi               i spaces
           .(         )   to which concatenate
             z@i          i'th character in lowercase alphabet
                X++i      repeated i times, after incrementing i
                    Js    joined on spaces

DLosc

Posted 2017-08-23T14:21:56.990

Reputation: 21 213

0

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!

Giuseppe

Posted 2017-08-23T14:21:56.990

Reputation: 21 077

0

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!

Herman L

Posted 2017-08-23T14:21:56.990

Reputation: 3 611

0

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!

gggg

Posted 2017-08-23T14:21:56.990

Reputation: 1 715

0

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.

mroman

Posted 2017-08-23T14:21:56.990

Reputation: 1 382

0

Common Lisp, 89 bytes

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

Try it online!

Renzo

Posted 2017-08-23T14:21:56.990

Reputation: 2 260

0

SmileBASIC, 58 57 bytes

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

12Me21

Posted 2017-08-23T14:21:56.990

Reputation: 6 110