24
\$\begingroup\$

Task

Your task is to print this exact text:

A
BCD
EFGHI
JKLMNOP
QRSTUVWXY
ZABCDEFGHIJ
KLMNOPQRSTUVW
XYZABCDEFGHIJKL
MNOPQRSTUVWXYZABC
DEFGHIJKLMNOPQRSTUV
WXYZABCDEFGHIJKLMNOPQ
RSTUVWXYZABCDEFGHIJKLMN
OPQRSTUVWXYZABCDEFGHIJKLM
NOPQRSTUVWXYZABCDEFGHIJKLMN
OPQRSTUVWXYZABCDEFGHIJKLMNOPQ
RSTUVWXYZABCDEFGHIJKLMNOPQRSTUV
WXYZABCDEFGHIJKLMNOPQRSTUVWXYZABC
DEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL
MNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVW
XYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJ
KLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXY
ZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOP
QRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHI
JKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCD
EFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZA
BCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ

Specs

  • You may do it in all-lowercase instead of all-uppercase.
  • Trailing newlines at the end of the triangle is allowed.
  • Trailing spaces after each line is allowed.
  • You must print to STDOUT instead of outputting an array of strings.

Scoring

This is . Program with lowest byte-count wins.

\$\endgroup\$
  • 1
    \$\begingroup\$ What do you mean by "strikes again"? Was there another challenge you made like this? \$\endgroup\$ – haykam Aug 21 '16 at 13:46
  • \$\begingroup\$ @Peanut codegolf.stackexchange.com/questions/87496/alphabet-triangle \$\endgroup\$ – Beta Decay Aug 21 '16 at 13:58
  • 1
    \$\begingroup\$ Seems fairly trivial do we really need (another) alphabet challenge? \$\endgroup\$ – Rohan Jhunjhunwala Aug 21 '16 at 21:44
  • 2
    \$\begingroup\$ It is a good challenge, but I think we have outstripped saturation of these alphabet challenges, nothing personal. \$\endgroup\$ – Rohan Jhunjhunwala Aug 21 '16 at 21:45
  • \$\begingroup\$ Actually looking for an alphabet challenge that the letter at a position cannot be calculated by simple expressions from its coordinates involving the mod function. May make one myself if I have time. \$\endgroup\$ – Weijun Zhou Jan 31 '18 at 20:17

54 Answers 54

1
\$\begingroup\$

C#, 153 Bytes

using b=System.Console;class a{static void Main(){int i=0,j=0,k=0;while(i<26){b.Write((char)(65+j));j++;j%=26;k++;if(2*i+1==k){b.WriteLine();i++;k=0;}}}}

Compile using Microsoft .NET Framework 2.0 or later. (Written using Visual Studio 2015 Update 3.)

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

Dyalog APL, 31 25 23 bytes

Requires ⎕IO←0, which is default on many systems.

↑(∊1,¨0⍴¨⍨2×⍳26)⊂676⍴⎕A

676⍴⎕A cycle the letters to get 676 of them

(...)⊂ split on ones in

⍳26 zero through 25; {0, 1, 2, 3, ..., 25}

multiply them by 2, {0, 2, 4, 6, ..., 50}

0⍴¨⍨ generate zero-sequences of such lengths; {}, {0}, {0, 0}, etc.

1,¨ prepend one to each sequence; {1}, {1, 0}, {1, 0, 0}, etc.

flatten; {1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, ..., 0}

stack the strings

TryAPL online!

-6 thanks to @jimmy23013

\$\endgroup\$
  • \$\begingroup\$ 26 51⍴(,↑1⍴¨⍨¯1+2×⍳26)\676⍴⎕A \$\endgroup\$ – jimmy23013 Aug 22 '16 at 13:29
  • \$\begingroup\$ ↑(∊1,1,¨0⍴¨⍨2×⍳25)⊂676⍴⎕A \$\endgroup\$ – jimmy23013 Aug 22 '16 at 13:39
1
\$\begingroup\$

Actually, 27 26 22 20 17 bytes

Takes the lowercase alphabet 26 times, prints 1,3,5,...,(2*n+1) at a time. Golfing suggestions welcome. Try it online!

Edit: Many thanks and -4 bytes to Leaky Nun and his suggestions.

úlú*iúl`╜u╟Σ)2╖`n

Ungolfing:

úl    Pushes 26 (the length of the lowercase alphabet).
ú*    26 * the lowercase alphabet.
i     Flatten the string.
úl    Pushes 26.
  `     Start function.
  ╜u    Push register 0 (default: 0) and increment (call it len, from now on)
  ╟     Take len elements from the stack
  Σ     sum() into a string.
  )     Rotate the string to the bottom of the stack.
  2╖    Add 2 to register 0.
  `     End function.
