Draw an alphabet party hat

22

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.

Oliver Ni

Posted 2016-10-25T22:37:34.043

Reputation: 9 650

2Why the downvotes? – Oliver Ni – 2016-10-25T23:31:16.200

19I suspect some people are just tired of all the alphabet-pattern ascii-art KC challenges. – xnor – 2016-10-26T00:21:50.687

Can we do it in uppercase? – Downgoat – 2016-10-26T03:43:06.777

@Downgoat Yes.. – Oliver Ni – 2016-10-26T03:46:30.383

Also, can we output an array of lines rather than join them by newlines? – Downgoat – 2016-10-26T03:56:14.330

@Downgoat You need to join it by newlines. – Oliver Ni – 2016-10-26T04:03:58.297

7Seriously though, another alphabet challenge? – Erik the Outgolfer – 2016-10-26T12:57:45.827

Also, can I print trailing newlines? – Erik the Outgolfer – 2016-10-26T13:19:36.833

@EriktheGolfer Yes – Oliver Ni – 2016-10-26T18:13:46.340

2I enjoy these alphabet challenges. This one could easily re-branded as a Christmas tree. – Pete Arden – 2016-11-18T21:49:02.557

Halp its my birthday and I do not freakin' want to learn ABCs again – Matthew Roh – 2017-03-25T02:53:37.143

Can I print a leading newline? – Titus – 2018-04-29T09:48:39.087

Answers

6

Cheddar, 50 45 42 37 bytes

25|>0=>i->print" "*(i/2|0)+(65+i)@"90

Straightforward, but utilizes cheddar's consise ranging syntax (both numerical and alphabetical)

Try it online!

Explanation

25 |> 0 =>    // Map range [0, 26) (i.e. [25, 0] reversed) over....
   i -> 
     print    // Prints in it's own line...
     " " * (i/2 |0) +     // Number of spaces is floor(n/2).
                          // `|0` for flooring is hack from JS
     (65 + i) @" 90       // Char code range is this

65 is char code for A and 90 for A

Downgoat

Posted 2016-10-25T22:37:34.043

Reputation: 27 116

1Z is 90, not A. – Mego – 2016-10-26T04:37:22.607

5

05AB1E, 15 13 bytes

A.svy12N;ï-ú,

