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LMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGFEDCBA
ABCDEFEDCBA
ABCDEDCBA
ABCDCBA
ABCBA
ABA
A

Specs

  • Extra trailing newlines are allowed at the end of the output.
  • Extra trailing spaces (U+0020) are allowed at the end of each line, including the extra trailing newlines.
  • You can use all lowercase instead of all uppercase, but you cannot print partially lowercase partially uppercase.
  • You can return the text as a function output instead of printing it in a full program.

Scoring

Since this is a triangle, and a triangle has 3 sides, and 3 is a small number, your code should be small in terms of byte-count.

\$\endgroup\$
5
  • 24
    \$\begingroup\$ So many alphabets recently \$\endgroup\$ Commented Aug 3, 2016 at 11:15
  • 1
    \$\begingroup\$ My synesthesia is going hog wild, @downrep_nation \$\endgroup\$ Commented Aug 3, 2016 at 13:33
  • 7
    \$\begingroup\$ "Since a triangle has 3 sides and 3 is a small number, so your code should be small in terms of byte count." seems legitimate \$\endgroup\$ Commented Aug 4, 2016 at 22:00
  • 1
    \$\begingroup\$ Squares of numbers composed only of 1 seems related: 1*1 = 1 ~= A , 11*11 = 121 ~= ABA , 111*111 = 12321 ~= ABCBA ... \$\endgroup\$
    – Caridorc
    Commented Aug 5, 2016 at 13:28
  • 2
    \$\begingroup\$ "Since a triangle has 3 sides and..." Illuminati Confirmed. \$\endgroup\$
    – hyperneutrino
    Commented Oct 28, 2016 at 0:47

96 Answers 96

3
\$\begingroup\$

brainfuck, 79 bytes

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

Formatted:

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

Try it online

\$\endgroup\$
2
\$\begingroup\$

Sesos, 27 bytes

0000000: a85ab9 ac5daa f8b1c7 785f9b b961f7 665c1b 73ccfc  .Z..]....x_..a.f\.s..
0000015: c01ecb 987303                                     ....s.

Try it online! Check Debug to see the generated SBIN code.

Sesos assembly

The binary file above has been generated by assembling the following SASM code.

add 65, rwd 1, add 10, rwd 2, add 25
jmp
    fwd 3
    jmp
        put, fwd 1
    jnz
    rwd 1
    jmp
        fwd 1, add 1, fwd 1, add 1, rwd 2, sub 1
    jnz
    fwd 2
    jmp
        rwd 2, add 1, fwd 2, sub 1
    jnz
    rwd 1, add 1, rwd 2
    jmp
        put, rwd 1
    jnz
    rwd 1, sub 1
jnz
fwd 3
jmp
    jmp
        put, fwd 1
    jnz
    rwd 1, get, rwd 1
    jmp
        put, rwd 1
    jnz
    fwd 2
; jnz (implicit)
\$\endgroup\$
2
\$\begingroup\$

///, 208 bytes