n     Run the above function (26) times.
\$\endgroup\$
1
\$\begingroup\$

05AB1E, 14 13 11 bytes

A27×26L·<£»

Try it online!

Explanation:

A27×         # Push the alphabet repeated 27 times
    26L      # Push [1, 2, ..., 26]
       ·     # Multiply by 2 [2, 4, ..., 52]
        <    # Subtract 1 [1, 3, ..., 51]
         £   # Repeated slice
          »  # Join by newlines
             # Implicit print
\$\endgroup\$
1
\$\begingroup\$

JavaScript (Using external library - Enumerable) (90 88 86 80 bytes)

Link to lib: https://github.com/mvegh1/Enumerable

(z=_.Range)(0,26).WriteLine(x=>z(x*x,2*x+1).Write("",y=>(y%26+10).toString(36)))

Code explanation: Create range of ints 0 to 25, and for each write a new line according to the predicate. For each line, create a range of ints starting at the square of the current int, for a count of 2x+1. Then take that range, and join it into a string delimited by nothing where each int is casted to the String represented by the int ascii code

enter image description here

\$\endgroup\$
  • \$\begingroup\$ I highly doubt that the javascript answer without the library would be longer than this. \$\endgroup\$ – Leaky Nun Aug 21 '16 at 19:49
  • \$\begingroup\$ Exactly. \$\endgroup\$ – Leaky Nun Aug 21 '16 at 19:52
  • \$\begingroup\$ Ill have to optimize my answer ;) \$\endgroup\$ – applejacks01 Aug 21 '16 at 20:22
  • \$\begingroup\$ 86 bytes, bring it on vanilla JS! \$\endgroup\$ – applejacks01 Aug 21 '16 at 21:27
  • \$\begingroup\$ Well, I already had borrowed your %26. Now can you do better? \$\endgroup\$ – edc65 Aug 22 '16 at 13:06
1
\$\begingroup\$

MY-BASIC, 72 bytes

Anonymous function that takes no input and outputs to the console.

For J=1 To 51
For K=1 To J
I=I Mod 26+1
Print Chr(64+I)
Next
Print;
Next

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Pyth, 14 bytes

V26:*26G^N2^hN2

Try it here!

V26             - for N in range(26):
        ^N2     -   N**2
   :*26G        -  (alphabet*26)[^:V]
           ^hN2 -   (N+1)**2
\$\endgroup\$
0
\$\begingroup\$

Java, 109 bytes

for(int i=0,c=-1,j;i<26;i++,System.out.println())for(j=0;j<1+2*i;j++)System.out.print((char)(65+(c=++c%26)));

Slightly ungolfed:

for (int i = 0, c = -1, j; i < 26; i++, System.out.println())
    for (j = 0; j < 1 + 2 * i; j++) System.out.print((char) (65 + (c = ++c % 26)));
\$\endgroup\$
0
\$\begingroup\$

Actually, 18 17 bytes

úl`╜²1╖╜²;ú*Ht`na

Ungolfing:

úl    Pushes 26 (the length of the lowercase alphabet).
  `     Start function
  ╜²    Push register 0 (default: 0) and square. Call this a.
  1╖    Increment register 0.
  ╜²;   Push register 0, square and duplicate. Call this b.
  ú*    b times the lowercase alphabet. Call this repeated_alphabet.
  Ht    Get repeated_alphabet[:b][a:]
  `     End function.
n     Run the above function (26) times.
a     Invert the stack.
      Print the stack implicitly with newlines.

Try it online!

\$\endgroup\$
0
\$\begingroup\$

><>, 59 bytes

