24
\$\begingroup\$

Given no input, output this interesting alphabet pattern in either case (the case has to be consistent) via an accepted output method:

A
AB
ACBC
ADBDCD
AEBECEDE
AFBFCFDFEF
AGBGCGDGEGFG
AHBHCHDHEHFHGH
AIBICIDIEIFIGIHI
AJBJCJDJEJFJGJHJIJ
AKBKCKDKEKFKGKHKIKJK
ALBLCLDLELFLGLHLILJLKL
AMBMCMDMEMFMGMHMIMJMKMLM
ANBNCNDNENFNGNHNINJNKNLNMN
AOBOCODOEOFOGOHOIOJOKOLOMONO
APBPCPDPEPFPGPHPIPJPKPLPMPNPOP
AQBQCQDQEQFQGQHQIQJQKQLQMQNQOQPQ
ARBRCRDRERFRGRHRIRJRKRLRMRNRORPRQR
ASBSCSDSESFSGSHSISJSKSLSMSNSOSPSQSRS
ATBTCTDTETFTGTHTITJTKTLTMTNTOTPTQTRTST
AUBUCUDUEUFUGUHUIUJUKULUMUNUOUPUQURUSUTU
AVBVCVDVEVFVGVHVIVJVKVLVMVNVOVPVQVRVSVTVUV
AWBWCWDWEWFWGWHWIWJWKWLWMWNWOWPWQWRWSWTWUWVW
AXBXCXDXEXFXGXHXIXJXKXLXMXNXOXPXQXRXSXTXUXVXWX
AYBYCYDYEYFYGYHYIYJYKYLYMYNYOYPYQYRYSYTYUYVYWYXY
AZBZCZDZEZFZGZHZIZJZKZLZMZNZOZPZQZRZSZTZUZVZWZXZYZ

Trailing spaces and newlines are acceptable, standard loopholes are disallowed, and this happens to be , so the shortest answer in bytes wins!

\$\endgroup\$
  • \$\begingroup\$ Related, Related \$\endgroup\$ – FantaC Jan 13 '18 at 23:18
  • \$\begingroup\$ BTW if I see an amazing answer I will bounty it 50 rep \$\endgroup\$ – FantaC Jan 13 '18 at 23:26
  • 13
    \$\begingroup\$ The leading A really messes things up for me... \$\endgroup\$ – ETHproductions Jan 13 '18 at 23:38
  • 2
    \$\begingroup\$ Some people simply don't like these kind of challenges I think. \$\endgroup\$ – Jonathan Allan Jan 14 '18 at 0:10
  • 1
    \$\begingroup\$ @ETHproductions It simplifies things for me! \$\endgroup\$ – Neil Jan 14 '18 at 0:17

47 Answers 47

5
\$\begingroup\$

Canvas, 7 bytes

Z[K*¹+]

Try it here!

Explanation:

Z[     ] for each prefix of the uppercase alphabet
    K        pop off the last letter
     *       and join the rest of the string with that character
      ¹+     and append the current iterated character to it
\$\endgroup\$
  • \$\begingroup\$ Why didn't you edit your previous answer? \$\endgroup\$ – Neil Jan 17 '18 at 10:03
  • \$\begingroup\$ @Neil good question. Not sure \$\endgroup\$ – dzaima Jan 17 '18 at 10:12
  • \$\begingroup\$ Accepted! You beat Jelly and Charcoal by two bytes! \$\endgroup\$ – FantaC Feb 9 '18 at 15:48
8
\$\begingroup\$

Jelly, 9 bytes

ØAjṪ$Ƥż¹Y

Try it online!

How it works

ØAjṪ$Ƥż¹Y  Main link. No arguments.

ØA         Yield "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
     Ƥ     Map the link to the left over all prefixes, i.e., ["A", "AB", ...].
    $        Combine the two links to the left into a chain.
   Ṫ           Tail; yield and remove the last letter of each prefix.
  j            Join the remainder, using that letter as separator.
      ż¹   Zip the resulting strings and the letters of the alphabet.
        Y  Separate the results by linefeeds.