/'/\/\///+/BA
AB'-/DC+CD'&/FE-EF')/HG&GH'=/JI)IJ'|/LK=KL'7/NM|MN'1/PO7OP'q/RQ1QR'p/TSqST'6/VUpUV'[/XW6WX/A
A+C+C-E-E&G&G)I)I=K=K|M|M7O7O1Q1QqSqSpUpU6W6W[Y[YZY[Y[W6W6UpUpSqSqQ1Q1O7O7M|M|K=K=I)I)G&G&E-E-C+C+A
A

Not winning of course, but here it is, predating Martin Ender...

\$\endgroup\$
2
\$\begingroup\$

bash, 80 bytes

printf -v a %s {A..Z};for i in {1..26} {25..1};{ echo ${a::i}`rev<<<${a::i-1}`;}
\$\endgroup\$
2
\$\begingroup\$

Javascript (ES5), 105 bytes

Beating all other ES6 answers using some good ol' vanilla JS looping!

for(a="",n=g=1;n++<52;n<27?g++:g--){for(z=x=0;z++<g*2-1;z<g?x++:x--)a+=String.fromCharCode(65+x);a+="\n"}a

I could save 1 byte by using ES6 and changing

a+="\n"

to

a+=`
`

but nah.

\$\endgroup\$
2
  • \$\begingroup\$ Since you don't have console.log anywhere I imagine this is supposed to be the contents of a function. If you wrapped it in the ()=>{} that you need to actually execute your code and tried it, it would return undefined. It needs to be return a. If you had done everything so that it can actually be run (including the ()=>{} and return ) it would be 119 bytes. tl;dr this code doesn't work. \$\endgroup\$
    – Pandacoder
    Commented Aug 5, 2016 at 18:37
  • \$\begingroup\$ Nice. Also (10+x).toString(36) is shorter than String.fromCharCode(65+x) and like @Pandacoder said, you should put something like alert(a) at the end to make it valid. \$\endgroup\$
    – user81655
    Commented Aug 14, 2016 at 10:11
2
\$\begingroup\$

C#, 289 215 206 190 179 171 159 157 156 153 147 bytes

(n,i,s)=>{s=new string[51];for(i=0;i<26;){for(n=65;n-65<i;)s[i]+=(char)n++;for(;n>64;)s[i]+=(char)n--;s[50-i]=s[i++];}return string.Join("\n",s);};

Saved 3 bytes thanks to VisualMelon

Saved 6 bytes thanks to mdfst13

Formatted version:

(n,i,s)=>
{
    s=new string[51];

    for(i=0;i<26;)
    {
        for(n=65;n-65<i;)
            s[i]+=(char)n++;

        for(;n>64;)
            s[i] += (char)n--;

        s[50-i]=s[i++];
    }

    return string.Join("\n",s);
};

156 byte version (when the irrelevant whitespace is removed) of counting backwards, uses a similar concept to the above method but does so in reverse.

(n, i, s) =>
{
    s = new string[i = 51];
    for (; --i > 24;)
    {
        for (n = 65; i + n < 116;)
            s[i] += (char)n++;

        for (n = 50 - i + 64; n > 64;)
            s[i] += (char)n--;

        s[50 - i] = s[i];
    }

    return string.Join("\n", s);
};
\$\endgroup\$
4
  • \$\begingroup\$ Feel free to share any improvements to my code if you find any \$\endgroup\$ Commented Aug 4, 2016 at 14:03
  • \$\begingroup\$ An explanation would be nice! You can use a for loop instead of a while, saving you the ; on the statement prior. The last statement in the outer loop can be put inside the last inner for loop (s[...]=s[i]+=) (need to juggle the i++ a bit, can certainly be done with only one extra byte). You've also got 51-i-1 in there, which can be reduced ;) I would be looking into reducing the two inner loops into one, and counting i backwards (so you assign it to 51 inside the array constructor). \$\endgroup\$ Commented Aug 4, 2016 at 17:51
  • \$\begingroup\$ @VisualMelon I've been looking at it for ages and I never saw the 51 - I - 1 haha, and I can't put the last statement in the last inner loop as it doesn't get called on the first pass but didn't know I could chain the assignment like that so that's cool! And I've been looking into combining the loops, getting there \$\endgroup\$ Commented Aug 5, 2016 at 8:06
  • \$\begingroup\$ @VisualMelon I reversed the outer loop and ended up adding 3 bytes when I got it working, will see if I can golf it down though \$\endgroup\$ Commented Aug 5, 2016 at 9:39
2
\$\begingroup\$

JavaScript (ES6), 89 bytes

R=(n,s=10,c=s.toString(36))=>n?c+R(n-1,s+1)+c:c
C=(n=0,r=R(n))=>n<25?r+`
`+C(n+1)+`
`+r:r

Not the shortest, but I wanted to try my hand at recursion. Call with C().

\$\endgroup\$
2
\$\begingroup\$

Pepe, 94 bytes

rEeEeEEeEeREeEeeeeeEREEEEEEerEEReeeReeEREEEeEREEEeEREEeeREEEEEreererEEReeeReeEReReREEeEreeReee

Try it online!

\$\endgroup\$
2
\$\begingroup\$

brainfuck, 96 bytes

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

Try it online!

; Initialize memory as: 0 (25) 0 "\n" "A" 0
+++++[->+++++>>++>+++++++++++++<<<<]>

[-                          ; Repeat 25 times
    >>>[.>]                 ; print all the characters on the band
    <[->+>+<<]>+>[-<<+>>]   ; copy the last character and increment
    <<<[.<]                 ; print all but the last two characters backwards
<]
>>>
[                           ; while there is still characters left
    [.>]                    ; print all the characters
    <[-]                    ; remove last character
    <[.<]                   ; print all characters backwards
>>]
\$\endgroup\$
2
\$\begingroup\$

Perl 5 with -M5.010, 54 bytes

for$@(A..Z){@;=($_.$/,@;);s/$*/$*$@$*/;say;$*=$@}say@;

Try it online!

Saved bytes thanks to @Xcali!

\$\endgroup\$
2
  • \$\begingroup\$ Found a method which takes 56 bytes \$\endgroup\$
    – Xcali
    Commented Jun 14, 2019 at 22:58
  • \$\begingroup\$ Thanks @Xcali! With you suggestion managed to get it down to 54. And some added obfuscation for entertainment... \$\endgroup\$ Commented Jun 17, 2019 at 19:37
2
\$\begingroup\$

Vyxal j, 8 bytes

kA¦ømƛøm

Try it Online!

Explanation:

kA        # Uppercase ALPHABET
  ¦       # Prefixes (A, AB, ABC, ...)
   øm     # Mirror without duplicating middle
     ƛ    # For each:
      øm  #   Mirror without duplicating middle
\$\endgroup\$
2
\$\begingroup\$

Julia 0.4, 84 bytes

!()=(- =join;a=-char(65:90);b=[a[1:x+1]*a[x:~0:1]for x=0:25];vcat(b,b[25:~0:1])-"
")

Try it online!

\$\endgroup\$
1
\$\begingroup\$

JavaScript (ES6), 141

for(a=65,q=[],z=[];a<91;z.push(a++))q.push(String.fromCharCode(...z,a,...[...z].reverse()))
a=q.pop(),alert([...q,a,...q.reverse()].join`\n`)

\$\endgroup\$
1
\$\begingroup\$

Retina, 90 88 86 76 bytes

I'm sure it can be made shorter, maybe by using non-verbose replacements and simply outputting at the end. (I tried. I don't think I can do it shorter that way.)

:`
A
A
ABA
{:`

(.)([^Z]\1)
$1$2$2
}T1`__L`L`(?<=(.)[^Z])\1
+:`(.).\1|^A$
$1

Try it online

Thanks to LeakyNun for 14 bytes off

\$\endgroup\$
2
  • \$\begingroup\$ @LeakyNun Thanks, idk why I thought I needed that part... \$\endgroup\$
    – mbomb007
    Commented Aug 3, 2016 at 16:21
  • \$\begingroup\$ Match the second stage with ^ and insert only AB. \$\endgroup\$ Commented Aug 4, 2016 at 14:20
1
\$\begingroup\$

Swift 2.2, 157 142 Bytes

let t={(l:Int)in[Int](1..<l)+[Int](l.stride(to:0,by:-1))}
for x in(t(n).map{t($0).map{"\(UnicodeScalar($0+64))"}.reduce(""){$0+$1}}){print(x)}

ungolfed:

let makeTriangleArray = {(limit: Int) -> [Int] in
    return [Int](1 ..< limit) + [Int](limit.stride(to: 0, by: -1))
}

let n = 26
let lines = makeTriangleArray(n).map{
    makeTriangleArray($0).map{String(UnicodeScalar($0 + 64))}
                         .reduce(""){ $0 + $1}
}

for line in lines {
    print(line)
}

157 bytes:

let t={(l:Int)in[Int](1..<l)+[Int](l.stride(to:0,by:-1))}
print(t(n).map{t($0).map{"\(UnicodeScalar($0+64))"}.joinWithSeparator("")}.joinWithSeparator("\n"))

ungolfed:

let makeTriangleArray = {(limit: Int) -> [Int] in // "called t" above
    return [Int](1 ..< limit) + [Int](limit.stride(to: 0, by: -1))
}

let n = 26
let s = makeTriangleArray(n).map{
    makeTriangleArray($0).map{String(UnicodeScalar($0 + 64))}
                         .joinWithSeparator("")
}.joinWithSeparator("\n")
print(s)
\$\endgroup\$
1
\$\begingroup\$

Jelly, 16 bytes

ŒRAạ
25ÇÇ€‘ịØAj⁷

This uses the same method in my Python answer.

Try it online.

Explanation

ŒRAạ  Define a helper link. Input: n
ŒR    Create the range [-abs(n), , ..., 0, ..., abs(n)]
  A   Take the absolute value of each
   ạ  Return the absolute difference between each value and n

25ÇÇ€‘ịØAj⁷  Main link. No arguments
25           The constant 25
  Ç          Call the helper link on 25 to get [0, 1, ..., 25, ..., 1, 0]
   ǀ        Call the helper link on each value in the previous
     ‘       Increment every value
       ØA    The alphabet (the string 'A..Z')
      ị      Select the char at each index in the alphabet
         j⁷  Join them using newlines and return
\$\endgroup\$
2
  • \$\begingroup\$ This is extremely close to this answer \$\endgroup\$
    – Leaky Nun
    Commented Aug 3, 2016 at 18:59
  • \$\begingroup\$ @LeakyNun It generates the indices into the alphabet using a different method. Since there is only one output the intermediate values only finally become identical after the increment. \$\endgroup\$
    – miles
    Commented Aug 3, 2016 at 19:19
1
\$\begingroup\$

Batch, 226 224 bytes

@set z=ABCDEFGHIJKLMNOPQRSTUVWXYZ
@set a=YXWVUTSRQPONMLKJIHGFEDCBA
@for /l %%i in (0,1,25)do @call echo %%z:~0,%%i%%%%z:~%%i,1%%%%a:~-%%i,%%i%%
@for /l %%i in (24,-1,0)do @call echo %%z:~0,%%i%%%%z:~%%i,1%%%%a:~-%%i,%%i%%

Edit: Saved 2 bytes thanks to @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ.

\$\endgroup\$
2
  • \$\begingroup\$ I think you can do )do, but not any other space (except in(), maybe... \$\endgroup\$ Commented Aug 3, 2016 at 9:20
  • \$\begingroup\$ @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ Oddly enough I have done this before, just the once: codegolf.stackexchange.com/a/68936/17602 \$\endgroup\$
    – Neil
    Commented Aug 4, 2016 at 10:04
1
\$\begingroup\$

QBasic, 151 122 bytes

Really just for fun (via QB64) - it doesn't golf well

Taking some ABS() inspiration from Joffan's VBA answer but applying it differently:

FOR i=-25 TO 25
FOR n=0 TO 25-abs(i)
s$=s$+chr$(n+65)
IF n THEN t$=t$+chr$(90-abs(i)-abs(n))
NEXT
? s$+t$
s$=""
t$=""
NEXT

Previously:

FOR i=0 TO 25
p(i)
NEXT
FOR i=0 to 25
p(25-i)
NEXT
SUB p(i)
FOR n=0 TO i
s$=s$+chr$(n+65)
IF n THEN t$=t$+chr$(65+i-n)
NEXT
? s$+t$
s$=""
t$=""
END SUB
\$\endgroup\$
1
\$\begingroup\$

C#, 162 bytes

void p(){for(int i=1;i<54;i++){var a=Enumerable.Range(65,i>27?54-i:i).Select(n=>(char)n);Console.WriteLine(new string(a.Concat(a.Reverse().Skip(1)).ToArray()));}}

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I was wondering what the linq version would look like, you need System.Console.. though right? and shouldn't you also include using System.Linq in the byte count although I'm unsure about that \$\endgroup\$ Commented Aug 4, 2016 at 12:15
  • \$\begingroup\$ Change your for loop to for(int i=0;++i<54;) to save some bytes \$\endgroup\$ Commented Aug 4, 2016 at 12:25
1
\$\begingroup\$

HTML, 1412 bytes

<pre>A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
ABCDEFGFEDCBA
ABCD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EDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGFEDCBA
ABCDEFEDCBA
ABCDEDCBA
ABCDCBA
ABCBA
ABA
A</pre>

\$\endgroup\$
4
  • 4
    \$\begingroup\$ Please – – – – – \$\endgroup\$
    – Leaky Nun
    Commented Aug 4, 2016 at 15:52
  • 1
    \$\begingroup\$ Actually, with native HTML it's impossible to do better than this \$\endgroup\$ Commented Aug 5, 2016 at 17:36
  • 1
    \$\begingroup\$ @LeakyNun You must be on a whole 'nother level. What is – – – – – – and how do I make it work? \$\endgroup\$
    – MonkeyZeus
    Commented Aug 5, 2016 at 17:44
  • \$\begingroup\$ A possible interpretation of @LeakyNun's comment: codegolf.stackexchange.com/a/88984 \$\endgroup\$
    – manatwork
    Commented Aug 6, 2016 at 10:56
1
\$\begingroup\$

R, 95 bytes

L=LETTERS;cat("A\n");for(i in 2:50)cat(L[1:(26-abs(i-26))],L[(25-abs(i-26)):1],'\n');cat("A\n")

Ungolfed:

L=LETTERS; #Took idea from @Frederic, I apologize if I shouldn't (first time posting)
cat("A\n")
for(i in 2:50)
{
    cat(L[1:(26-abs(i-26))],L[(25-abs(i-26)):1],'\n')
}
cat("A\n")

Basically, the formula in the cat function in the for loop is a transformation on the absolute value function, mapping n -> n for Letters 2 through 26 and then mapping Letters 27 -> 25, 28 -> 24, ..., 50 -> 2. I don't think it would work if I included the 'A' in this formula, which is why I printed it out separately.

\$\endgroup\$
1
  • \$\begingroup\$ 100 bytes and actually valid. \$\endgroup\$
    – Giuseppe
    Commented Jan 15, 2018 at 17:57
1
\$\begingroup\$

PHP, 80 83 bytes

Making half of the triangle then print it in reverse did the trick.

for($a="A";$a<"Z";$b.=$a++)$c.=$b.$a.strrev($b)."
";echo"$c{$b}Z".strrev($c.$b);
\$\endgroup\$
1
\$\begingroup\$

MATLAB, 53 Bytes

MATLAB is not made for strings, so this needs some looping. I haven't found a faster way to create a list 1 2 3 4 3 2 1, than [1:4,3:-1:1], which seems really verbose.

Anyway, it's only beaten by 11/55 other submissions, and most of those are golfing languages.

for i=[1:26,25:-1:1]
disp(['',64+[1:i,i-1:-1:1]])
end
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Just spent an entertaining fifteen minutes proving you right that this is indeed the shortest - even inline definition of an anonymous function (Octave-only) is still longer. \$\endgroup\$
    – Sanchises
    Commented Jul 25, 2017 at 11:42
1
\$\begingroup\$

R, 71 69 bytes

L=LETTERS;for(i in c(1:26,25:1))cat(c(L[1:i],L[i:1][-1]),"\n",sep="")

See here on an online interpreter.

Edit: moved LETTERS outside the loop in order to avoid the curly brackets.

\$\endgroup\$
2
  • \$\begingroup\$ 59 bytes \$\endgroup\$
    – Giuseppe
    Commented Jan 15, 2018 at 17:59
  • \$\begingroup\$ oh I didn't notice that my suggestion was identical to this one. \$\endgroup\$
    – Giuseppe
    Commented Jan 15, 2018 at 17:59
1
\$\begingroup\$

Javascript (ES6), 113 bytes

i=>{for(i=0;i<51;i++,console.log(L))for(j=s=i<26?i:50-i,L="";j>=0;)k=String.fromCharCode(65+j),L=k+(j---s?L+k:L)}

Thanks to manatwork for pointing me to a tip written by William Barbosa to reduce by a byte.

\$\endgroup\$
1
  • \$\begingroup\$ As William Barbosa wrote in his tip, is shorter to declare an unused dummy parameter. \$\endgroup\$
    – manatwork
    Commented Aug 5, 2016 at 18:45
1
\$\begingroup\$

Rust, 120 bytes

fn main(){for j in -25i8..26{let k=25-j.abs();for i in -k..k+1{print!("{}",(65+k-i.abs())as u8 as char);}println!("");}}

My first attempt at codegolfing in Rust... codegolfing in anything, really. A straightforward attempt, just using for loops and abs().

fn main() {
    for j in -25i8..26 {
        let k=25-j.abs();
        for i in -k..k+1{
            print!("{}",(65+k-i.abs())as u8 as char);
        }
        println!("");
    }
}
\$\endgroup\$
1
\$\begingroup\$

PHP, 78 Bytes

foreach(range(A,Z)as$r)$o.="\n$t".strrev($t.=$r);echo$o.substr(strrev($o),51);
\$\endgroup\$
1
\$\begingroup\$

Python, 156 bytes

Not impressive, but I'm proud of myself because I'm a noob:

def p(k):
    x=k-1
    while x>-k:
        print(chr(64+(k-abs(x))),end="")
        x-=1
q=25
while q>-27:
    p(26-abs(q))
    print()
    q-=1
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Welcome to PPCG! You can save a bunch of bytes by making your indentation single spaces. You can also use tricks like print();q-=1. \$\endgroup\$
    – Stephen
    Commented Sep 10, 2017 at 20:26
1
\$\begingroup\$

SOGL V0.12, 10 bytes

øZ{⁴Κ}¹╬,k

Try it Here!

Explanation:

ø           push an empty string
 Z{  }      for each character in the alphabet do
   ⁴          duplicate the item before the top item
    Κ         reverse add to that
              or simpler - on each iteration creates a duplicate of ToS but with the current character appended.
      ¹     wrap the stack in an array
       ╬,   quad-palindromize without spacing to a square
         k  remove the 1st line

The last k could be removed if the question allowed leading newlines.

\$\endgroup\$
3
  • \$\begingroup\$ Your interpreter site runs fine half of the time and half of the time, the run button seems to do nothing! \$\endgroup\$
    – 0xffcourse
    Commented Sep 15, 2017 at 3:43
  • 1
    \$\begingroup\$ @officialaimm ..huh. It's probably that Processing.js hasn't yet downloaded/transpiled the source. When I get the time I'll make the run button blank out while its loading \$\endgroup\$
    – dzaima
    Commented Sep 15, 2017 at 5:09
  • \$\begingroup\$ ah, makes sense. \$\endgroup\$
    – 0xffcourse
    Commented Sep 15, 2017 at 5:59
1
\$\begingroup\$

Kotlin, 99 93 88 bytes

(('A'..'Y')+'Z'.downTo('A')).map{println((('A'..it-1)+it.downTo('A')).joinToString(""))}

That's still longer than I expected but I doubt I'll be able to golf it further.

Factorisation doesn't save the day, best I could do is 93 bytes :

fun r(a:Char,b:Char)=(a..b-1)+b.downTo(a)
r('A','Z').map{println(r('A',it).joinToString(""))}
\$\endgroup\$

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.