Try it online! (slightly different from above as ú isn't on TIO yet)

Explanation

  1. Push alphabet
  2. Compute the suffixes of the alphabet
  3. Prepend 12-index/2 spaces
  4. Print

Emigna

Posted 2016-10-25T22:37:34.043

Reputation: 50 798

4

Python 2, 70 bytes

Ported from Emigna's answer, -2 bytes for replacing -i-1 with ~i

for i in range(26):print' '*(12-i/2)+"abcdefghijklmnopqrstuvwxyz"[~i:]

Karl Napf

Posted 2016-10-25T22:37:34.043

Reputation: 4 131

I'm fairly sure using map can yield a shorter alphabet, except maybe lowercase having higher values – Destructible Lemon – 2016-10-26T03:25:56.580

Actually I'm not sure anymore. I think it wouldn't work for this anyway :( soz – Destructible Lemon – 2016-10-26T03:34:23.243

4

R, 67 66 59 bytes

EDIT: Saved a couple of bytes thanks to @rturnbull

for(i in 25:0)cat(rep(" ",i/2),letters[i:25+1],"\n",sep="")

Exploiting the fact that any number passed to the rep function is automatically rounded down to the closest integer (e.g. rep("*",1.99) => "*") which means that the actual sequence passed is floor(13-1:26/2):

12 12 11 11 10 10  9  9  8  8  7  7  6  6  5  5  4  4  3  3  2  2  1  1  0  0

Billywob

Posted 2016-10-25T22:37:34.043

Reputation: 3 363

1This comes out shorter than my matrix attempt. Replace 14...-1 with 13? – JDL – 2016-10-26T10:23:44.543

@JDL Ah yes of course. A remnant of attempting another approach – Billywob – 2016-10-26T11:00:24.770

2If you loop through 25:0 instead of 1:26, you can change 13-i/2 to i/2, and simplify (27-i):26 to i:25+1, saving 6 bytes. – rturnbull – 2016-10-26T14:54:12.427

3

JavaScript (ES6), 85 75 69 68 bytes

for(s=a='',x=36;--x>9;)s+=` `.repeat(x/2-5)+(a=x.toString(36)+a)+`
`

-1 byte thanks to @l4m2.

darrylyeo

Posted 2016-10-25T22:37:34.043

Reputation: 6 214

2Isn't this a snippet rather than a function or program? – Neil – 2016-10-27T12:35:24.227

1for(s=a='',x=36;--x>9;)s+=` `.repeat(x/2-5)+(a=x.toString(36)+a)+'#' 1B shorter – l4m2 – 2018-01-05T11:38:42.983

@l4m2 Brilliant! – darrylyeo – 2018-01-07T03:15:35.233

1Nice idea using base 36! +1 – Titus – 2018-04-29T15:38:56.680

3

Python 2, 52 bytes

n=26;s=''
while n:n-=1;s=chr(97+n)+s;print n/2*' '+s

Accumulates the string s to print and updates the number of leading spaces n/2. A while loop terminating at 0 is a rare numerical loop than beats an exec loop (53 bytes):

n=26;s=''
exec"n-=1;s=chr(97+n)+s;print n/2*' '+s;"*n

Also a 53-byte alternative:

s=''
exec"s=chr(122-len(s))+s;print s.center(26);"*26

xnor

Posted 2016-10-25T22:37:34.043

Reputation: 115 687

3

Pyth, 15 bytes

j_m+*/d2\ >GdUG

A program that prints the result to STDOUT.

Try it online

How it works

j_m+*/d2\ >GdUG  Program
             UG  Yield [1, 2, 3, 4, ..., 26]
  m              Map over the range with variable d:
          >Gd      Yield alphabet with first d-1 letters discarded
   +               Prepend
     /d2             d//2
    *   \            spaces
 _               Reverse
j                Join on newlines
                 Implicitly print

TheBikingViking

Posted 2016-10-25T22:37:34.043

Reputation: 3 674

Try ; instead of \ – isaacg – 2016-10-26T05:17:03.930

2

05AB1E, 5 bytes

A.s.c

Try it online!

A.s.c
A     Push 'abcdefghijklmnopqrstuvwxyz'
 .s   Push suffixes starting from the shortest one
   .c Centralize focused on the left

Erik the Outgolfer

Posted 2016-10-25T22:37:34.043

Reputation: 38 134

2

Jelly, 15 13 bytes

-2 bytes thanks to @miles (formed a niladic chain I suspected existed but did not form)

ØaJ’H⁶ẋżṫJ$ṚY

TryItOnline!

How?

ØaJ’H⁶ẋżṫJ$ṚY - Main link
Øa            - alphabet yield -> ['a', 'b', 'c', ..., 'y', 'z']
  J           -    range(length)      -> [1, 2, 3, ..., 25, 26]
   ’          -    decrement          -> [0, 1, 2, ..., 24, 25]
    H         -    halve              -> [0,.5  1, ..., 12, 12.5]
     ⁶        -    literal [' ']
      ẋ       -    repeat list        -> [[], [], [' '], ..., 12x' ', 12x' ']
          $   - last two links as a monad
         J    -     range(length)     -> [1, 2, 3, ..., 25, 26]
        ṫ     -     tail (vectorises) -> [['a'-'z'], ['b'-'z'], ..., ['y','z'], ['z']]
       ż      - zip
              -> [[[],['a'-'z']], [[],['b'-'z']], ..., [12x' ',['y','z']], [12x' ',['z]]]
           Ṛ  - reverse whole array
            Y - join with line feeds (implicit print)

Jonathan Allan

Posted 2016-10-25T22:37:34.043

Reputation: 67 804

I found a way to form a niladic chain starting with the alphabet ØaJ’H⁶ẋżṫJ$ṚY that saves 2 bytes – miles – 2016-10-26T01:54:32.900

Do you think the explanation is correct? – Jonathan Allan – 2016-10-26T17:08:04.017

1Yeah just think of it as a monadic chain with a single argument being the alphabet – miles – 2016-10-26T17:41:46.137

2

Brain-Flak, 244 bytes

((((((()()()()())){}{}){}){}()){})((((()()()){}){}()){}){(({}[()]<>)<({}<(<>({})<>)>){({}[()]<(({})[()])>)}({}({})<>[({})]<>(((()()()){}){}){}())((<>)<>{<({}[()])><>([{}]())<>}<>[{}]<>{}){({}[()]<((((()()()()){}){}){})>)}((()()()()()){})><>)}<>

Try it online!


This should be readable enough as is. If you need it, I have a full explanation:

push 122 (z): ((((((()()()()())){}{}){}){}()){})
push 26:      ((((()()()){}){}()){})
loop 26 times (i = 25..0): {
 (
  i--, push to b stack:({}[()]<>)
  <
   put 122 from a stack under i: ({}<(<>({})<>)>)
   i times push letter-1: {({}[()]<(({})[()])>)}
   replace top 0 with 26-i: ({}({})<>[({})]<>(((()()()){}){}){}())
   devide by two: ((<>)<>{<({}[()])><>([{}]())<>}<>[{}]<>{})
   add spaces: {({}[()]<((((()()()()){}){}){})>)}
   push 10 (\n): ((()()()()()){})
  >
  flip stack back: <>
 push i--: ) 
}
flip to results stack: <>

MegaTom

Posted 2016-10-25T22:37:34.043

Reputation: 3 787

4This should be readable enough as is. You are talking about Brain-Flak, right? – Erik the Outgolfer – 2016-10-26T17:13:32.710

2

C, 72 68 bytes

m(i){for(char*k=&k[i=26];i;printf("%*c%s\n",--i/2+1,0,k))*--k=64+i;}

o79y

Posted 2016-10-25T22:37:34.043

Reputation: 509

1

Common Lisp, SBCL, 83 82 bytes

(dotimes(i 27)(format t"~26:@<~a~>
"(subseq"ABCDEFGHIJKLMNOPQRSTUVWXYZ"(- 26 i))))

Explanation

(dotimes(i 27) ; loop from i=0 to i=26
(format t"~26:@<~a~>
"(subseq"ABCDEFGHIJKLMNOPQRSTUVWXYZ"(- 26 i))))
;print out part of alphabet starting from character number 26-i (counting from zero)
;using justification (~26:@<~a~>) to center with weight 26 characters

-1 using sugestion by ASCII-only to use <enter> instead of ~%

user65167

Posted 2016-10-25T22:37:34.043

Reputation:

182 – ASCII-only – 2018-04-26T07:19:39.210

1

Tcl, 92 bytes

set a {}
time {set a [format %c [expr 123-[incr i]]]$a;puts [format %[expr 13+$i/2]s $a]} 26

Try it online!

tcl, 94

set a {}
set i 123
time {set a [format %c [incr i -1]]$a;puts [format %[expr 74-$i/2]s $a]} 26

demo

In the middle of the process, I accidentaly got the italic version of the hat:

tcl, 94

set a {}
set i 123
time {set a [format %c [incr i -1]]$a;puts [format %[expr $i/2-24]s $a]} 26

demo


tcl, 101

set a {}
set i 123
while \$i>97 {set a [format %c [incr i -1]]$a;puts [format %[expr ($i-48)/2]s $a]}

demo

In the middle of the process, I accidentaly got the italic version of the hat:

tcl, 99

set a {}
set i 123
while \$i>97 {set a [format %c [incr i -1]]$a;puts [format %[expr $i/2-24]s $a]}

demo

sergiol

Posted 2016-10-25T22:37:34.043

Reputation: 3 055

92? – ASCII-only – 2018-04-26T06:23:47.903

@ASCII-only thanks! – sergiol – 2018-04-27T11:39:11.993

1

Japt, 16 bytes

;C¬£SpY/2 +CsYÃw ·

Try it online!

Explanation:

;C¬£SpY/2 +CsYÃw ·
;C                  // Alphabet shortcut
  ¬                 // Split into an array of chars
   £          Ã     // Map each item X and index Y by:
    SpY/2           //  " " repeated floor(Y/2) times
          +CsY      //  + alphabet.slice(Y)
               w    // Reverse the array of lines
                 ·  // Join with newlines

Oliver

Posted 2016-10-25T22:37:34.043

Reputation: 7 160

1

REXX, 52 bytes

do i=1 to 26
  say centre(right(xrange(a,z),i),26)
  end

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

idrougge

Posted 2016-10-25T22:37:34.043

Reputation: 641

1

Vim, 25 Keystrokes

:h<_␍jjYZZPqqPxYPr Yq12@q

Where ␍ is the Enter key, also sometimes notated as <cr>.

Explanation

:h<_␍jjYZZ                 " get a-z
          P                " initialize by pasting
           qq              " start record macro @q
             Px            " paste and remove the 1st char
               YPr␣        " yank and paste and replace 1st char with space
                   Y       " yank the whole line again
                    q      " end recording
                     12@q  " call macro 12 @q times

I am new to ViM though -- I started in November. Wondering if there is a way to merge the initializing P with the one in the macro.

What is the "correct" way to test a golfed ViM sequence? I tested with \vi -u /dev/null. However in a VM even :h<_␍ doesn't work. Also not very sure why my ViM will move to the first non space character haha.

P.S. Before I moved to use OS X, I golfed in Hexagony with great tools... Now on OS X I don't do wine and thus not running the great tools for explanations and debugging. So started my journey with ViM!

Sunny Pun

Posted 2016-10-25T22:37:34.043

Reputation: 821

1

C# (.NET Core), 112 bytes

()=>string.Join("\n",new int[26].Select((_,i)=>"".PadLeft(12-i/2)+"abcdefghijklmnopqrstuvwxyz".Substring(25-i)))

Try it online!

()=>string.Join("\n", // OP doesnt want to output a sequence of string...
    new int[26].Select((_,i)=> // yield range from 0 to 25
        "".PadLeft(12-i/2)+ // add spaces to center
            "abcdefghijklmnopqrstuvwxyz".Substring(25-i)))  // remove letters

aloisdg moving to codidact.com

Posted 2016-10-25T22:37:34.043

Reputation: 1 767

1

Perl 5, 40 38 bytes

-2 bytes thanks to @Dom Hastings

say$"x(13+--$x/2),@a[$x..-1]for@a=a..z

Try it online!

Xcali

Posted 2016-10-25T22:37:34.043

Reputation: 7 671

Came up with a slightly different variation for -2: Try it online!

– Dom Hastings – 2018-04-27T19:56:23.597

1

T-SQL, 107 bytes

DECLARE @t VARCHAR(99)=SPACE(13),@ INT=27a:SET @t=STUFF(@t,@/2,@%2,CHAR(@+95))PRINT @t
SET @-=1IF @>1GOTO a

Modifies the string for each line by cramming in the correct letter at the correct position using the SQL fuction STUFF(). Formatted:

DECLARE @t VARCHAR(99)=SPACE(13), @ INT=27
a:
    SET @t=STUFF(@t,@/2,@%2,CHAR(@+95))
    PRINT @t
    SET @-=1
IF @>1 GOTO a

@/2 uses integer division (no remainder) to determine the position to insert the letter. @%2 is the MODULO function, and flips between 0 (insert the letter) and 1 (overwrite a space).

If you prefer capitial letters, use CHAR(@+63) instead (doesn't change our byte count).

BradC

Posted 2016-10-25T22:37:34.043

Reputation: 6 099

1

Stax, 7 bytes

ô2òΘé8└

Run and debug it

recursive

Posted 2016-10-25T22:37:34.043

Reputation: 8 616

1

PHP, 71 Bytes

for(;++$i<27;)echo str_pad(substr(join(range(a,z)),-$i),26," ",2)."\n";

Jörg Hülsermann

Posted 2016-10-25T22:37:34.043

Reputation: 13 026

1(26-$i)/213-$i/2 – manatwork – 2016-10-26T07:01:16.587

Will it throw an error if you removed the last colon? Also, would be nice if you provided a link to an online website with example, ex. http://sandbox.onlinephpfunctions.com/

– RedClover – 2018-01-05T13:37:08.463

1

Turtlèd, 70 68 bytes

note the trailing space

#abcdefghijklmnopqrstuvwxyz#' -{ -{ +.r_}' l[ l-]d,(*@!' r)(!@*)_}' 

Try it online!

How it works:

#abcdefghijklmnopqrstuvwxyz#              Set string var to this value
                            ' -           write space on first grid cell, string pointer-=1
                               {                                    } While cell is space
                                 -                 decrement string pointer
                                  {     }    While cell is space
                                    +.       increment string pointer, write pointed char
                                      r      move right
                                       _     write non-space if pointed char is last char

                                         '[space]   write space on cell
                                           l        move left
                                            [ l-]   move left, pointer-- until cell's space
                                                 d, move down, write character var \
                                                                           (initially *)

                                                   (*     ) if cell is *
                                                     @!     set char var=!
                                                       ' r  write space over *, move right

                                                           (!    ) if cell is !
                                                             @*    set char var=*
                                                               '[space] write space over !

                                                                 _ (explanation below)
                                               write (*|!) if pointed char is last char

                                                                   '[space]    Write space

Human-readable explanation(?):

It uses the string var to contain the alphabet. Each iteration, it reduces the index by one, until it wraps around, and halts, after getting to the last line. For the alternating indents, it uses the char var. Each iteration it checks the char var and flips it. if it was * it shifts right, so the first character aligns, otherwise not, so the last character aligns.

Destructible Lemon

Posted 2016-10-25T22:37:34.043

Reputation: 5 908

1

Java 7 ,128 127 bytes

Saved 1 byte.Thanks to kevin.

String c(int n,String s,char v,String d){String c="";for(int j=0;j++<(n-1)/2;c+=" ");return n>0?c(--n,s=v+s,--v,d+c+s+"\n"):d;}

ungolfed

  class A {

public static void main(String[] args) {
System.out.print(c(26, "", (char)122, ""));
}
static String c(int n, String s, char v, String d){

    String c = "";

    for (int j = 0; j++ < (n - 1)/2; c += " ");

    return n > 0 ? c(--n, s = v + s, --v, d + c + s + "\n" ) : d;
}
}

Without an passing 122 in a function

132 bytes

String c(String s,int n,String d){String c="";int v=96,j=0;for(;j++<(n-1)/2;c+=" ");return n>0?c(s=(char)(v+n--)+s,n,d+c+s+"\n"):d;}

ungolfed

  class A{

public static void main(String[] args) {
System.out.print(c("",26,""));

}
static String c(String s, int n, String d) {
    String c = "";
    int v = 96,j=0;
    for (; j++ < (n - 1)/2; c += " ");
    return n > 0 ? c(s = ( char) (v + n--) + s, n, (d + c + s + "\n")) : d;
     }
  }

Numberknot

Posted 2016-10-25T22:37:34.043

Reputation: 885

1You can remove the = at d+=c+s+"\n". Also, you might want to format your ungolfed code a bit with indentations. I noticed that with some of your other answers as well. :) – Kevin Cruijssen – 2016-10-26T06:56:06.223

1oops! i did this mistake again,Shame to me. ......ok @KevinCruijssen i am on it. – Numberknot – 2016-10-26T07:20:49.777

Can't you replace the s=v+s in the recursion with s+=v? – Roman Gräf – 2016-10-26T13:40:03.777

No..because the letters pattern are in backward. – Numberknot – 2016-10-26T13:45:22.173

1

Perl, 44 bytes

This is a port of @xnor's answer.

$n=26;say$"x($n/2),$@=chr(97+$n).$@while$n--

Needs -E (or -M5.010) to run :

perl -E '$n=26;say$"x($n/2),$@=chr(97+$n).$@while$n--';

Dada

Posted 2016-10-25T22:37:34.043

Reputation: 8 279

1

Ruby, 64 bytes

(0..26).each{|x|puts' '*(12-x/2)+('a'..'z').to_a[~x..-1].join()}

Manny42

Posted 2016-10-25T22:37:34.043

Reputation: 111

A few comments:

You don't need to put the brackets after join

Calling each instead of map is unnecessary, since we don't care about what we're returning

You can call last on a range – Lee W – 2016-10-27T19:05:09.263

Instead of (0..26).map, try 27.times; instead of ('a'..'z').to_a, [*?a..?z]; and instead of .join, *"". – Jordan – 2017-11-18T04:17:27.243

0

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

Pete Arden

Posted 2016-10-25T22:37:34.043

Reputation: 1 151

0

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

Spydercrawler

Posted 2016-10-25T22:37:34.043

Reputation: 61

0

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

dzaima

Posted 2016-10-25T22:37:34.043

Reputation: 19 048

0

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

Taylor Scott

Posted 2016-10-25T22:37:34.043

Reputation: 6 709

0

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.

Barodus

Posted 2016-10-25T22:37:34.043

Reputation: 43

1

Hello fellow C# golfer. We are not allowed to post a snippet, but we can use a function and lamda are allowed. source.

– aloisdg moving to codidact.com – 2017-11-16T17:21:00.267

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, – Barodus – 2017-11-17T12:14:46.057

most of the time we can, but here OP want to output a string with "\n"... – aloisdg moving to codidact.com – 2017-11-18T11:03:49.057

0

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

aloisdg moving to codidact.com

Posted 2016-10-25T22:37:34.043

Reputation: 1 767

0

Ruby, 54 bytes

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

Try it online!

Justin Mariner

Posted 2016-10-25T22:37:34.043

Reputation: 4 746

0

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.

Charlie

Posted 2016-10-25T22:37:34.043

Reputation: 11 448

12 bytes, I think – ASCII-only – 2018-02-28T12:23:40.767

@ASCII-only 11 bytes: ⮌Eβ⁺× ⊘κ✂βκ

– Neil – 2018-06-13T08:21:33.997

0

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.

cole

Posted 2016-10-25T22:37:34.043

Reputation: 3 526

0

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!

Taylor Scott

Posted 2016-10-25T22:37:34.043

Reputation: 6 709

0

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!

Taylor Scott

Posted 2016-10-25T22:37:34.043

Reputation: 6 709

0

APL (Dyalog Classic), 20 bytes

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

Try it online!

uses ⎕io←1

ngn

Posted 2016-10-25T22:37:34.043

Reputation: 11 449

0

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.

Titus

Posted 2016-10-25T22:37:34.043

Reputation: 13 814

0

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.

Bubbler

Posted 2016-10-25T22:37:34.043

Reputation: 16 616

0

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

Jaden Lee

Posted 2016-10-25T22:37:34.043

Reputation: 1

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.

– Chris – 2018-04-27T07:42:56.813

7

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.

– ovs – 2018-04-27T08:20:28.677

Not an expert with Java, but can't you use the repeat function for 109 bytes?

– Jo King – 2018-10-08T10:04:27.280

0

Canvas, 6 bytes

z±[±]r

Try it here!

dzaima

Posted 2016-10-25T22:37:34.043

Reputation: 19 048

0

Haskell (Lambdabot), 73 bytes

unlines[([1..div(26-length x)2]>>" ")++x|x<-reverse.init$tails['a'..'z']]

same length:

do x<-reverse.init$tails['a'..'z'];([1..div(26-length x)2]>>" ")++x++"\n"

I use init.tails or tail.inits with a possible reverse in front in pretty much every challenge; I wish they would add it to Prelude already.

BlackCap

Posted 2016-10-25T22:37:34.043

Reputation: 3 576

0

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!

Blue

Posted 2016-10-25T22:37:34.043

Reputation: 26 661

Is it splat or split? – Erik the Outgolfer – 2016-10-26T13:23:07.767

@EriktheGolfer it is splat. It pops a list and pushes the contents of that list in reverse to the stack – Blue – 2016-10-26T13:26:47.487

Okay, putting the spellcheck edit in. – Erik the Outgolfer – 2016-10-26T13:29:47.327

0

Python 2, 66 64 bytes

i=91;exec'i-=1;print`map(chr,range(i,91))`[2::5].center(26);'*26

Blue

Posted 2016-10-25T22:37:34.043

Reputation: 26 661

0

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

steenbergh

Posted 2016-10-25T22:37:34.043

Reputation: 7 772

Doesn't match the OP. – Magic Octopus Urn – 2016-10-26T17:43:39.453

@carusocomputing it does now. – steenbergh – 2016-10-26T21:50:18.893

0

Groovy, 53 bytes

('z'..'a').each{println((it..'z').join().center(26))}

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

Magic Octopus Urn

Posted 2016-10-25T22:37:34.043

Reputation: 19 422

0

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

rnso

Posted 2016-10-25T22:37:34.043

Reputation: 1 635

-1

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

colsw

Posted 2016-10-25T22:37:34.043

Reputation: 3 195

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.

– AdmBorkBork – 2016-10-28T13:03:12.097

@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. – colsw – 2016-10-28T13:45:11.970

Does not match the text in the question. – Oliver Ni – 2016-11-02T23:45:29.233

should be 1,1,2,2,3,3,etc. not 1,2,2,3,3,etc. – Oliver Ni – 2016-11-02T23:45:50.517

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. – colsw – 2016-11-03T09:44:11.403

(27-$l)/2 in the PadLeft might fix it. And: (27-$l)/2+$l = 13.5-$l/2+$l = 13.5+$l/2. Or does / cast to int? I guess it´s the function call, though. – Titus – 2018-04-29T15:48:58.700

Replacing 26 with 25.5 appears to be enough. Try it online!

– Dennis – 2018-04-29T17:24:31.083