\$\endgroup\$
  • 2
    \$\begingroup\$ Oh, haha and I was just about to post ØAjṪ$ƤżØAY :D \$\endgroup\$ – Jonathan Allan Jan 13 '18 at 23:43
7
\$\begingroup\$

C, 82 bytes

f(i,j){for(i=!puts("A");++i<26;puts(""))for(j=0;j++<i*2;)putchar(65+(j&1?j/2:i));}

Try it online!

\$\endgroup\$
6
\$\begingroup\$

Charcoal, 9 bytes

Eα⁺⪫…ακιι

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

 α          Predefined uppercase alphabet
E           Map over each character
    …ακ     Get current prefix of alphabet
   ⪫   ι    Join with current character
  ⁺     ι   Append current character
            Implicitly print on separate lines
\$\endgroup\$
5
\$\begingroup\$

R, 50 bytes

l=LETTERS
for(i in 0:25)cat(l[0:i],"
",sep=l[i+1])

Try it online!

Perhaps the cleverest part here is using letters[0] for the empty string to get cat(character(0),'\n',sep="A") to print the first line.

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

Python 2, 56 bytes

n=65;s='';exec'c=chr(n);print c.join(s)+c;s+=c;n+=1;'*26

Try it online!

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

6502 machine code routine (C64), 39 bytes

A9 41 20 D2 FF AA A8 84 FB E4 FB B0 0B 8A 20 D2 FF 98 20 D2 FF E8 D0 F1 A9 0D
20 D2 FF A2 41 C0 5A F0 03 C8 D0 E1 60

Position-independet machine code subroutine, clobbers A, X and Y.

Online demo

The demo loads at $C000, so use SYS49152 to call the routine.


Commented disassembly:

A9 41       LDA #$41            ; 'A'
20 D2 FF    JSR $FFD2           ; Kernal CHROUT (output character)
AA          TAX                 ; copy to X (current pos)
A8          TAY                 ; copy to Y (current endpos)
  .outerloop:
84 FB       STY $FB             ; endpos to temporary
  .innerloop:
E4 FB       CPX $FB             ; compare pos with endpos
B0 0B       BCS .eol            ; reached -> do end of line
8A          TXA                 ; current pos to accu
20 D2 FF    JSR $FFD2           ; and output
98          TYA                 ; endpos to accu
20 D2 FF    JSR $FFD2           ; and output
E8          INX                 ; next character
D0 F1       BNE .innerloop      ; (repeat)
  .eol:
A9 0D       LDA #$0D            ; load newline
20 D2 FF    JSR $FFD2           ; and output
A2 41       LDX #$41            ; re-init current pos to 'A'
C0 5A       CPY #$5A            ; test endpos to 'Z'
F0 03       BEQ .done           ; done when 'Z' reached
C8          INY                 ; next endpos
D0 E1       BNE .outerloop      ; (repeat)
  .done:
60          RTS
\$\endgroup\$
3
\$\begingroup\$

Java 8, 93 91 90 bytes

v->{String t="";for(char c=64;++c<91;t+=c)System.out.println(t.join(c+"",t.split(""))+c);}

-1 byte thanks to @OlivierGrégoire by printing directly instead of returning

Explanation:

Try it online.

v->{                     // Method with empty unused parameter and String return-type
  String t="";           //  Temp-String, starting empty
  for(char c=64;++c<91;  //  Loop over the letters of the alphabet:
      t+=c)              //    After every iteration: append the letter to the temp-String
    System.out.println(  //   Print with trailing new-line:
       r.join(c+"",t.split(""))
                         //    The temp-String with the current letter as delimiter
       +c);}             //    + the current letter as trailing character 
\$\endgroup\$
  • 2
    \$\begingroup\$ 90 bytes (just using stdout instead of returning). \$\endgroup\$ – Olivier Grégoire Jan 15 '18 at 12:19
  • \$\begingroup\$ Nice answer! I ported to C# to see if it was shorter and I get 91 (more if I include System.) :) \$\endgroup\$ – aloisdg Jan 15 '18 at 13:04
3
\$\begingroup\$

SNOBOL4 (CSNOBOL4), 169 143 bytes

i &ucase len(x) . r len(1) . s
 o =
 i =
t r len(i) len(1) . k :f(o)
 o =o s k
 i =i + 1 :(t)
o o s =
 output =o s
 x =lt(x,25) x + 1 :s(i)
end

Try it online!

i &ucase len(x) . r len(1) . s	;* set r to the first x characters and s to the x+1th.
 o =				;* set o,i to empty string
 i =
t r len(i) len(1) . k :f(o)	;* set k to the ith letter of r. on failure (no match), go to o.
 o =o s k			;* concatenate o,s,k
 i =i + 1 :(t)			;* increment i, goto t
o o s =				;* remove the first occurrence of s (the first character for x>1, and nothing otherwise)
 output =o s			;* output o concatenated with s
 x =lt(x,25) x + 1 :s(i)	;* increment x, goto i if x<25.
end

The problem here is the first line

using o s k will add an extra separator character at the beginning of each line and also not have an s at the end. This is OK because line t will jump over the following two lines when x=0. This means that o will still be blank. Hence, o s = will remove the first s character from o, and then we can simply print o s to have the appropriate last s.

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

JavaScript (ES6), 81 bytes

f=
_=>[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ"].map((c,i,a)=>a.slice(0,i).join(c)+c).join`
`
;document.write('<pre>'+f());

Save 9 bytes if a string array return value is acceptable.

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

Japt (-R flag), 14 12 bytes

-2 bytes thanks to @Shaggy

;B¬
ËiU¯E qD

Test it online!

\$\endgroup\$
  • \$\begingroup\$ If only there were a shortcut for s0,! ;p \$\endgroup\$ – Shaggy Jan 14 '18 at 0:31
  • \$\begingroup\$ 12 bytes. But why aren't you counting the -R here? \$\endgroup\$ – Shaggy Jan 14 '18 at 0:37
  • \$\begingroup\$ @Shaggy Oh wow, I knew I was missing something :P The i trick is great, thanks! As for the flag, there appears to be a new consensus that each unique invocation of a program should be considered a separate language. (which makes Japt's flag system seem kind of cheaty...) \$\endgroup\$ – ETHproductions Jan 14 '18 at 1:37
2
\$\begingroup\$

Haskell, 49 48 bytes

'A':unlines[init['A'..x]>>=(:[x])|x<-['A'..'Z']]

Try it online!

Edit: -1 byte thanks to totallyhuman!

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

PowerShell, 56 bytes

"A";65..89|%{([char[]](65..$_)-join[char]++$_)+[char]$_}

Try it online!

Loops 65 to 89, each iteration constructing a char array of 65 to the current number $_, then -joins that array together into a string with the next character, then tacks on that character at the end.

Change the 89 to some other ASCII number to see the behavior better.

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

><>, 44 34 bytes

"BA"oao"ZA"\=?;1+40.
o1+:{::o}=?\:

Try it online!

><>, 44 bytes

"A"o10ao\55*=?;1+40.
1+:{:}=?\:"A"+o{:}"A"+o

Try it online!

As I use a different route to producing the output I've posted my own ><> answer; The other ><> answer can be found here.

Big thanks to Jo king for spotting I didn't need to keep putting "A" onto the stack if I just compared against "Z" instead of 26. (-10 bytes)

Explanation

The explanation will follow the flow of the code.

"BA"                 : Push "BA" onto the stack;
                       [] -> [66, 65]
    oao              : Print the stack top then print a new line;
                       [66, 65] -> [66]
       "ZA"\         : Push "ZA" onto the stack then move down to line 2;
                       [66, 90, 65]
o          \:        : Duplicate the stack top then print
 1+:                 : Add one to the stack top then duplicate;
                       [66, 90, 65, 65]
    {::              : Shift the stack right 1 place then duplicate the stack top twice;
                       [90, 65, 65, 66, 66]
       o}            : Print the stack top then shift the stack left 1 place;
                       [66, 90, 65, 65, 66]
         =?\         : Comparison for equality on the top 2 stack items then move to line 1 if equal otherwise continue on line 2;
                       [66, 90, 65]
           \=?;      : Comparison for equality on the top 2 stack items then quit if equal else continue on line 1;
                       [66]
               1+    : Add 1 to the stack top;
                       [67]
                 40. : Move the code pointer to column 4 row 0 of the code box and continue execution of code. 
\$\endgroup\$
  • \$\begingroup\$ 36 bytes. Your method is much better than mine \$\endgroup\$ – Jo King Jan 16 '18 at 9:41
  • \$\begingroup\$ inb4 "crossed out 44 is still 44 ;(" \$\endgroup\$ – Jo King Jan 16 '18 at 10:02
  • \$\begingroup\$ @JoKing Excellent spot with comparing to Z, only improvement I made was moving line logic and placing the Z in the middle of the stack items to save using those quote marks again. \$\endgroup\$ – Teal pelican Jan 16 '18 at 14:34
1
\$\begingroup\$

Jelly, 12 bytes

ØA;\;€Ṫ$€YFḊ

Try it online!

Bah just got ØAjṪ$ƤżØAY which is a step between this and the already posted solution of Dennis :/

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

Pyth, 13 bytes

+\ajmPjedd._G

Try it here!, Alternative

That leading a though...

\$\endgroup\$
  • 1
    \$\begingroup\$ Good morning :p \$\endgroup\$ – Jonathan Allan Jan 13 '18 at 23:53
  • \$\begingroup\$ @JonathanAllan Morning bro :p You and your inside jokes! \$\endgroup\$ – Mr. Xcoder Jan 13 '18 at 23:57
1
\$\begingroup\$

Jelly, 13 bytes

ØA¹Ƥ+"¹Ṗ€Yṭ”A

Try it online!

Explanation

ØA¹Ƥ+"¹Ṗ€Yṭ”A  Main Link
ØA              Uppercase Alphabet
  ¹Ƥ            Prefixes
    +"¹         Doubly-vectorized addition to identity (uppercase alphabet) (gives lists of lists of strings)
       Ṗ€      a[:-1] of each (get rid of the double letters at the end)
         Y     Join on newlines
          ṭ”A  "A" + the result

partially abuses the way strings and character lists differ in Jelly

\$\endgroup\$
  • \$\begingroup\$ That was quick! \$\endgroup\$ – FantaC Jan 13 '18 at 23:28
  • \$\begingroup\$ @tfbninja ehhh, 11 mins is ok for Jelly. thanks though :P \$\endgroup\$ – HyperNeutrino Jan 13 '18 at 23:29
  • \$\begingroup\$ You can replace your second ØA with ¹ (like Dennis's) \$\endgroup\$ – Jonathan Allan Jan 14 '18 at 0:04
  • \$\begingroup\$ @JonathanAllan oh cool, thanks! \$\endgroup\$ – HyperNeutrino Jan 14 '18 at 0:05
1
\$\begingroup\$

Python 2, 92 86 79 75 64 bytes

s=map(chr,range(65,91))
for d in s:print d.join(s[:ord(d)-65])+d

Try it online!

11 bytes thx to Rod.

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

APL+WIN, 51 bytes

⍎∊'a←⎕av[65+⍳26]⋄a[n←1]',25⍴⊂'⋄,⊃a[⍳n-1],¨a[n←n+1]'

Explanation:

a←⎕av[65+⍳26] create a vector of upper case letters

a[n←1] first A

25⍴⊂'⋄,⊃a[⍳n-1],¨a[n←n+1]' create an implicit loop to concatenate subsequent letters
\$\endgroup\$
1
\$\begingroup\$

><>, 47 bytes

d2*:1-v
-&$:?!\$:&$:1
1-:?!v\69*-$1-:
+*88~< 1o

Try it online!

How It Works:

d2*:1-v Initialise the stack with 26 (outer loop counter) and 26-1 (inner loop counter)
....
....
....

....
-&$:?!\$:&$:1 Repeatedly make copies of both counters
....          And decrement the inner loop counter
....          Go to third line when inner loop counter is 0

....            Add -54 to the stack (for the newline) and decrement the outer loop counter
....            Initialise the inner loop counter as outer-1
1-:?!v\69*-$1-: If the inner counter is 0, go to the fourth line, else back to the second.
....

....
....      
....      Transform numbers and -54s into letters and newlines by adding 64
+*88~< 1o Output each character until it runs out of stack and errors
\$\endgroup\$
1
\$\begingroup\$

Acc!!, 84 bytes

This is actually what inspired this challenge:

Write 65
Count i while i-26 {
Count b while b-i {
Write b+65
Write i+65
}
Write 10
}

Try it online!

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

Canvas, 11 10 bytes

Z{Z²╷m¹*×]

Try it here!

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

GNU M4, 119 bytes

The worst so far. Well, time's already spent…

define(f,`ifelse($1,$2,,`format(%c%c,$1,$2)`'f(incr($1),$2)')')define(g,`f(65,$1)ifelse($1,90,,`
g(incr($1))')')A
g(66)
\$\endgroup\$
1
\$\begingroup\$

Husk, 13 bytes

Γ·:mhSzJḣ…"AZ

Try it online!

Explanation

This leading A really messes things up -.-

          "AZ  -- string literal: "AZ"
         …     -- fill gaps: "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
     S         -- with alphabet and
        ḣ      -- | alphabet rangified: ["A","AB","ABC",…,"AB……XYZ"]
      zJ       -- : zipWith join: ["A","ABB","ACBCC","ADBDCDD",…,"AZB……ZYZZ"]
Γ              -- pattern match (x:xs) with the following function (x is "A" and xs ["ABB","ACBCC",…,"A……ZYZZ"]
 · mh          -- | drop the last element of each element of xs: ["AB","ACBC",…,"A……ZYZ"]
  :            -- | cons (construct list): ["A","AB","ACBC",…,"A……ZYZ"]
               -- : strings are printed implicitly
\$\endgroup\$
1
\$\begingroup\$

C# (.NET Core)

Port from Kevin Cruijssen's answer:

91 90 bytes

_=>{var t="";for(char c='@';++c<91;t+=c)Console.WriteLine(string.Join(c+"",t.Skip(0))+c);}

Try it online!

132 122 110 109 104 103 bytes

_=>"ABCDEFGHIJKLMNOPQRSTUVWXYZ".Select((c,i)=>string.Join(""+c,"ABCDEFGHIJKLMNOPQRSTUVWXYZ".Take(i))+c)

Try it online!

  • Replace () with _ to show that we declare an unused variable. Thank you Kevin Cruijssen.
\$\endgroup\$
1
\$\begingroup\$

Jelly, 22 bytes

ØAż€Ð€`F€µJ’Ḥ»1ż@¹ḣ/€Y

Try it online!

How it works:

                       take argument implicitly
ØA                     the uppercase alphabet
    Ѐ`                for C in the alphabet
  ż€                     appends C to every letter in the alphabet
       F€              flatten every sublist
          J            get indices
           ’           subtract 1
            Ḥ          and double
             »1        take max([n, 1])
         µ     ż@¹     interleave alphabet list and indices
                  ḣ/€  reduce on head() for each element
                     Y join on newline
                       implicitly output
\$\endgroup\$
1
\$\begingroup\$

uBASIC, 80 bytes

Anonymous function that takes no input and outputs to the console

0?"A":ForI=65To89:ForJ=65ToI:?Left$(Chr$(J),1)+Left$(Chr$(I+1),1);:NextJ:?:NextI

Try it online!

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

Visual Basic .NET (Mono), 134 bytes

Declared function that takes no input and outputs to the console

Module M
Sub Main
Dim S,I,J
S="A"
For I=65To 90
Console.WriteLine(S)
S=""
For J=65To I
S+=Chr(J)+Chr(I+1)
Next
Next
End Sub
End Module

Try it online!

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

Ruby, 44 34 bytes

?A.upto(?Z){|w|puts [*?A...w]*w+w}

Try it online!

Thanks benj2240 for getting it down to 37 bytes. And of course crossed out 44 blah blah.

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

05AB1E, 29 bytes

'A,Au©.sRí¦®RSDgÝ×Rs)ø˜.Bíø»=

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.