26
\$\begingroup\$

Your task is to print this exact text:

            z
            yz
           xyz
           wxyz
          vwxyz
          uvwxyz
         tuvwxyz
         stuvwxyz
        rstuvwxyz
        qrstuvwxyz
       pqrstuvwxyz
       opqrstuvwxyz
      nopqrstuvwxyz
      mnopqrstuvwxyz
     lmnopqrstuvwxyz
     klmnopqrstuvwxyz
    jklmnopqrstuvwxyz
    ijklmnopqrstuvwxyz
   hijklmnopqrstuvwxyz
   ghijklmnopqrstuvwxyz
  fghijklmnopqrstuvwxyz
  efghijklmnopqrstuvwxyz
 defghijklmnopqrstuvwxyz
 cdefghijklmnopqrstuvwxyz
bcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz

Case does not matter.

Remember, this is , so the code with the smallest number of bytes wins.

\$\endgroup\$
12
  • 2
    \$\begingroup\$ Why the downvotes? \$\endgroup\$
    – Oliver Ni
    Commented Oct 25, 2016 at 23:31
  • 20
    \$\begingroup\$ I suspect some people are just tired of all the alphabet-pattern ascii-art KC challenges. \$\endgroup\$
    – xnor
    Commented Oct 26, 2016 at 0:21
  • \$\begingroup\$ Can we do it in uppercase? \$\endgroup\$
    – Downgoat
    Commented Oct 26, 2016 at 3:43
  • 7
    \$\begingroup\$ Seriously though, another alphabet challenge? \$\endgroup\$ Commented Oct 26, 2016 at 12:57
  • 2
    \$\begingroup\$ I enjoy these alphabet challenges. This one could easily re-branded as a Christmas tree. \$\endgroup\$
    – Pete Arden
    Commented Nov 18, 2016 at 21:49

51 Answers 51

1
2
0
\$\begingroup\$

QBIC, 57 bytes

