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

48 Answers 48

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\$
  • \$\begingroup\$ Is it splat or split? \$\endgroup\$ – Erik the Outgolfer Oct 26 '16 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 Oct 26 '16 at 13:26
  • \$\begingroup\$ Okay, putting the spellcheck edit in. \$\endgroup\$ – Erik the Outgolfer Oct 26 '16 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\$
  • 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 says Reinstate Monica Nov 16 '17 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 Nov 17 '17 at 12:14
  • \$\begingroup\$ most of the time we can, but here OP want to output a string with "\n"... \$\endgroup\$ – aloisdg says Reinstate Monica Nov 18 '17 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\$
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\$
  • \$\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 Apr 27 '18 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 Apr 27 '18 at 8:20
  • \$\begingroup\$ Not an expert with Java, but can't you use the repeat function for 109 bytes? \$\endgroup\$ – Jo King Oct 8 '18 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\$
-1
\$\begingroup\$

Powershell 90 80 Bytes

Non-competing, broken output.

Saved 10 bytes by piping into a pipeline instead of a dumb loop with an extra variable.

90..65|%{$s=(($_..90|%{[char]$_})-join"");$l=$s.length;$s.PadLeft((26-$l)/2+$l)}

Partially golfed:

90..65 | % { # loop down from Z-A char codes
    $s = ( ($_..90 | % { [char]$_ } ) -join "" ) # go from the current pipeline char through to Z, join the array at the end into a string and store in $s
    $l = $s.length # get the length of the string
    $s.PadLeft( ( 26-$l ) / 2 + $l  ) # 'center' the string by padding left and output
}

$c=91;1..26|%{$c--;$s=(($c..90|%{[char]$_})-join"");$l=$s.length;$s.PadLeft((26-$l)/2+$l)}

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\$
  • \$\begingroup\$ Sadly, this doesn't work. Because of how PowerShell does Banker's Rounding by default, the .PadLeft gives 3 lines the same length, then one, then three, then one, etc., whereas the challenge requests two lines each. \$\endgroup\$ – AdmBorkBork Oct 28 '16 at 13:03
  • \$\begingroup\$ @TimmyD ah thanks for pointing that out. just spent 10 minutes trying to find a short way of doing it, but without doing a weird manual count and a switch ($x%3){0{}1{}) type of thing i'm out of ideas. \$\endgroup\$ – colsw Oct 28 '16 at 13:45
  • \$\begingroup\$ Does not match the text in the question. \$\endgroup\$ – Oliver Ni Nov 2 '16 at 23:45
  • \$\begingroup\$ should be 1,1,2,2,3,3,etc. not 1,2,2,3,3,etc. \$\endgroup\$ – Oliver Ni Nov 2 '16 at 23:45
  • \$\begingroup\$ Yeah i've marked this as non-competing, if another powershell golfer can find a way to get around the broken rounding I'll update this. \$\endgroup\$ – colsw Nov 3 '16 at 9:44

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.