<v01'5'&0
+>    :@@:@$-?!v$&:d2*%'A'+o1+&1
 ^0;?=}:{:+2oa~<

This increments one item for each letter, another for how many letters in the current row, and checks that one to a constant to halt the program after the last line of 53 characters

Try it online

\$\endgroup\$
0
\$\begingroup\$

C++, 122 108 bytes

void a(){int a=65,l,i;for(l=1;l<53;l+=2){for(i=0;i<l;i++){std::putchar(a);a>90?a=65:a++;}std::cout<<'\n';}}

First time trying my hand at one of these, so it'll probably be super inefficient.

It creates an integer a, then enters a for loop with l representing the number of characters in a line (stopping when reaching the maximum amount, 53) Inside the loop, it enters another loop based on the value of l, which prints a to the console, then either increments it or sets it back to A. After completing that loop, it prints a newline to extend the pyramid.

EDIT: Improved by changing a from a char to an int, which eliminates the need for (int)a++ among other things and saves precious bytes. Also replaced the while statement with an equivalent for.

\$\endgroup\$
  • \$\begingroup\$ Hi, and welcome to PPCG! Nice first post! \$\endgroup\$ – Rɪᴋᴇʀ Aug 23 '16 at 2:00
0
\$\begingroup\$

Perl 6: 51 bytes

say .join for (|("A".."Z")xx*).rotor(1,3...51)[^26]
\$\endgroup\$
0
\$\begingroup\$

Perl 6: 50 bytes

Regex based solution:

.put for (("A".."Z").join x 26)~~m:g/.**{1+2*$++}/
\$\endgroup\$
0
\$\begingroup\$

Python 3, 83 bytes

[print("".join([chr((i%26)+97)for i in range(j*j,(j+1)*(j+1))]))for j in range(26)]

My first golfing experience.

\$\endgroup\$
0
\$\begingroup\$

Matlab, 81 bytes

b=char('A'+(1:26)-1)';b=repmat(b,1,26);
for j=1:26
disp(b((j-1)*(j-1)+1:j*j))
end
\$\endgroup\$
0
\$\begingroup\$

Racket 160 bytes

(let p((n 65)(t 0)(x 0))(when(> n 90)(set! n 65))(when(> x t)(set! t(+ 2 t))
(set! x 0)(displayln""))(when(< t 51)(display(integer->char n))(p(+ 1 n)t(+ 1 x))))

Ungolfed:

(define (f)
  (let loop ((n 65)
             (t 0)
             (x 0))
    (when (> n 90)
      (set! n 65))
    (when (> x t)
      (set! t (+ 2 t))
      (set! x 0)
      (displayln ""))
    (when (< t 51)
        (display (integer->char n))
        (loop (add1 n) 
              t 
              (add1 x)))))

Testing:

(f)

Output:

A
BCD
EFGHI
JKLMNOP
QRSTUVWXY
ZABCDEFGHIJ
KLMNOPQRSTUVW
XYZABCDEFGHIJKL
MNOPQRSTUVWXYZABC
DEFGHIJKLMNOPQRSTUV
WXYZABCDEFGHIJKLMNOPQ
RSTUVWXYZABCDEFGHIJKLMN
OPQRSTUVWXYZABCDEFGHIJKLM
NOPQRSTUVWXYZABCDEFGHIJKLMN
OPQRSTUVWXYZABCDEFGHIJKLMNOPQ
RSTUVWXYZABCDEFGHIJKLMNOPQRSTUV
WXYZABCDEFGHIJKLMNOPQRSTUVWXYZABC
DEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL
MNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVW
XYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJ
KLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXY
ZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOP
QRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHI
JKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCD
EFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZA
BCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
\$\endgroup\$
0
\$\begingroup\$

Pip, 17 16 bytes

15 bytes of code, +1 for -n flag.

zX26^@(1,27)**2

Try it online!

Explanation:

zX26             Lowercase alphabet, repeated 26 times
    ^@           Split at these indices:
       1,27        Range(1,27), i.e. numbers 1 through 26
      (    )**2    Square each number
                 Autoprint the resulting list, joined on newlines due to -n

My first solution is longer, but I think it's pretty cute:

L26P(zy,Y++++v+y)

Explanation:

L26               Loop 26 times:
      y             y is initially "", which is 0 in numeric context
       ,            Range from y to the following value:
         ++++v        v is initially -1; increment it twice (so it goes 1, 3, 5, ...)
        Y     +y      Add previous y to new v and yank result into y for next iteration
    (z          )   Use that range to get a slice from the lowercase alphabet (with
                    cyclical indexing)
   P                Print the slice (with trailing newline)
\$\endgroup\$
0
\$\begingroup\$

Common Lisp, 139 bytes

(let((a"abcdefghijklmnopqrstuvwxyz"))(do((n 3(+ n 2))(i 0 j)(j 1(+ j n))(b a(format()"~a~a"b a)))((= n 55))(format t"~a~%"(subseq b i j))))

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Yabasic, 63 bytes

Long live BASIC.

For J=1To 51
For K=1To J
I=Mod(I,26)+1
?Chr$(64+I);
Next
?
Next

Try it online!

\$\endgroup\$
0
\$\begingroup\$

uBASIC, 68 bytes

Anonymous function that takes no input and outputs to the console.

That pesky Chr$(...) function is forcing me to use Left$(...,1) again.

0ForI=1To51:ForJ=1ToI:K=KMod26+1:?Left$(Chr$(64+K),1);:NextJ:?:NextI

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Visual Basic .NET (Mono), 136 bytes

Declared Subroutine that takes no input and outputs to the console.

Module M
Sub Main
Dim I,J,K,S
For J=1To 51
S=""
For K=1To J
I=I Mod 26+1
S+=Chr$(64+I)
Next
Console.WriteLine(S)
Next
End Sub
End Module

Try it online!

\$\endgroup\$
0
\$\begingroup\$

K4, 25 bytes

Solution:

-1(0,+\1+2*!25)_676#.Q.A;

Example:

q)k)-1(0,+\1+2*!25)_676#.Q.A;
A
BCD
EFGHI
JKLMNOP
QRSTUVWXY
ZABCDEFGHIJ
KLMNOPQRSTUVW
XYZABCDEFGHIJKL
MNOPQRSTUVWXYZABC
DEFGHIJKLMNOPQRSTUV
WXYZABCDEFGHIJKLMNOPQ
RSTUVWXYZABCDEFGHIJKLMN
OPQRSTUVWXYZABCDEFGHIJKLM
NOPQRSTUVWXYZABCDEFGHIJKLMN
OPQRSTUVWXYZABCDEFGHIJKLMNOPQ
RSTUVWXYZABCDEFGHIJKLMNOPQRSTUV
WXYZABCDEFGHIJKLMNOPQRSTUVWXYZABC
DEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL
MNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVW
XYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJ
KLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXY
ZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOP
QRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHI
JKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCD
EFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZA
BCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ

Explanation:

Slice up a list of the alphabet repeated 26 times...

-1(0,+\1+2*!25)_676#.Q.A; / the solution
-1                      ; / print to STDOUT and swallow return
                    .Q.A  / uppercase alphabet A-Z
                676#      / 676 take from the alphabet
               _          / cut at indexes given by left
  (           )           / do this stuff together
           !25            / range 0..24
         2*               / multiply by 2
       1+                 / add 1
     +\                   / calculate sums of list
   0,                     / prepend 0
\$\endgroup\$
-1
\$\begingroup\$

C#, 164 bytes

void a(){int i=0;Console.Write(String.Join("\n",Enumerable.Range(0,26).Select(n=>new string(Enumerable.Range(0,n*2+1).Select(m=>(char)(97+(i++)%26)).ToArray()))));}
\$\endgroup\$
  • \$\begingroup\$ I believe "\n" is enough instead of "\r\n" \$\endgroup\$ – Leaky Nun Aug 21 '16 at 12:06
  • 1
    \$\begingroup\$ You need to count using System; and using System.Linq; \$\endgroup\$ – LegionMammal978 Aug 21 '16 at 12:06
  • 2
    \$\begingroup\$ no i do not need to count them, theyre default packages. im getting sick of this remark \$\endgroup\$ – downrep_nation Aug 21 '16 at 12:20
  • 3
    \$\begingroup\$ Actually, it seems like you do need to include using System, since otherwise I get an error about Console not existing in the current context. \$\endgroup\$ – Nic Hartley Aug 21 '16 at 19:49
  • 1
    \$\begingroup\$ meta.codegolf.stackexchange.com/questions/9847/… About java but the result is the same, either fully qualify them or include the namespaces \$\endgroup\$ – TheLethalCoder Aug 22 '16 at 10:15
-3
\$\begingroup\$

HTML, 701 bytes

A
BCD
EFGHI
JKLMNOP
QRSTUVWXY
ZABCDEFGHIJ
KLMNOPQRSTUVW
XYZABCDEFGHIJKL
MNOPQRSTUVWXYZABC
DEFGHIJKLMNOPQRSTUV
WXYZABCDEFGHIJKLMNOPQ
RSTUVWXYZABCDEFGHIJKLMN
OPQRSTUVWXYZABCDEFGHIJKLM
NOPQRSTUVWXYZABCDEFGHIJKLMN
OPQRSTUVWXYZABCDEFGHIJKLMNOPQ
RSTUVWXYZABCDEFGHIJKLMNOPQRSTUV
WXYZABCDEFGHIJKLMNOPQRSTUVWXYZABC
DEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL
MNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVW
XYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJ
KLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXY
ZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOP
QRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHI
JKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCD
EFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZA
BCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ

Yes, it's HTML. ;)

\$\endgroup\$
  • 4
    \$\begingroup\$ Unfortunately, this will not work on an HTML page. For newlines, you need to include <br> tags. \$\endgroup\$ – NoOneIsHere Aug 23 '16 at 20:25

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.