[25,0,-1|Y=Z[1,a/2|Y=Y+@ |]X=Z[a,25|X=X+$CHR$(65+|c)]?Y+X

This one works surprisingly well with QBIC' FOR loops. Explanation (of previous version - same principle applies):

[26,1,-1|          Loops from 26 to 1, decrementing 'a'
                   'a' is used to determine the number of spaces per line and the last letter we want to print
Y=Z                Z is always an empty string in this program, 
                   Y will hold the spaces we need to center this line
[1,a/2|Y=Y+@ |]    Add a space to Y equal to half the value of 'a', giving us a center alignment
X=Z                X holds the characters we need on this line, reset it
[a,26|             FOR c = a to 26 --> loop over the last part of the alphabet
X=X+$CHR$(64+|c)]  Convert c+64 to ASCII and append
?Y+X               Print the spaces and the letters

<outer FOR loop is closed by QBIC>

Output:

            Z
            YZ
           XYZ
           WXYZ
          VWXYZ
          UVWXYZ
         TUVWXYZ
         STUVWXYZ
        RSTUVWXYZ
        QRSTUVWXYZ
       PQRSTUVWXYZ
       OPQRSTUVWXYZ
      NOPQRSTUVWXYZ
      MNOPQRSTUVWXYZ
     LMNOPQRSTUVWXYZ
     KLMNOPQRSTUVWXYZ
    JKLMNOPQRSTUVWXYZ
    IJKLMNOPQRSTUVWXYZ
   HIJKLMNOPQRSTUVWXYZ
   GHIJKLMNOPQRSTUVWXYZ
  FGHIJKLMNOPQRSTUVWXYZ
  EFGHIJKLMNOPQRSTUVWXYZ
 DEFGHIJKLMNOPQRSTUVWXYZ
 CDEFGHIJKLMNOPQRSTUVWXYZ
BCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
\$\endgroup\$
2
  • \$\begingroup\$ Doesn't match the OP. \$\endgroup\$ Commented Oct 26, 2016 at 17:43
  • \$\begingroup\$ @carusocomputing it does now. \$\endgroup\$
    – steenbergh
    Commented Oct 26, 2016 at 21:50
0
\$\begingroup\$

Racket 137 bytes

(for((n(range 122 96 -1)))(for((i(floor(/(- n 97)2))))(display #\space))
(for((i(range n 123)))(display(integer->char i)))(displayln ""))

Ungolfed:

(define (f)
  (for ((n (range 122 96 -1)))
       (for ((i (floor(/(- n 97)2))))
         (display #\space))
       (for ((i (range n 123)))
         (display (integer->char i)))
    (displayln "")))

Testing:

(f)

Output:

            z
            yz
           xyz
           wxyz
          vwxyz
          uvwxyz
         tuvwxyz
         stuvwxyz
        rstuvwxyz
        qrstuvwxyz
       pqrstuvwxyz
       opqrstuvwxyz
      nopqrstuvwxyz
      mnopqrstuvwxyz
     lmnopqrstuvwxyz
     klmnopqrstuvwxyz
    jklmnopqrstuvwxyz
    ijklmnopqrstuvwxyz
   hijklmnopqrstuvwxyz
   ghijklmnopqrstuvwxyz
  fghijklmnopqrstuvwxyz
  efghijklmnopqrstuvwxyz
 defghijklmnopqrstuvwxyz
 cdefghijklmnopqrstuvwxyz
bcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
\$\endgroup\$
0
\$\begingroup\$

C#, 175 Bytes:

Golfed:

string H(){string o="",a="abcdefghijklmnopqrstuvwxyz";int p=12,i=0;for(i=0;i<=26;i++){o+=a.Substring(26-i,i).PadLeft(p+i)+"\n";if(i==0||i==1)continue;p-=i%2==0?1:0;}return o;}

Ungolfed:

public string H()
{
  string o = "", a = "abcdefghijklmnopqrstuvwxyz";
  int p = 12, i=0;
  for (i = 0; i <= 26; i++)
  {
    o += a.Substring(26 - i, i).PadLeft(p+i)+ "\n";
    if (i == 0 || i == 1) continue;
    p -= i % 2 == 0 ? 1 : 0;
  }
  return o;
}

Test:

Console.Write(new DrawAnAlphabetHat().H());

Output:

            z
            yz
           xyz
           wxyz
          vwxyz
          uvwxyz
         tuvwxyz
         stuvwxyz
        rstuvwxyz
        qrstuvwxyz
       pqrstuvwxyz
       opqrstuvwxyz
      nopqrstuvwxyz
      mnopqrstuvwxyz
     lmnopqrstuvwxyz
     klmnopqrstuvwxyz
    jklmnopqrstuvwxyz
    ijklmnopqrstuvwxyz
   hijklmnopqrstuvwxyz
   ghijklmnopqrstuvwxyz
  fghijklmnopqrstuvwxyz
  efghijklmnopqrstuvwxyz
 defghijklmnopqrstuvwxyz
 cdefghijklmnopqrstuvwxyz
bcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
\$\endgroup\$
0
\$\begingroup\$

Javascript, 133 Bytes

for(i=26,s="";i>0;i--){for(k=26-i+Math.floor((i+1)/2),l=34+Math.floor((i+1)/2);k>0;k--,l--)k>27-i?s+=" ":s+=l.toString(36);s+="<br>"}

Try it here

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

Pyke, 18 12 bytes

26Fed*Gi>+)X

Try it here!

26F       )  -  for i in range(26):
   ed*       -    (i//2)*" "
         +   -   concatenate ↑ and ↓
      Gi>    -    alphabet[i:]
           X - splat(^) (print list reversed with newlines)

Or 10 bytes noncompetitive

26DXF2GR>c

Try it here!

\$\endgroup\$
3
  • \$\begingroup\$ Is it splat or split? \$\endgroup\$ Commented Oct 26, 2016 at 13:23
  • \$\begingroup\$ @EriktheGolfer it is splat. It pops a list and pushes the contents of that list in reverse to the stack \$\endgroup\$
    – Blue
    Commented Oct 26, 2016 at 13:26
  • \$\begingroup\$ Okay, putting the spellcheck edit in. \$\endgroup\$ Commented Oct 26, 2016 at 13:29
0
\$\begingroup\$

SOGL V0.12, 8 bytes

z{Xf}¹№╚

Try it Here!

Explanation:

z         push the lowercase alphabet
 {  }     for each, pushing current character
  X         remove the character from the stack as it's not needed
   f        push the remaining string, including the current character, what the loop has to traverse
     ¹    wrap all that in an array
      №   reverse vertically
       ╚  center horizontally - this centers it exactly as required :D
\$\endgroup\$
0
\$\begingroup\$

VBA, 68 66 Bytes

Anonymous VBE immediate function that takes no input and outputs to the VBE immediate window

For i=1To 26:?:?Spc(13-i/2);:For j=27-i To 26:?Chr(j+96);:Next j,i
\$\endgroup\$
0
\$\begingroup\$

C# (Visual C# Compiler), 125 bytes

()=>{var s="";for(var c='z';c>'`';c--){for(var i='a';i<'{';i++)s+=i<c?' ':i;s+="\n";}Console.WriteLine(s.Replace("  "," "));}

Try it online!

Highlights: seen how char is a numeric datatype, let's use it for the loop. The value ranges from 'a' to 'z', which is awesome! We can just add a char to a string, so that's another back-curling - but now convenient - feature.

The outer counter counts from z to a, the inner counter from a to z. The inner loop checks if the inner counter is more than the outer, if so print a space, else print the counter character. After every outer iteration we print a newline, after the function completes we print it to the console after replacing a double space with a single one (very, very wasteful line, but included in character count).

I couldn't think of any more abuse in a language specification than this.

EDIT: added lambda function specification and call in accordance to alois' remark.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Hello fellow C# golfer. We are not allowed to post a snippet, but we can use a function and lamda are allowed. source. \$\endgroup\$
    – aloisdg
    Commented Nov 16, 2017 at 17:21
  • \$\begingroup\$ Got it, alois. Sorry for being too short through. Are we allowed to not print but output the text, and leave the printing and line breaking to an outside-the-function loop-and-print? If so, i'll have a go at shaving off those characters again! Thanks dude, \$\endgroup\$
    – Barodus
    Commented Nov 17, 2017 at 12:14
  • \$\begingroup\$ most of the time we can, but here OP want to output a string with "\n"... \$\endgroup\$
    – aloisdg
    Commented Nov 18, 2017 at 11:03
0
\$\begingroup\$

Ruby, 54 bytes

puts (0..25).map{|c|[*(90-c).chr..'Z'].join.center 26}

Try it online!

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

F# (.NET Core), 101 bytes

[0..25]|>Seq.map(fun i->"".PadLeft(12-i/2)+"abcdefghijklmnopqrstuvwxyz".[25-i..])|>String.concat "\n"

Try it online!

A naive port of my C# answer

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

Charcoal, 16 bytes

F²⁷«P⮌…⮌βι¿﹪ι²↓↙

Try it online!

Link is to the verbose version of the code. I'm sure there must be a shorter way to do this in Charcoal.

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

J, 39 bytes

echo(' '<@#"0~2#i._13),&><@|.\u:90-i.26

Try it online!

I see capital letters in some submissions so I assume it's OK to use them. If not, then add a byte to convert to lowercase.

Explanation

See my (almost identical) answer to this (duplicate) question.

The only difference is in generating the alphabet, where I generate ZYX...CBA and then reverse each prefix of that string to give the desired parts. I feel like there is a way to avoid that but I'm tired right now and this is the best way of fixing it that I could think of.

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

Yabasic, 82 bytes

A jolly solution that takes no input and outputs to the console.

For i=1To 26
For j=1To 13-i/2
?" ";
Next
For j=27-i To 26
?Chr$(j+96);
Next
?
Next

Try it online!

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

uBASIC, 75 bytes

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

Slightly different approach than other BASIC answers as uBASIC's integer division functions differently - (25/2 equals 12 rather than 13)

0ForI=2To27:?Tab(13-I/2);:ForJ=28-ITo26:?Left$(Chr$(J+96),1);:NextJ:?:NextI

Try it online!

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

APL (Dyalog Classic), 20 bytes

(⌈13-.5×⍳26)⌽⌽↑,\⌽⎕a

Try it online!

uses ⎕io←1

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

Gol><>, 22 bytes

asFa`z9sL-F:M|L2,R` |H

Try it online!

How it works

asFa`z9sL-F:M|L2,R` |H

asF                 |   Repeat 26 times...
   a                      Push 10 (\n)
    `z                    Push z
      9sL-F  |            Repeat (25 - loop counter(L)) times...
           :M               Clone the top and decrement
              L2,R        Repeat (L / 2) times...
                  `         Push 32 (space)
                     H  Output the entire content (top to bottom) and halt

Basically, this constructs the entire output backwards.

There are two division operators in Gol><>, namely , (floating division) and S, (integer division). Luckily R (repeat X times) floors its argument, so I could save a byte.

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

Java 10: 136 bytes

GOLFED

for(int i=25;i>=0;i--){for(int j=0;j<i/2;j++){System.out.print(" 
");}System.out.println("abcdefghijklmnopqrstuvwxyz".substring(i,26));}}

UNGOLFED

class a {
    public static void main(String[] args) {
        for (int i = 25; i >= 0; i--) {
            for (int j = 0; j < i/2; j++) {
                System.out.print(" ");
            }
            System.out.println("abcdefghijklmnopqrstuvwxyz".substring(i,26));
        }
    }
}

RESULTS

            z
            yz
           xyz
           wxyz
          vwxyz
          uvwxyz
         tuvwxyz
         stuvwxyz
        rstuvwxyz
        qrstuvwxyz
       pqrstuvwxyz
       opqrstuvwxyz
      nopqrstuvwxyz
      mnopqrstuvwxyz
     lmnopqrstuvwxyz
     klmnopqrstuvwxyz
    jklmnopqrstuvwxyz
    ijklmnopqrstuvwxyz
   hijklmnopqrstuvwxyz
   ghijklmnopqrstuvwxyz
  fghijklmnopqrstuvwxyz
  efghijklmnopqrstuvwxyz
 defghijklmnopqrstuvwxyz
 cdefghijklmnopqrstuvwxyz
bcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
\$\endgroup\$
3
  • \$\begingroup\$ Welcome to PPCG! One thing: your code doesn't seem to run, on TIO at least. Also, it's a good idea to add a TIO link to your answer. \$\endgroup\$
    – Chris
    Commented Apr 27, 2018 at 7:42
  • 7
    \$\begingroup\$ Your current GOLFED submission seems to be a snippet, which is not allowed here. What you can do to make this a valid submission is to convert this into a function, which can be done in 139 bytes. \$\endgroup\$
    – ovs
    Commented Apr 27, 2018 at 8:20
  • \$\begingroup\$ Not an expert with Java, but can't you use the repeat function for 109 bytes? \$\endgroup\$
    – Jo King
    Commented Oct 8, 2018 at 10:04
0
\$\begingroup\$

PHP, 68 58 57 bytes

edit #1: a different approach with left padding and string concatenation + uppercase
edit #2: shorter padding expression

while($i++<26)printf("
%".($i+26>>1).s,$s=chr(91-$i).$s);

Add two bytes if a leading newline is disallowed:

while($i++<26)printf("%".($i+26>>1)."s
",$s=chr(91-$i).$s);

Run with -nr or try them online.

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

Canvas, 6 bytes

z±[±]r

Try it here!

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

Japt -R, 7 bytes

;CÔåi û

Test it

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

Elixir, 99 bytes

import Enum
reduce 25..0,'            ',&(IO.puts(&2++slice(?a..?z,&1,26))&&rem(&1,2)>0&& &2||tl&2)

Try it online!

Trying to find another way to generate the space string but can't make anything shorter...

\$\endgroup\$
1
2

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.