Alphabet triangle

49

10

You are to print this exact text:

A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
ABCDEFGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYZYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGFEDCBA
ABCDEFEDCBA
ABCDEDCBA
ABCDCBA
ABCBA
ABA
A

Specs

  • Extra trailing newlines are allowed at the end of the output.
  • Extra trailing spaces (U+0020) are allowed at the end of each line, including the extra trailing newlines.
  • You can use all lowercase instead of all uppercase, but you cannot print partially lowercase partially uppercase.
  • You can return the text as a function output instead of printing it in a full program.

Scoring

Since this is a triangle, and a triangle has 3 sides, and 3 is a small number, your code should be small in terms of byte-count.

Leaky Nun

Posted 2016-08-03T04:42:23.497

Reputation: 45 011

22So many alphabets recently – downrep_nation – 2016-08-03T11:15:52.777

1My synesthesia is going hog wild, @downrep_nation – DoctorHeckle – 2016-08-03T13:33:34.977

5"Since a triangle has 3 sides and 3 is a small number, so your code should be small in terms of byte count." seems legitimate – Rohan Jhunjhunwala – 2016-08-04T22:00:52.653

1Squares of numbers composed only of 1 seems related: 11 = 1 ~= A , 1111 = 121 ~= ABA , 111*111 = 12321 ~= ABCBA ... – Caridorc – 2016-08-05T13:28:07.690

1"Since a triangle has 3 sides and..." Illuminati Confirmed. – HyperNeutrino – 2016-10-28T00:47:31.593

Answers

38

Vim, 37 bytes

:h<_↵↵↵YZZPP$xqqxYpGP√2G$A♥-€k$q24@qJ

enter image description here

Legend

↵ = Return
√ = Ctrl+V
♥ = Ctrl+R
€ = Escape

Lynn

Posted 2016-08-03T04:42:23.497

Reputation: 55 648

2That's a really cool GIF. – AdmBorkBork – 2016-08-03T15:51:17.033

13I will never cease to be amazed by Vim answers. – DanTheMan – 2016-08-04T05:05:37.823

Care to explain how this works for those not fluent in Vim? – R. Kap – 2016-08-09T06:30:06.683

6@R.Kap I recommend you download Vim and try the solution out yourself — you can watch the solution unfold stroke by stroke! Essentially, I steal the alphabet from a help file (:h<_↵↵↵YZZP), then record a macro (qq…q) that repeatedly chops a letter off the top line, makes two copies of it to grow the triangle vertically, then appends the chopped-off letter to all lines to grow it horizontally. I repeat this macro 24 more times to draw the full triangle. – Lynn – 2016-08-09T10:06:40.640

31

Logo, 232 207 196 190 bytes

Did somebody say triangles?

Get out your compass and protractor, and let's do this the graphical way. The geometry uses an equilateral triangle to align the results. I previously had an isosceles triangle, but it involved too many decimal places. This change also compacted the output, reducing the amount of screen prep and font changing I had to do.

I used the Calormen online interpreter to flesh this one out. If you don't have enough screen real estate, it's going to wrap, but you can also fiddle with some numbers to take care of that. I used the "F11" full-screen mode on my browser.

ht
pu
to r:n:b:l repeat:n[rt:b label char 90-:n lt:b fd:l] end
to t:s
fd 12 rt 120 bk 6
repeat 2[r:s 90 12]
repeat 2[rt 120 r:s 90-heading 24]
end
rt 90 label "Z lt 210
repeat 25[t repcount]

The r procedure draws a line of n characters. The character is determined automatically depending on how many segments it is told to use. The b parameter tells it how much to temporarily rotate so that the letters are pointing in the right direction. The l parameter determines the linear distance between letters.

The t procedure steps to the next position and calls the r function a four times to create a triangle, rotating when appropriate. I called it twice for the vertical side because that took fewer bytes than calling it once with special handling. The end of the procedure positions the turtle for start of the next triangle, one step above.

Z is a special case, so we just print it directly and rotate as if we had just finished a triangle. Finally, t is called 25 times.

In progress annotated pictureFinished result

GuitarPicker

Posted 2016-08-03T04:42:23.497

Reputation: 1 101

3Out of the box. Nicely done. – CousinCocaine – 2016-08-12T20:30:16.897

19

Haskell, 58 bytes

f x=init x++reverse x
t=unlines$f[f['A'..c]|c<-['A'..'Z']]

Defines a function t that returns the output as a string.

f x=               define a helper function
init x             take the argument minus its last element
++                 and concatenate it with
reverse x          the argument reversed, producing ex. [a,b,c,b,a] from [a,b,c]

t=                                    define the main function
           [         |c<-['A'..'Z']]  for every char c from 'A' to 'Z'...
             ['A'..c]                 generate the range from 'A' to c
            f                         call the helper function to "reflect" it
          f                           call the helper function on the entire list
  unlines$                            join on newlines

Doorknob

Posted 2016-08-03T04:42:23.497

Reputation: 68 138

12

Jelly, 16 13 bytes

Ṗ;Ṛ
ØAḣJÇ€Çj⁷

Thanks to @LeakyNun for golfing off 3 bytes!

Try it online!

How it works

Ṗ;Ṛ        Helper link. Argument: A (array)

Ṗ          Pop; yield A without its last element.
  Ṛ        Reversed; yield A with inverted order.
 ;         Concatenate the results to both sides.


ØAḣJÇ€Çj⁷  Main link. No arguments.

ØA         Alphabet; set link argument and return value to "A...Z".
   J       Indices; yield [1, ..., 26].
  ḣ        Head; take the first, the first two, etc. elements of the alphabet.
           This yields ["A", AB", ..., "A...Z"].
    ǀ     Apply the helper link to each string.
      Ç    Apply the helper link to the array itself.
       j⁷  Join, separating by linefeeds.

Dennis

Posted 2016-08-03T04:42:23.497

Reputation: 196 637

33 bytes off – Leaky Nun – 2016-08-03T05:12:50.933

@LeakyNun Thanks. – Dennis – 2016-08-03T05:24:31.353

4I'd be curious to know how in the world this works... – Socratic Phoenix – 2016-08-03T05:34:15.450

maybe if use the link duplicator u can save one byte – Leaky Nun – 2016-08-03T05:35:48.593

@SocraticPhoenix I've added an explanation. – Dennis – 2016-08-03T05:49:49.087

@LeakyNun Unfortunately, combining Ṗ;Ṛ requires two bytes. ØAḣJµṖ;Ṛµ⁺€j⁷ is just as long. – Dennis – 2016-08-03T05:51:04.730

In which encoding does this code take 13 bytes? – Mathieu Rodic – 2016-08-04T09:16:20.173

3@MathieuRodic Jelly uses a custom code page that encodes all 256 characters it understands as a single byte each. The bytes link in the header points to it. – Dennis – 2016-08-04T15:41:52.993

@Dennis Thanks for the info :) – Mathieu Rodic – 2016-08-05T09:55:11.000

Is something like ØA;\ŒBŒḄY possible or does it use commands that postdate the challenge :p?

– Adnan – 2016-10-26T13:58:00.590

@Adnan Unfortunately, everything after the first four bytes postdates the challenge... – Dennis – 2016-10-26T14:09:11.603

10

Python, 74 bytes

def f(x=66,s='A'):
 t=s+s[-2::-1];print t
 if x<91:f(x+1,s+chr(x));print t

A Python 2 function that prints and takes no arguments. The key idea is to generate the triangular there-and-back pattern with recursion. First consider this simpler function that prints the letters 'A' up to 'Z' and down back to 'A':

def f(x=65):
 t=chr(x);print t
 if x<90:f(x+1);print t 

The function first prints "A" (char-code 65), then recurses to print "B" (66) and so on to "Z" (90). From there, it stops recursing. On the way popping back down the recursive stack, it prints whatever character t it printed at the same layer, from "Y" back to "A".

The main code does the same, except it accumulates into s the string of letters so far, and prints the up-and-down string s+s[-2::-1].

Thanks to xsot for 2 bytes.

In Python 3, the same thing is a byte shorter (73 bytes) by putting everything on one line.

def f(x=66,s='A'):t=s+s[-2::-1];print(t);x>90or[f(x+1,s+chr(x)),print(t)]

xnor

Posted 2016-08-03T04:42:23.497

Reputation: 115 687

You can save 2 bytes if you offset the variables, i.e. f(x=66,s='A'). This allows you to update s in the function call instead of the function body. – xsot – 2016-08-03T12:09:29.270

I think your Python 3 version, like its Python 2 relative, needs a value of 90 instead of 89 in order to have the longest row that goes all the way to Z and back. – Tebbe – 2016-08-04T19:29:41.067

@Tebbe Thanks, fixed them. – xnor – 2016-08-04T20:21:07.370

8

05AB1E, 20 13 12 6 bytes

Saved 2 bytes thanks to Adnan.
Saved 6 bytes thanks to Magic Octopus Urn and some new language functionality.

Aη€ûû»

Try it online!

Explanation

Aη       # push prefixes of alphabet
  €û     # palendromize each prefix
    û    # palendromize the whole list
     »   # join on newlines

Emigna

Posted 2016-08-03T04:42:23.497

Reputation: 50 798

Very nice! You can change Œ26£ to .p, which is the prefix command. Also, you can change D, to =, which prints without popping. – Adnan – 2016-08-03T10:02:01.597

Wow, clever trick with the gF,! – Adnan – 2016-08-03T10:05:28.787

@Adnan: Thanks! I knew there was a prefix command in there somewhere :) I seldom check the extended ones though. – Emigna – 2016-08-03T10:05:36.537

2That bifurcate command  is very nice and a really neat feature. – miles – 2016-08-03T16:48:46.323

1@carusocomputing: unfortunately û is newer than the challenge and would make this answer non-competing. – Emigna – 2016-10-25T20:09:25.733

A.p€û}û» - 8 bytes, ahh... Yeah, just realized that as well. – Magic Octopus Urn – 2016-10-25T20:09:31.193

@carusocomputing: It would have been amazing to have that command when this challenge was made :) – Emigna – 2016-10-25T20:11:20.980

Aη€ûû» :P, since it's been rebumped hehe – Magic Octopus Urn – 2019-06-14T11:28:29.463

8

brainfuck, 1733 121 119 bytes

----[---->+<]>++.<++++++++++.<+++++[<+++++>-]<+>>>.<[>>[>.]<[>+>+<<-]>+.>[<<+> >-]<[<.]<-]>>[>[>]<[-]<[<]>>[.>]<<[.<]>]

Slightly more readable version:

----[---->+<]>++.<
++++++++++.<
+++++[<+++++>-]<+
>>
>.<
[
  >>[>.]<
  [>+>+<<-]
  >+.>
  [<<+>>-]
  <[<.]<
  -
]
>>
[
  >[>]<
  [-]
  <[<]>
  >[.>]<<[.<]>
]

Explanation possibly to come.

DanTheMan

Posted 2016-08-03T04:42:23.497

Reputation: 3 140

Try using a loop instead of building each character manually. – Leaky Nun – 2016-08-04T08:56:41.300

@LeakyNun I have no idea how to go about that. Any suggestions? – DanTheMan – 2016-08-04T09:00:49.367

Refer to this.

– Leaky Nun – 2016-08-04T09:03:47.830

Basically, to do a loop of n iterations, set up n on a cell and then start a while loop [ on it. On each iteration, return to that cell and minus one. – Leaky Nun – 2016-08-04T09:05:09.953

@LeakyNun But then how will I return to the cell I was on after decrementing? – DanTheMan – 2016-08-04T09:12:56.073

Can we discuss this in chat?

– Leaky Nun – 2016-08-04T09:15:36.720

@LeakyNun Actually, I just realised how to do it. I'll work on it tomorrow. – DanTheMan – 2016-08-04T09:40:08.670

@LeakyNun I did it! – DanTheMan – 2016-08-04T14:01:14.247

4Nice, so you only slept for 4 hours. – Leaky Nun – 2016-08-04T14:04:15.680

@LeakyNun I suppose so. That may not have been a good idea. – DanTheMan – 2016-08-04T14:10:35.180

An alternative starting point, perhaps: ->+>++++++[++[>++++++++<-]++<]. It initializes the tape as [2, 10, 26, 64]. – primo – 2016-08-05T14:08:54.450

1Congratulations on getting the program smaller than the output! – GuitarPicker – 2016-08-05T19:53:39.260

1How does one golf off 1612 bytes? – FantaC – 2017-12-22T16:11:13.080

6

J, 26 23 22 bytes

f(f=:,1}.|.)\u:65+i.26

Explanation

,1}.|.  Monad f: Input: A
    |.  Reverse the items in A
 1}.    Drop the first item in the reversed A
,       Join A and the previous

f(f=:,1}.|.)\u:65+i.26
                  i.26  Create the range [0, 1, ..., 25]
               65+      Add 65 to each
             u:         Convert to characters to get 'A..Z'
  f=:,1}.|.             Define a verb f
 (         )\           Call f monadically on each prefix of 'A..Z'
f                       Call f again on that result

miles

Posted 2016-08-03T04:42:23.497

Reputation: 15 654

f=:,1}.|. try this – Leaky Nun – 2016-08-03T05:34:19.447

@LeakyNun Thanks I don't know why I thought they were different. – miles – 2016-08-03T05:41:03.243

5

Python 3, 97 bytes

s="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
a=[s[:x]+s[x::-1]for x in range(26)]
print('\n'.join(a+a[24::-1]))

Ideone it!

Leaky Nun

Posted 2016-08-03T04:42:23.497

Reputation: 45 011

1You can also do '\n'.join(a+a[-2::-1]) – Miguel – 2016-08-03T16:40:25.167

96 bytes! – Artemis still doesn't trust SE – 2019-06-14T19:37:53.100

5

Ruby, 71 bytes

Try it on repl.it

s=*?A..?Y
s+=[?Z]+s.reverse
puts s.map{|e|k=[*?A...e]*'';k+e+k.reverse}

Value Ink

Posted 2016-08-03T04:42:23.497

Reputation: 10 608

This solution builds on yours, using absolute value arithmetic to save 3 bytes. – benj2240 – 2018-03-23T16:59:46.813

5

C, 272 247 234 230 144 137 bytes:

(Saved many bytes (272 -> 230) in my previous method thanks to great golfing tips & tricks from sigalor!)

(Saved nearly 100 bytes (230 -> 144) by switching to a better method.)

main(q,i,e,x){for(q=0;q<51;q++){i=q>25 ? 25-(q-25):q;for(e=65;e<66+i;e++)printf("%c",e);for(x=64+i;x>64;x--)printf("%c",x);printf("\n");}}

My first answer ever in C. I just started self-learning it recently, so let's see how it goes.

C it in Action! (Ideone)

R. Kap

Posted 2016-08-03T04:42:23.497

Reputation: 4 730

1Ahhh, I just wanted to add a C answer as well... Whatever, I'll just help you then ;) First, this is code golf, you do not need to write perfect code. Compiler warnings are completely fine. That's why you can remove main()'s return type and even the #include <stdio.h>. GCC (and also sites like Ideone) are OK with that. Next, you can 'outsource' variable definitions to the parameter list of a function. Let for(int i=65;... become for(i=65... and change main() to main(i). Do the same for every other int variable as well (GCC defaults missing types to int). – sigalor – 2016-08-03T09:48:16.063

@sigalor Thanks for the tips! :) Just one question: why do I need to change main() to main(i)? – R. Kap – 2016-08-03T09:51:35.193

@sigalor Actually, now I'm getting a bunch of compilation errors. – R. Kap – 2016-08-03T09:54:20.097

When you do not declare your i variable in the for loop's initialization, you need to declare it somewhere else. And because (at least in C) the parameters of a function can be used like normal variables, there should be no problem. Btw, which compiler are you using? – sigalor – 2016-08-03T09:55:03.663

@sigalor Currently C in Ideone. I'm getting several <variable> undeclared errors. – R. Kap – 2016-08-03T09:56:14.070

I see your problem. First, you can (of course) ignore all lines of the compilation info that contain warning. Next, you need to add the names of all variables you removed the type from (and that were int's previously) to main's parameter list like this: main(i,w,g,x,q,b). The compiler will implicitly convert this function head to int main(int i, int w, int g, int x, int q, int b) (remember, missing types are defaulted to int). – sigalor – 2016-08-03T10:03:05.857

@sigalor Oh wow. It worked! Thanks! :) – R. Kap – 2016-08-03T10:06:20.660

Let us continue this discussion in chat.

– sigalor – 2016-08-03T10:06:47.043

@R.Kap - 117 bytes: main(q,i,e,x){for(q=0;q<51;q++){i=q>25?50-q:q;for(e=65;e<66+i;)putchar(e++);for(x=64+i;x>64;)putchar(x--);puts("");}}. – owacoder – 2016-08-03T12:51:15.780

I think your provided code requires 138, not 137 bytes. Anyway, 131 bytes.

– Jonathan Frech – 2017-09-19T06:37:18.847

You can use putchar(e); instead of printf("%c", e);, saving 4 bytes. – Krzysztof Szewczyk – 2019-06-14T10:01:53.570

5

Mathematica 59 bytes

Column@FromCharacterCode[#@#@26+64]&[#-Abs@Range[1-#,#-1]&]

chyanog

Posted 2016-08-03T04:42:23.497

Reputation: 1 078

I think that removing the //Column from the end and prefixing your code with Column@ works. – Yytsi – 2016-08-03T15:17:23.980

2You seem to have counted and as single bytes. I doubt that there's a single-byte code page that has them and is also supported by Mathematica out of the box. They'd by three bytes in UTF-8, so they don't really save anything over plain [[...]]. I'm also not sure how legitimate Column is since it only displays like a list of lines in a Mathematica notebook. Running this code from a script file wouldn't display anything. However, Print/@ is the same number of bytes and works in either case. – Martin Ender – 2016-08-04T10:12:16.957

If you want to make a link to a page with a long address, you can do the following: [what you see](actual link). Ex. [Example Link](https://www.example.com), which shows as Example Link

– Stan Strum – 2017-09-16T16:47:48.690

5

><>, 60 bytes

1"AA"1[v
?v:1-:}>:5d*=
o>l  ?!v
{$-}:1[\ao]{:}+::"@Z"@=?;=2*

Try it online!

Sok

Posted 2016-08-03T04:42:23.497

Reputation: 5 592

5

JavaScript (ES6), 81 bytes

[...'ZYXWVUTSRQPONMLKJIHGFEDCBA'].reduce((p,c)=>c+`
`+p.replace(/^|$/gm,c)+`
`+c)

ASCII-only

Posted 2016-08-03T04:42:23.497

Reputation: 4 687

4

Dyalog APL, 18 bytes

↑(⊣,⌽)(⊣,1↓⌽)¨,\⎕a

lstefano

Posted 2016-08-03T04:42:23.497

Reputation: 850

2

Your longest line is duplicated. Fix that and save two bytes.

– Adám – 2017-05-01T05:17:50.543

4

R, 63 61 59 bytes

for(i in c(1:26,25:1))cat(LETTERS[c(1:i,i:1-1)],"
",sep="")

Helpfully LETTTERS[0] doesn't return any characters.

Edit: lost one thanks to @leakynun

Edit: two more thanks to @plannapus

user5957401

Posted 2016-08-03T04:42:23.497

Reputation: 699

1You can use a literal newline instead of \n – Leaky Nun – 2016-08-05T16:57:49.987

3

brainfuck, 79 bytes

+<++<<--------[>+++++>>[+++<+<]>]<+[[>+>+.<<-]>-[<+>>-.<-]>->.>[->]<<<[<<++>]<]

Formatted:

+<++<<
--------[>+++++>>[+++<+<]>]
<+
[
  [>+>+.<<-]
  >-[<+> >-.<-]
  >->.>[->]
  <<<[<<++>]
  <
]

Try it online

Mitch Schwartz

Posted 2016-08-03T04:42:23.497

Reputation: 4 899

3

Javascript(using external library-Enumerable), 135 bytes

_.Range(1,51).WriteLine(x=>(g=_.Range(65,x>25?52-x:x)).Write("",y=>(w=String.fromCharCode)(y))+(g.Reverse().Skip(1).Write("",y=>w(y))))

Link to the library: https://github.com/mvegh1/Enumerable

Code explanation: Create a range of ints starting at 1, for a count of 51. For each, write a line according to complex pred. Do some JS wizardry with global variables and caching...and voila. For each int in WriteLine, we are creating the left hand range of ints and storing into global "g", and String Joining (Write) with "" delimiter and mapping each int to the String mapping to the int char code. Then, we concat the right hand side by taking the reversal of that sequence (and skipping the first element because that will match the last element of the original order...), writing with the same logic. EDIT: Updated the internals of Write in the library. An empty sequence will write an empty string instead of null now. This also shaved 15 bytes off the answer

enter image description here

applejacks01

Posted 2016-08-03T04:42:23.497

Reputation: 989

1Don't you need to include bytes that you need to import the library? – MatthewRock – 2016-08-03T12:06:01.047

1Idk, Ive posted over 20 answers using a library and you would be the first to say that to me. I dont think anybody really cares because my answers never win anyway – applejacks01 – 2016-08-03T12:58:42.243

1@applejacks01 Pretty sure if you don't import it, then you have to say something like "JS + Enumerable" at the top. Similar to "Bash + Coreutils" – mbomb007 – 2016-08-03T14:03:53.640

@mbomb007 Hahahah, I did!! Dr Green Eggs and Iron Man edited that out of my answer lmao – applejacks01 – 2016-08-03T14:17:06.137

2It's commonplace to count the import. Python + SymPy answers still have import sympy or from sympy import* at the top. The Bash + x answers are different because you only have to install x, not enable it somehow. – Dennis – 2016-08-03T15:29:01.817

Lol, why cant anybody agree? Ive heard conflicting rules on this, unless people have just remained silent or didn't really scrutinize my code. OR...nobody really cared about my answer and thus never said anything – applejacks01 – 2016-08-03T15:53:55.120

So, can I just put <script>a.js</script> at the top or something? – applejacks01 – 2016-08-03T15:59:03.840

That would make it a HTML + JavaScript + Enumerable answer, and you'd need to wrap your code in a <script> tag as well. Non-browser interpreters (Node, etc.) should have a saner way to import libraries, but I don't really know JS. – Dennis – 2016-08-03T22:15:03.983

Ok, I'll do some research to find a way to make it Node compatible I guess if I want to use a lib. Or, could I just mark my answer as non-competing, since I'm also just doing these to test my skills? – applejacks01 – 2016-08-03T22:30:22.977

@Dennis does this mean libraries like lodash are allowed if I specify them in the title and include the amount of bytes to import them? This is the first I'm hearing of this... – Patrick Roberts – 2016-08-04T02:37:20.000

1@PatrickRoberts As long as the library existed before the challenge was posted, yes. Python answers make use of sympy, numpy, scipy, etc. all the time. – Dennis – 2016-08-04T02:49:02.420

3

VBA, 94 bytes

Function T:For j=-25To 25:k=25-Abs(j):For i=-k To k:T=T &Chr(65+k-Abs(i)):Next:T=T &vbLf:Next

Call in Immediate window with ?T

Just to explain what's going on: I use Abs function twice, to reflect both the alphabet traverse and the line length. It's well suited to the task because of the single extreme value in both cases, which corresponds to the zero crossing of the pre-Abs variable.

As a simple set of commands in VBA Immediate window, rather than a program or function, the following would need 72 bytes:

For j=-25To 25:k=25-Abs(j):For i=-k To k:?Chr(65+k-Abs(i));:Next:?:Next

(with thanks to @GuitarPicker)

Joffan

Posted 2016-08-03T04:42:23.497

Reputation: 832

1I used some similar logic in one of my Iceland flag submissions. Couldn't you golf this further by running it entirely in the immediate window and skipping the function declaration, or does that break some rule I'm not familiar with? – GuitarPicker – 2016-08-04T12:52:51.047

@GuitarPicker ; not sure whether running in immediate window counts as a complete program, but if so then 8 bytes less, effectively; instead of starting with Function T: , end with :?T (although it would only work once, because after that you'd need to reset T to "" - but who needs more than one of these triangles?) – Joffan – 2016-08-04T16:04:28.457

2You don't even need T if you ? as you go with ;. – GuitarPicker – 2016-08-04T16:10:58.497

I was able to shave it down to 71 using that method. Hint: you won't need vbCrLf either. – GuitarPicker – 2016-08-04T16:18:32.567

1yeah, I got the same; note that return is required. – Joffan – 2016-08-04T16:22:45.790

3

Mathematica 98 96 92 bytes

There has to be a shorter way, even in Mathematica.

6 bytes saved thanks to Martin Ender.

r=Reverse@*Most; Print/@FromCharacterCode@Join[t=Join[s=Range[65,64+k],r@s]~Table~{k,26},r@t]

DavidC

Posted 2016-08-03T04:42:23.497

Reputation: 24 524

Can't Range[65,64+k] just be 65~Range~64+k? – Yytsi – 2016-08-03T10:31:08.800

That doesn't work. I think the +k somehow is left out. – DavidC – 2016-08-03T10:55:41.987

~Table~ and Column@ should work though. And since you seem to use r only in conjunction with Most you might as well define it as Reverse@*Most. – Martin Ender – 2016-08-03T14:36:15.077

Table and Column now have infix notation. r=Reverse@Most appears not to work. – DavidC – 2016-08-03T15:00:03.897

It should be Reverse@*Most (the asterisk wasn't a typo ;)). I'm also not sure how legitimate Column actually is since it only displays like a list of lines in a Mathematica notebook. Running this code from a script file wouldn't display anything. However, Print/@ is the same number of bytes and works in either case. – Martin Ender – 2016-08-04T10:14:25.083

Nice. But I am puzzled by *. What does it do here? – DavidC – 2016-08-04T10:39:51.633

@* is Composition. Also, I'm not getting notifications for your comments if you don't @mention me. ;) – Martin Ender – 2016-08-04T14:15:23.327

@MartinEnder, Composition? Very useful! – DavidC – 2016-08-04T15:36:51.433

3

TSQL, 159 bytes

DECLARE @ varchar(52)='ABCDEFGHIJKLMNOPQRSTUVWXY',@o varchar(max)SELECT @+='Z'+REVERSE(@)+'
',@o=@
WHILE''<@
SELECT @=STUFF(@,LEN(@)/2,2,''),@o=@+@o+@
PRINT @o

Fiddle

t-clausen.dk

Posted 2016-08-03T04:42:23.497

Reputation: 2 874

1I tried to do it but end up with 250+ bytes so never posted that. You, indeed, have a better solution then mine. Once again :) – Anuj Tripathi – 2016-08-10T16:47:30.603

3

R, 127 125 bytes

k=cat;L=LETTERS;for(i in 1:26)k(c(L[1:i],L[(i-1):0],"\n"));for(i in 1:26)k(c(L[0:(26-i)],L[ifelse((25-i)>=0,25-i,0):0],"\n"))

Not completely satisfied with this solution, especially the two for loops, but couldn't come with something better !
LETTERS contains the uppercase letters.

Ungolfed :

for(i in 1:26){
  cat(c(LETTERS[1:i],LETTERS[(i-1):0],"\n"))
               }

for(i in 1:26){
  cat(c(LETTERS[0:(26-i)],LETTERS[ifelse((25-i)>=0,25-i,0):0],"\n"))
               }

ifelse is a shorter way for unsing if... else... and works this way : ifelse(condition,action if TRUE, action if FALSE)

An other 125 bytes' solution :

for(i in 1:26)(k=cat)(c((L=LETTERS)[1:i],L[(i-1):0],"\n"));for(i in 1:26)k(c(L[0:(26-i)],L[ifelse((25-i)>=0,25-i,0):0],"\n"))

Frédéric

Posted 2016-08-03T04:42:23.497

Reputation: 2 059

112 bytes – Giuseppe – 2018-01-15T17:54:11.830

3

C, 93 bytes

Call f() without arguments.

g(l,n){putchar(l);n?g(l+1,--n),putchar(l):0;}f(n){for(n=-26;++n<26;puts(""))g(65,25-abs(n));}

Try it on ideone.

owacoder

Posted 2016-08-03T04:42:23.497

Reputation: 1 556

3

Powershell, 61 52 bytes

Thanks to TimmyD for saving 9 bytes!

65..90+89..65|%{-join[char[]]((65..$_-ne$_)+$_..65)}

Loops through ASCII values for capital letters forwards, then backwards. For each number, this creates an array of the first X numbers, removes the X-1st number, then adds the reverse of the first X numbers, which is all then cast to chars and joined into a string.

Ben Owen

Posted 2016-08-03T04:42:23.497

Reputation: 111

Hey, that's good, thanks! I had plugged in 65..90..65 on a whim earlier with no success. Guess I forgot I could just add the ranges together. – Ben Owen – 2016-08-03T13:51:52.087

3

Python, 73 71 bytes

Thanks to @xnor for the recursion

f=lambda x=66,s='A',t='':x/92*t or t+f(x+1,s+chr(x),s+s[-2::-1]+"\n")+t

Explanation

  • Parameters:
    • x is the ascii value of the next letter in the alphabet
    • s is an accumulator for the alphabet
    • t is a line in the triangle (ie s + s backwards)
  • Return: t if the alphabet is done (ie we're at the center)
  • Else: t+f(...)+t with:
    • x incremented
    • s appended with the next letter
    • t reset to s + s backwards + \n

Update

  • -2 [16-08-05] Remove leading \n (+1) and shortened conditional (-3) all thanks to @xnor

NonlinearFruit

Posted 2016-08-03T04:42:23.497

Reputation: 5 334

1What a clever method, pushing t through to the next loop. There's an extra leading newline though; x=66,s='A'' gets rid of it. The base case can be shortened to x/92*t or. – xnor – 2016-08-05T09:45:49.647

3

Python 2, 117 111 105 100 bytes

s="ABCDEFGHIJKLMNOPQRSTUVWXYZ"*2
for i in range(51):print(s[:-i-1]+s[-i-3::-1],s[:i]+s[i::-1])[26>i]

Run it

Thanks to @LeakyNun and @manatwork for pointing out a few byte saves.

Non-Golfed:

import string

def print_alphatriangle(n):
    offset = 1
    tail_offset = 3
    alpha = string.ascii_uppercase * n

    for i in range(len(alpha) - offset):
        if len(alpha) / 2 > i:
            print alpha[:i] + alpha[i::-offset]
            continue
        print alpha[:-i-offset] + alpha[-i-tail_offset::-offset]

This method works simply by string splicing an alphabet string that is concatenated together. Depending on whether i has reached a mid-way point of the string, it then starts to print out decreasing strings.

ospahiu

Posted 2016-08-03T04:42:23.497

Reputation: 231

1You can remove both instances of 0 – Leaky Nun – 2016-08-03T16:53:20.890

Good catch! Thanks, updated @LeakyNun – ospahiu – 2016-08-03T16:54:43.397

1Huh? len(s)/2? Why not 26? – manatwork – 2016-08-03T17:00:07.667

Good catch! @manatwork – ospahiu – 2016-08-03T17:04:51.790

1

See and apply marcog's tip from Tips for golfing in Python: print[s[:-i-1]+s[-i-3::-1],s[:i]+s[i::-1]][26>i].

– manatwork – 2016-08-03T17:09:13.260

3

Cheddar, 102 96 79 69 67 bytes

17 bytes thanks to Downgoat, and inspiration for 10 more.

"A"+(2@"27+@"(25|>1)).bytes.map(i->65@"(64+i)+@"((64+i)|>65)).vfuse

The fact that strings can concatenate but not arrays means that I would have to convert the two ranges to strings, concatenate, and then convert back to arrays.

Also, the fact that vfuse produces a leading newliens means that I would need to generate the first line manually and then concat to the rest.

@" as a dyad (two-argument function) can convert to string directly, but does not work for reversed range (if first argument is bigger than the second).

Range was half-inclusive. After the bug-fix it became inclusive.

Usage

cheddar> "A"+(2@"27+@"(25|>1)).bytes.map(i->(65@"(64+i)+@"((64+i)|>65))).vfuse
"A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
ABCDEFGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYZYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGFEDCBA
ABCDEFEDCBA
ABCDEDCBA
ABCDCBA
ABCBA
ABA
A"

Cheddar, 55 bytes (non-competing)

In the latest version with all the fixes, the answer is:

(|>25+24|>0).map(i->65@"(65+i)+(i?(64+i)@"65:"")).vfuse

but it was made after the challenge.

Leaky Nun

Posted 2016-08-03T04:42:23.497

Reputation: 45 011

@"(1|>26) can be 1@"26 – Downgoat – 2016-08-03T18:17:01.290

String.letters can be (65@"91) – Downgoat – 2016-08-03T18:18:03.607

String.letters.slice(0,i) could maybe be 65@"(66+i) – Downgoat – 2016-08-03T18:19:25.550

Aha, I see you've been grating your bytecount. – steenbergh – 2016-10-27T07:52:35.497

3

Java 131 bytes

Without using String (131 bytes)

public static void main(String[] args) {
    for(int i = 0 ,k=1; i>-1; i+=k){
        for(int c= 65, d = 1; c>64;){
            d = d>-1 & c < 65+i?1:-1;
            System.out.print((char)c+((c+=d)<65?"\n":""));
        }
        k = k>-1 & i < 25?1:-1;
    }
}

Codegolfed

for(int i=0,k=1;i>-1;k=k>-1&i<25?1:-1,i+=k)for(int c=65,d=1;c>64;d=d>-1&c<65+i?1:-1,System.out.print((char)c+((c+=d)<65?"\n":"")));

With String(173 bytes)

String a="abcdefghijklmnopqrstuvwxyz";
for(int i = 1 ,k=1; i>0; i+=k==1?1:-1){
    System.out.println(a.substring(0,i)+new StringBuilder(a).reverse().substring(27-i));
    k = k>-1 & i < 26?1:-1;
}

Codegolfed

String a="abcdefghijklmnopqrstuvwxyz";for(int i=1,k=1;i>0;k=k>-1&i<26?1:-1,System.out.println(a.substring(0,i)+new StringBuilder(a).reverse().substring(27-i)),i+=k==1?1:-1);

Thanks to manatwork and Kevin Cruijssen

Syamesh K

Posted 2016-08-03T04:42:23.497

Reputation: 131

2

Welcome to PPCG. Please read the “How should I answer a code golf? Any hints?” section in the [tag:code-golf] tag's info page. Answers to this kind of challenges are expected to present efforts to reduce the code size. In this you may find help in Tips for golfing in Java and Tips for golfing in <all languages>.

– manatwork – 2016-08-04T08:59:51.163

1There you use 4 ternary operators and all conditions are enclosed in parenthesis. You can remove those to save 8 characters. – manatwork – 2016-08-04T09:13:47.457

1d and k can not go below -1, right? Then you can replace d!=-1 with d>-1, same for k. (BTW, you forgot to fix the golfed version.) – manatwork – 2016-08-04T10:12:25.703

Moved statements from loop body to increment statement section to save 3 bytes.. – Syamesh K – 2016-08-04T11:39:33.330

you could also use bitwise operator & instead logical &&, which gives you another 2 bytes – user902383 – 2016-08-05T09:35:51.243

you could remove int, if you declare c inside your outer for loop – user902383 – 2016-08-05T09:40:59.887

I can use bitwise operator.. Thanks.. But changing c incide will not save any charectors.. – Syamesh K – 2016-08-08T04:36:27.767

1Hi, I know it's been quite a while, but you can golf two things: i+=k==1?1:-1 can be i+=k and System.out.print((char)c+(c+d<65?"\n":"")),c+=d==1?1:-1); can be System.out.print((char)c+((c+=d)<65?"\n":"")));. So in total it becomes (131 bytes): for(int i=0,k=1;i>-1;k=k>-1&i<25?1:-1,i+=k)for(int c=65,d=1;c>64;d=d>-1&c<65+i?1:-1,System.out.print((char)c+((c+=d)<65?"\n":""))); – Kevin Cruijssen – 2017-05-01T11:28:36.630

3

HTML + CSS, 884 characters

(763 characters HTML + 121 characters CSS)

Just expanding Leaky Nun's comment on MonkeyZeus's answer. (Though I might misread the comment…)

p{margin:0}p:before{content:"ABCDEFGH"}p:after{content:"HGFEDCBA"}a:before{content:"IJKLMNOP"}a:after{content:"PONMLKJI"}
<pre>A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
ABCDEFGFEDCBA
ABCDEFGHGFEDCBA
<p>I</p><p>IJI</p><p>IJKJI</p><p>IJKLKJI</p><p>IJKLMLKJI</p><p>IJKLMNMLKJI</p><p>IJKLMNONMLKJI</p><p>IJKLMNOPONMLKJI</p><p><a>Q</p><p><a>QRQ</p><p><a>QRSRQ</p><p><a>QRSTSRQ</p><p><a>QRSTUTSRQ</p><p><a>QRSTUVUTSRQ</p><p><a>QRSTUVWVUTSRQ</p><p><a>QRSTUVWXWVUTSRQ</p><p><a>QRSTUVWXYXWVUTSRQ</p><p><a>QRSTUVWXYZYXWVUTSRQ</p><p><a>QRSTUVWXYXWVUTSRQ</p><p><a>QRSTUVWXWVUTSRQ</p><p><a>QRSTUVWVUTSRQ</p><p><a>QRSTUVUTSRQ</p><p><a>QRSTUTSRQ</p><p><a>QRSTSRQ</p><p><a>QRSRQ</p><p><a>QRQ</p><p><a>Q</a></p><p>IJKLMNOPONMLKJI</p><p>IJKLMNONMLKJI</p><p>IJKLMNMLKJI</p><p>IJKLMLKJI</p><p>IJKLKJI</p><p>IJKJI</p><p>IJI</p><p>I</p>ABCDEFGHGFEDCBA
ABCDEFGFEDCBA
ABCDEFEDCBA
ABCDEDCBA
ABCDCBA
ABCBA
ABA
A

manatwork

Posted 2016-08-03T04:42:23.497

Reputation: 17 865

3

Brachylog, 37 29 bytes

Credits to Fatalize for his assistance throughout.

4 bytes thanks to Fatalize, and inspiration for another 4 bytes.

@A:1&e:"a"yr:1&cw@Nw\
:Lc.r.!

Try it online!

Predicate 0 (Main predicate)

@A:1&e:"a"yr:1&cw@Nw\
@A:1&                  Apply predicate 1 to @A, which is
                       basically "abcdefghijklmnopqrstuvwxyz"
     e                 Choose one element from the result (choice point)
      :"a"yr               generate substring from element to "a"
            :1&            apply predicate 1
               c           concatenate
                w          write to STDOUT
                 @Nw       write "\n" to STDOUT
                    \  Backtrack to last choice point to choose
                       another element until there is no more
                       choice left, then halt.

Predicate 1 (Auxiliary predicate)

This basically builds a palindrome from the given string.

:Lc.r.!
:Lc.     output is [input:L]
   .r.   output reversed is still output
      !  stop searching after the first output

Leaky Nun

Posted 2016-08-03T04:42:23.497

Reputation: 45 011

You can replace ,A in Predicate 1 with h, saving one byte. – Fatalize – 2016-08-11T07:25:39.673

You can also save two bytes by replacing :1:2yt. with :2&. and adding a ! (cut choice points) at the end of predicate 2. – Fatalize – 2016-08-11T07:29:33.350

2

Pepe, 94 bytes

rEeEeEEeEeREeEeeeeeEREEEEEEerEEReeeReeEREEEeEREEEeEREEeeREEEEEreererEEReeeReeEReReREEeEreeReee

Try it online!

u_ndefined

Posted 2016-08-03T04:42:23.497

Reputation: 1 253

2

brainfuck, 96 bytes

+++++[->+++++>>++>+++++++++++++<<<<]>[->>>[.>]<[->+>+<<]>+>[-<<+>>]<<<[.<]<]>>>[[.>]<[-]<[.<]>>]

Try it online!

; Initialize memory as: 0 (25) 0 "\n" "A" 0
+++++[->+++++>>++>+++++++++++++<<<<]>

[-                          ; Repeat 25 times
    >>>[.>]                 ; print all the characters on the band
    <[->+>+<<]>+>[-<<+>>]   ; copy the last character and increment
    <<<[.<]                 ; print all but the last two characters backwards
<]
>>>
[                           ; while there is still characters left
    [.>]                    ; print all the characters
    <[-]                    ; remove last character
    <[.<]                   ; print all characters backwards
>>]

Helena

Posted 2016-08-03T04:42:23.497

Reputation: 321

2

Sesos, 27 bytes

0000000: a85ab9 ac5daa f8b1c7 785f9b b961f7 665c1b 73ccfc  .Z..]....x_..a.f\.s..
0000015: c01ecb 987303                                     ....s.

Try it online! Check Debug to see the generated SBIN code.

Sesos assembly

The binary file above has been generated by assembling the following SASM code.

add 65, rwd 1, add 10, rwd 2, add 25
jmp
    fwd 3
    jmp
        put, fwd 1
    jnz
    rwd 1
    jmp
        fwd 1, add 1, fwd 1, add 1, rwd 2, sub 1
    jnz
    fwd 2
    jmp
        rwd 2, add 1, fwd 2, sub 1
    jnz
    rwd 1, add 1, rwd 2
    jmp
        put, rwd 1
    jnz
    rwd 1, sub 1
jnz
fwd 3
jmp
    jmp
        put, fwd 1
    jnz
    rwd 1, get, rwd 1
    jmp
        put, rwd 1
    jnz
    fwd 2
; jnz (implicit)

Dennis

Posted 2016-08-03T04:42:23.497

Reputation: 196 637

2

bash, 80 bytes

printf -v a %s {A..Z};for i in {1..26} {25..1};{ echo ${a::i}`rev<<<${a::i-1}`;}

izabera

Posted 2016-08-03T04:42:23.497

Reputation: 879

2

///, 208 bytes

/'/\/\///+/BA
AB'-/DC+CD'&/FE-EF')/HG&GH'=/JI)IJ'|/LK=KL'7/NM|MN'1/PO7OP'q/RQ1QR'p/TSqST'6/VUpUV'[/XW6WX/A
A+C+C-E-E&G&G)I)I=K=K|M|M7O7O1Q1QqSqSpUpU6W6W[Y[YZY[Y[W6W6UpUpSqSqQ1Q1O7O7M|M|K=K=I)I)G&G&E-E-C+C+A
A

Not winning of course, but here it is, predating Martin Ender...

Erik the Outgolfer

Posted 2016-08-03T04:42:23.497

Reputation: 38 134

2

Perl 5 with -M5.010, 54 bytes

for$@(A..Z){@;=($_.$/,@;);s/$*/$*$@$*/;say;$*=$@}say@;

Try it online!

Saved bytes thanks to @Xcali!

Dom Hastings

Posted 2016-08-03T04:42:23.497

Reputation: 16 415

Found a method which takes 56 bytes

– Xcali – 2019-06-14T22:58:37.303

Thanks @Xcali! With you suggestion managed to get it down to 54. And some added obfuscation for entertainment... – Dom Hastings – 2019-06-17T19:37:06.370

2

C#, 289 215 206 190 179 171 159 157 156 153 147 bytes

(n,i,s)=>{s=new string[51];for(i=0;i<26;){for(n=65;n-65<i;)s[i]+=(char)n++;for(;n>64;)s[i]+=(char)n--;s[50-i]=s[i++];}return string.Join("\n",s);};

Saved 3 bytes thanks to VisualMelon

Saved 6 bytes thanks to mdfst13

Formatted version:

(n,i,s)=>
{
    s=new string[51];

    for(i=0;i<26;)
    {
        for(n=65;n-65<i;)
            s[i]+=(char)n++;

        for(;n>64;)
            s[i] += (char)n--;

        s[50-i]=s[i++];
    }

    return string.Join("\n",s);
};

156 byte version (when the irrelevant whitespace is removed) of counting backwards, uses a similar concept to the above method but does so in reverse.

(n, i, s) =>
{
    s = new string[i = 51];
    for (; --i > 24;)
    {
        for (n = 65; i + n < 116;)
            s[i] += (char)n++;

        for (n = 50 - i + 64; n > 64;)
            s[i] += (char)n--;

        s[50 - i] = s[i];
    }

    return string.Join("\n", s);
};

TheLethalCoder

Posted 2016-08-03T04:42:23.497

Reputation: 6 930

Feel free to share any improvements to my code if you find any – TheLethalCoder – 2016-08-04T14:03:26.080

An explanation would be nice! You can use a for loop instead of a while, saving you the ; on the statement prior. The last statement in the outer loop can be put inside the last inner for loop (s[...]=s[i]+=) (need to juggle the i++ a bit, can certainly be done with only one extra byte). You've also got 51-i-1 in there, which can be reduced ;) I would be looking into reducing the two inner loops into one, and counting i backwards (so you assign it to 51 inside the array constructor). – VisualMelon – 2016-08-04T17:51:15.960

@VisualMelon I've been looking at it for ages and I never saw the 51 - I - 1 haha, and I can't put the last statement in the last inner loop as it doesn't get called on the first pass but didn't know I could chain the assignment like that so that's cool! And I've been looking into combining the loops, getting there – TheLethalCoder – 2016-08-05T08:06:36.370

@VisualMelon I reversed the outer loop and ended up adding 3 bytes when I got it working, will see if I can golf it down though – TheLethalCoder – 2016-08-05T09:39:36.733

2

Javascript (ES5), 105 bytes

Beating all other ES6 answers using some good ol' vanilla JS looping!

for(a="",n=g=1;n++<52;n<27?g++:g--){for(z=x=0;z++<g*2-1;z<g?x++:x--)a+=String.fromCharCode(65+x);a+="\n"}a

I could save 1 byte by using ES6 and changing

a+="\n"

to

a+=`
`

but nah.

Bassdrop Cumberwubwubwub

Posted 2016-08-03T04:42:23.497

Reputation: 5 707

Since you don't have console.log anywhere I imagine this is supposed to be the contents of a function. If you wrapped it in the ()=>{} that you need to actually execute your code and tried it, it would return undefined. It needs to be return a. If you had done everything so that it can actually be run (including the ()=>{} and return) it would be 119 bytes. tl;dr this code doesn't work. – Pandacoder – 2016-08-05T18:37:53.577

Nice. Also (10+x).toString(36) is shorter than String.fromCharCode(65+x) and like @Pandacoder said, you should put something like alert(a) at the end to make it valid. – user81655 – 2016-08-14T10:11:20.693

2

JavaScript (ES6), 89 bytes

R=(n,s=10,c=s.toString(36))=>n?c+R(n-1,s+1)+c:c
C=(n=0,r=R(n))=>n<25?r+`
`+C(n+1)+`
`+r:r

Not the shortest, but I wanted to try my hand at recursion. Call with C().

ETHproductions

Posted 2016-08-03T04:42:23.497

Reputation: 47 880

1

SOGL V0.12, 10 bytes

øZ{⁴Κ}¹╬,k

Try it Here!

Explanation:

ø           push an empty string
 Z{  }      for each character in the alphabet do
   ⁴          duplicate the item before the top item
    Κ         reverse add to that
              or simpler - on each iteration creates a duplicate of ToS but with the current character appended.
      ¹     wrap the stack in an array
       ╬,   quad-palindromize without spacing to a square
         k  remove the 1st line

The last k could be removed if the question allowed leading newlines.

dzaima

Posted 2016-08-03T04:42:23.497

Reputation: 19 048

Your interpreter site runs fine half of the time and half of the time, the run button seems to do nothing! – officialaimm – 2017-09-15T03:43:24.037

1@officialaimm ..huh. It's probably that Processing.js hasn't yet downloaded/transpiled the source. When I get the time I'll make the run button blank out while its loading – dzaima – 2017-09-15T05:09:19.297

ah, makes sense. – officialaimm – 2017-09-15T05:59:26.373

1

brainfuck, 109 bytes

+++++[<+++++>-]<+[>>[>[.>]]>++++++++++<<[>>.<]>[<]>--[<++++++++>-]<[+.<]<-]>>,>[.>]++++++++++.[<[.<]>,>[.>]<]

Try it online!

Explanation

+++++[<+++++>-] 26 times
<+[
  >>[>[.>]]     print every letter up to new char position
  >++++++++++<<[>>.<]  if any letter exists print lf
  >[<]>         resync pointer position
  --[<++++++++>-] set new char to A minus 1
  <[+.<]        increment each letter and print it
  <-            decrement counter
]
>>,             delete last letter
>[.>]           print rest of middle line
+++++ +++++.    print lf
[               while chars exist
  <[.<]         print all
  >,            delete last
  >[.>]<        print second half (including lf)
]

Alternative

If a leading newline would be alowed, this could also be done with 97 bytes.

+++++[<+++++>-]<+[>>[>[.>]]>++++++++++.--[<++++++++>-]<[+.<]<-]>>,>[.>]++++++++++.[<[.<]>,>[.>]<]

Try it online!

Explanation

+++++[<+++++>-]     26 times
<+[
  >>[>[.>]]           print every letter up to new char position
  >++++++++++.        print lf
  --[<++++++++>-]     set new char to A minus 1
  <[+.<]              increment each letter and print it
  <-                  decrement counter
]
>>,                 delete last letter
>[.>]               print rest of middle line
+++++ +++++.        print lf
[                   while chars exist
  <[.<]               print all
  >,                  delete last
  >[.>]<              print second half (including lf)
]

Both codes need interpreters that use "end of input = 0".

Dorian

Posted 2016-08-03T04:42:23.497

Reputation: 1 521

1

Common Lisp, 170 bytes

(let ((r "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))(loop for i from 1 to 51 do(let ((l (subseq r 0 (- i (* 2 (- i 26) (floor i 26))))))(format t "~a~a~%" l (subseq (reverse l) 1)))))

Run it: TIO here.

Formatted:

(let ((r "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
  (loop for i from 1 to 51
    do(let ((l (subseq r 0 (- i (* 2 (- i 26) (floor i 26))))))
      (format t "~a~a~%" l (subseq (reverse l) 1)))))

Breakdown:

  • (let ((r "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) - variable r holds string range of all characters
  • variable l holds a substring from the r of length based on the line number, where l = r[0:i - (2 * (i - 26) * i % 26)] ... (2 * (i - 26) * i % 26) this part ensures the i to be this sequence 0...26...0
  • format prints the l string and its reversed counter part with skipped first letter (to avoid ABBA, ABCCBA , etc.)

David Horák

Posted 2016-08-03T04:42:23.497

Reputation: 121

Welcome! Consider adding a detailed explanation. We also like to use online interpreters to allow easy testing of code. I like to use TIO. Here is its Common Lisp interpreter. It also has a permalink tool that can automatically generate markup for an answer post.

– mbomb007 – 2019-06-14T19:08:06.823

@mbomb007 Thank you for the suggestions, will add the notes. The REPL code is in the title "Common Lisp" ... the TIO looks better, good to know. – David Horák – 2019-06-14T19:13:35.350

Ah, I didn't notice. Most answers with linked language names are links to the language's home page or documentation. – mbomb007 – 2019-06-14T19:15:54.427

@mbomb007 updated with with the link to TIO and with the breakdown. ... Common Lisp is just my newest guilty pleasure, so there is definitely a better approach, just this is my current best try. Looking forward for any suggestions. – David Horák – 2019-06-14T19:26:18.267

1

See if this helps: Tips for golfing is Lisp

– mbomb007 – 2019-06-14T19:33:27.837

1

Batch, 226 224 bytes

@set z=ABCDEFGHIJKLMNOPQRSTUVWXYZ
@set a=YXWVUTSRQPONMLKJIHGFEDCBA
@for /l %%i in (0,1,25)do @call echo %%z:~0,%%i%%%%z:~%%i,1%%%%a:~-%%i,%%i%%
@for /l %%i in (24,-1,0)do @call echo %%z:~0,%%i%%%%z:~%%i,1%%%%a:~-%%i,%%i%%

Edit: Saved 2 bytes thanks to @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ.

Neil

Posted 2016-08-03T04:42:23.497

Reputation: 95 035

I think you can do )do, but not any other space (except in(), maybe... – Erik the Outgolfer – 2016-08-03T09:20:02.337

@EʀɪᴋᴛʜᴇGᴏʟғᴇʀ Oddly enough I have done this before, just the once: http://codegolf.stackexchange.com/a/68936/17602

– Neil – 2016-08-04T10:04:34.563

1

JavaScript (ES6), 141

for(a=65,q=[],z=[];a<91;z.push(a++))q.push(String.fromCharCode(...z,a,...[...z].reverse()))
a=q.pop(),alert([...q,a,...q.reverse()].join`\n`)

edc65

Posted 2016-08-03T04:42:23.497

Reputation: 31 086

1

QBasic, 151 122 bytes

Really just for fun (via QB64) - it doesn't golf well

Taking some ABS() inspiration from Joffan's VBA answer but applying it differently:

FOR i=-25 TO 25
FOR n=0 TO 25-abs(i)
s$=s$+chr$(n+65)
IF n THEN t$=t$+chr$(90-abs(i)-abs(n))
NEXT
? s$+t$
s$=""
t$=""
NEXT

Previously:

FOR i=0 TO 25
p(i)
NEXT
FOR i=0 to 25
p(25-i)
NEXT
SUB p(i)
FOR n=0 TO i
s$=s$+chr$(n+65)
IF n THEN t$=t$+chr$(65+i-n)
NEXT
? s$+t$
s$=""
t$=""
END SUB

Chris H

Posted 2016-08-03T04:42:23.497

Reputation: 581

1

Retina, 90 88 86 76 bytes

I'm sure it can be made shorter, maybe by using non-verbose replacements and simply outputting at the end. (I tried. I don't think I can do it shorter that way.)

:`
A
A
ABA
{:`

(.)([^Z]\1)
$1$2$2
}T1`__L`L`(?<=(.)[^Z])\1
+:`(.).\1|^A$
$1

Try it online

Thanks to LeakyNun for 14 bytes off

mbomb007

Posted 2016-08-03T04:42:23.497

Reputation: 21 944

@LeakyNun Thanks, idk why I thought I needed that part... – mbomb007 – 2016-08-03T16:21:39.293

Match the second stage with ^ and insert only AB. – Martin Ender – 2016-08-04T14:20:43.670

1

Swift 2.2, 157 142 Bytes

let t={(l:Int)in[Int](1..<l)+[Int](l.stride(to:0,by:-1))}
for x in(t(n).map{t($0).map{"\(UnicodeScalar($0+64))"}.reduce(""){$0+$1}}){print(x)}

ungolfed:

let makeTriangleArray = {(limit: Int) -> [Int] in
    return [Int](1 ..< limit) + [Int](limit.stride(to: 0, by: -1))
}

let n = 26
let lines = makeTriangleArray(n).map{
    makeTriangleArray($0).map{String(UnicodeScalar($0 + 64))}
                         .reduce(""){ $0 + $1}
}

for line in lines {
    print(line)
}

157 bytes:

let t={(l:Int)in[Int](1..<l)+[Int](l.stride(to:0,by:-1))}
print(t(n).map{t($0).map{"\(UnicodeScalar($0+64))"}.joinWithSeparator("")}.joinWithSeparator("\n"))

ungolfed:

let makeTriangleArray = {(limit: Int) -> [Int] in // "called t" above
    return [Int](1 ..< limit) + [Int](limit.stride(to: 0, by: -1))
}

let n = 26
let s = makeTriangleArray(n).map{
    makeTriangleArray($0).map{String(UnicodeScalar($0 + 64))}
                         .joinWithSeparator("")
}.joinWithSeparator("\n")
print(s)

Alexander - Reinstate Monica

Posted 2016-08-03T04:42:23.497

Reputation: 481

1

Jelly, 16 bytes

ŒRAạ
25ÇÇ€‘ịØAj⁷

This uses the same method in my Python answer.

Try it online.

Explanation

ŒRAạ  Define a helper link. Input: n
ŒR    Create the range [-abs(n), , ..., 0, ..., abs(n)]
  A   Take the absolute value of each
   ạ  Return the absolute difference between each value and n

25ÇÇ€‘ịØAj⁷  Main link. No arguments
25           The constant 25
  Ç          Call the helper link on 25 to get [0, 1, ..., 25, ..., 1, 0]
   ǀ        Call the helper link on each value in the previous
     ‘       Increment every value
       ØA    The alphabet (the string 'A..Z')
      ị      Select the char at each index in the alphabet
         j⁷  Join them using newlines and return

miles

Posted 2016-08-03T04:42:23.497

Reputation: 15 654

This is extremely close to this answer

– Leaky Nun – 2016-08-03T18:59:29.997

@LeakyNun It generates the indices into the alphabet using a different method. Since there is only one output the intermediate values only finally become identical after the increment. – miles – 2016-08-03T19:19:34.007

1

PHP, 80 83 bytes

Making half of the triangle then print it in reverse did the trick.

for($a="A";$a<"Z";$b.=$a++)$c.=$b.$a.strrev($b)."
";echo"$c{$b}Z".strrev($c.$b);

Crypto

Posted 2016-08-03T04:42:23.497

Reputation: 862

1

Kotlin, 99 93 88 bytes

(('A'..'Y')+'Z'.downTo('A')).map{println((('A'..it-1)+it.downTo('A')).joinToString(""))}

That's still longer than I expected but I doubt I'll be able to golf it further.

Factorisation doesn't save the day, best I could do is 93 bytes :

fun r(a:Char,b:Char)=(a..b-1)+b.downTo(a)
r('A','Z').map{println(r('A',it).joinToString(""))}

Aaron

Posted 2016-08-03T04:42:23.497

Reputation: 3 689

1

C#, 162 bytes

void p(){for(int i=1;i<54;i++){var a=Enumerable.Range(65,i>27?54-i:i).Select(n=>(char)n);Console.WriteLine(new string(a.Concat(a.Reverse().Skip(1)).ToArray()));}}

Try it online!

downrep_nation

Posted 2016-08-03T04:42:23.497

Reputation: 1 152

1I was wondering what the linq version would look like, you need System.Console.. though right? and shouldn't you also include using System.Linq in the byte count although I'm unsure about that – TheLethalCoder – 2016-08-04T12:15:27.527

Change your for loop to for(int i=0;++i<54;) to save some bytes – TheLethalCoder – 2016-08-04T12:25:52.300

1

HTML, 1412 bytes

<pre>A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
ABCDEFGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYZYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGFEDCBA
ABCDEFEDCBA
ABCDEDCBA
ABCDCBA
ABCBA
ABA
A</pre>

MonkeyZeus

Posted 2016-08-03T04:42:23.497

Reputation: 461

4Please – – – – – – Leaky Nun – 2016-08-04T15:52:18.107

1Actually, with native HTML it's impossible to do better than this – Richard Hamilton – 2016-08-05T17:36:56.253

1@LeakyNun You must be on a whole 'nother level. What is – – – – – – and how do I make it work? – MonkeyZeus – 2016-08-05T17:44:18.333

A possible interpretation of @LeakyNun's comment: http://codegolf.stackexchange.com/a/88984

– manatwork – 2016-08-06T10:56:33.530

1

R, 95 bytes

L=LETTERS;cat("A\n");for(i in 2:50)cat(L[1:(26-abs(i-26))],L[(25-abs(i-26)):1],'\n');cat("A\n")

Ungolfed:

L=LETTERS; #Took idea from @Frederic, I apologize if I shouldn't (first time posting)
cat("A\n")
for(i in 2:50)
{
    cat(L[1:(26-abs(i-26))],L[(25-abs(i-26)):1],'\n')
}
cat("A\n")

Basically, the formula in the cat function in the for loop is a transformation on the absolute value function, mapping n -> n for Letters 2 through 26 and then mapping Letters 27 -> 25, 28 -> 24, ..., 50 -> 2. I don't think it would work if I included the 'A' in this formula, which is why I printed it out separately.

Sol

Posted 2016-08-03T04:42:23.497

Reputation: 11

100 bytes and actually valid. – Giuseppe – 2018-01-15T17:57:20.293

1

MATLAB, 53 Bytes

MATLAB is not made for strings, so this needs some looping. I haven't found a faster way to create a list 1 2 3 4 3 2 1, than [1:4,3:-1:1], which seems really verbose.

Anyway, it's only beaten by 11/55 other submissions, and most of those are golfing languages.

for i=[1:26,25:-1:1]
disp(['',64+[1:i,i-1:-1:1]])
end

Stewie Griffin

Posted 2016-08-03T04:42:23.497

Reputation: 43 471

1Just spent an entertaining fifteen minutes proving you right that this is indeed the shortest - even inline definition of an anonymous function (Octave-only) is still longer. – Sanchises – 2017-07-25T11:42:38.210

1

R, 71 69 bytes

L=LETTERS;for(i in c(1:26,25:1))cat(c(L[1:i],L[i:1][-1]),"\n",sep="")

See here on an online interpreter.

Edit: moved LETTERS outside the loop in order to avoid the curly brackets.

plannapus

Posted 2016-08-03T04:42:23.497

Reputation: 8 610

59 bytes – Giuseppe – 2018-01-15T17:59:05.697

oh I didn't notice that my suggestion was identical to this one.

– Giuseppe – 2018-01-15T17:59:50.577

1

Javascript (ES6), 113 bytes

i=>{for(i=0;i<51;i++,console.log(L))for(j=s=i<26?i:50-i,L="";j>=0;)k=String.fromCharCode(65+j),L=k+(j---s?L+k:L)}

Thanks to manatwork for pointing me to a tip written by William Barbosa to reduce by a byte.

Pandacoder

Posted 2016-08-03T04:42:23.497

Reputation: 190

As William Barbosa wrote in his tip, is shorter to declare an unused dummy parameter.

– manatwork – 2016-08-05T18:45:19.927

1

PHP, 78 Bytes

foreach(range(A,Z)as$r)$o.="\n$t".strrev($t.=$r);echo$o.substr(strrev($o),51);

Jörg Hülsermann

Posted 2016-08-03T04:42:23.497

Reputation: 13 026

1

Rust, 120 bytes

fn main(){for j in -25i8..26{let k=25-j.abs();for i in -k..k+1{print!("{}",(65+k-i.abs())as u8 as char);}println!("");}}

My first attempt at codegolfing in Rust... codegolfing in anything, really. A straightforward attempt, just using for loops and abs().

fn main() {
    for j in -25i8..26 {
        let k=25-j.abs();
        for i in -k..k+1{
            print!("{}",(65+k-i.abs())as u8 as char);
        }
        println!("");
    }
}

Harald Korneliussen

Posted 2016-08-03T04:42:23.497

Reputation: 430

0

CJam, 29 bytes

'[,65>:A,{)A<_W%(;+}%_W%(;+N*

Pretty simple.

Explanation:

'[,65>:A e# Get the string "ABCDEFGHIJKLMNOPQRSTUVWXYZ" and store in A
,{       e# For i in range(26), collecting j:
  )      e#   j += i + 1
  A<     e#   j = a[:i]
  _W%    e#   k = reverse(j)
  (;     e#   k.pop()
  +      e#   j += k
}%       e# End
_W%      e# Duplicate and reverse
(;       e# Pop()
+        e# Append
N*       e# Join with newlines

Esolanging Fruit

Posted 2016-08-03T04:42:23.497

Reputation: 13 542

0

Clojure, 111 bytes

#(let[f(fn[i](concat(range i)(range i -1 -1)))](doseq[i(f 25)](println(apply str(for[j(f i)](char(+ j 65)))))))

A function which prints the result. f is an utility function which creates the sequence from 0 to i and back to 0.

NikoNyrh

Posted 2016-08-03T04:42:23.497

Reputation: 2 361

0

Common Lisp, 175 bytes

(let*((a"abcdefghijklmnopqrstuvwxyz")(f"~a~a~%")(b(reverse a)))(#1=dotimes(i 26)(#2=format t f(#3=subseq a 0 i)(#3#b(- 25 i))))(#1#(i 25)(#2#t f(#3#a 0(- 24 i))(#3#b(1+ i)))))

Try it online!

Ungolfed version:

(let* ((a "abcdefghijklmnopqrstuvwxyz")          ; define the alphabet
       (b (reverse a)))                          ; and reverse it
  (dotimes (i 26)                                ; print first half, 26 lines
    (format t "~a~a~%" (subseq a 0 i) (subseq b (- 25 i))))
  (dotimes (i 25)                                ; print second half
    (format t "~a~a~%" (subseq a 0 (- 24 i)) (subseq b (1+ i)))))

Renzo

Posted 2016-08-03T04:42:23.497

Reputation: 2 260

0

Japt -R, 14 9 bytes

;Bå+ mê ê

Test it


Explanation

;B            :Uppercase alphabet
  å+          :Cumulatively reduce by addition
     m        :Map
      ê       :  Mirror
        ê     :Mirror
              :Implicitly join with newlines and output

Shaggy

Posted 2016-08-03T04:42:23.497

Reputation: 24 623

0

VBA, 91 Bytes

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

For i=-25To 25:For j=0To-Abs(i)+25:s=s+Chr(65+j):Next:?s;StrReverse(Left(s,j-1)):s="":Next

-1 byte for use of ; over & in ? statement

Taylor Scott

Posted 2016-08-03T04:42:23.497

Reputation: 6 709

0

Recursiva, 12 bytes

{pB26'PpZ0(}

Try it online!

Explanation:

{pB26'PpZ0(}
{                   - For each
 p                  - Palindromize [1,2..26,25,24...1]
  B26               - Range 26 [1,2....26]
     '              - iteration command begin
      P             - Print
       p            - palindromize 'ABCDEDCBA'
        Z0(}        - Slice upper-case alphabet "(" from 0 to current count "}" 
                      for example if }=5 'ABCDE'

officialaimm

Posted 2016-08-03T04:42:23.497

Reputation: 2 739

0

Python, 156 bytes

Not impressive, but I'm proud of myself because I'm a noob:

def p(k):
    x=k-1
    while x>-k:
        print(chr(64+(k-abs(x))),end="")
        x-=1
q=25
while q>-27:
    p(26-abs(q))
    print()
    q-=1

Spiffo

Posted 2016-08-03T04:42:23.497

Reputation: 1

Welcome to PPCG! You can save a bunch of bytes by making your indentation single spaces. You can also use tricks like print();q-=1. – Stephen – 2017-09-10T20:26:06.357

0

Canvas, 6 bytes

Z[│]──

Try it here!

Explanation:

Z       push the alphabet
 [ ]    map over the prefixes
  │     palindromize horizontally
    ──  palindromize vertically without mirroring characters

dzaima

Posted 2016-08-03T04:42:23.497

Reputation: 19 048

0

K4, 28 bytes

Solution:

-1 .Q.A@f'(f:{t,x,|t:!x})25;

Explanation:

Define a function to create a palindrome range, create a palindrome range of 0..25..0, and then apply it to each in the list:

-1 .Q.A@f'(f:{t,x,|t:!x})25; / the solution
-1                         ; / print to stdout and swallow return value (-1)
          (             )    / do together
           f:{         }     / define function f as...
                     !x      / range 0..x-1
                   t:        / save as variable t
                  |          / reverse it
                x,           / join with x
              t,             / join with t
                         25  / perform f[25] => 0 1 2.. 25 24.. 1 0
        f'                   / apply f to each of these
   .Q.A@                     / apply (@) these indices to the alphabet A..Z

K4 isn't on TIO, but there's oK which is similar... Try it online!

streetster

Posted 2016-08-03T04:42:23.497

Reputation: 3 635

0

MATL, 12 bytes

26Zv"1Y2@Zv)

Try it on MATL Online

Pretty straightforward in MATL, thanks to the Zv symmetric range function.

26Zv - Make the symmetric range around 26 i.e. [1:26 25:-1:1]

" - Iterate through that

1Y2 - Push the literal 'A':'Z' on the stack

@ - Push the current loop index on the stack

Zv - Make the symmetric range around the index

) - Index into the alphabets using this symmetric range

sundar - Reinstate Monica

Posted 2016-08-03T04:42:23.497

Reputation: 5 296

0

Small Basic, 146 bytes

A Script that takes no input and outputs to the TextWindow Object

For i=-25To 25
For j=0To-Math.Abs(i)+25
c=Text.GetCharacter(65+j)
s=s+c
t=c+t
EndFor
TextWindow.WriteLine(s+Text.GetSubText(t,2,j))
s="
t="
EndFor

Try it at SmallBasic.com! Requires IE/Silverlight

Taylor Scott

Posted 2016-08-03T04:42:23.497

Reputation: 6 709

0

JavaScript - 97 bytes

f=(i,l,q,t,r,a="ABCDEFGHIJKLMNOPQRSTUVWXYZ")=>(r="\n"+q+(c=a[i])+l+t)+(i<25?f(i+1,c,q+c,l+t)+r:"")

Which is called as:

f(0,"","","")

Should the function call factor into the byte count?

MattH

Posted 2016-08-03T04:42:23.497

Reputation: 171

0

Stax, 8 bytes

çtò-+è╥â

Run and debug it

Palindromize the palindromizations of the prefixes of the alphabet. Not very interesting program, but the challenge is back on the front page.

recursive

Posted 2016-08-03T04:42:23.497

Reputation: 8 616

0

Python 2, 86 85 bytes

n=0;exec'x=25-abs(n-25);print bytearray(65+x-abs(y-x)for y in range(2*x+1));n+=1;'*51

Try it at Ideone.

This follows a simple process. First, create the range [0, 1, ..., 24, 25, 24, ..., 1, 0]. Then, for each value x in that range, create another range [0, 1, ..., x, ..., 1, 0] and map each of those values to a character in 'A..Z'. Finally, print each string of characters.

miles

Posted 2016-08-03T04:42:23.497

Reputation: 15 654

0

JavaScript (ES6), 122 bytes

_=>(s='',r=x=>[...x].reverse().join``,t=[...'ABCDEFGHIJKLMNOPQRSTUVWXYZ'].map(c=>s+c+r(s,s+=c)).join`
`)+r(t.slice(0,650))

As an anonymous function. (4 more bytes if you want to alert it)

Test

document.write('<pre>'+(

_=>(
  s='',
  r=x=>[...x].reverse().join``,
  t=
    [...'ABCDEFGHIJKLMNOPQRSTUVWXYZ']
    .map(c=>
      s+c+r(s,s+=c)
    ).join`\n`
)+r(t.slice(0,650))

)());

user81655

Posted 2016-08-03T04:42:23.497

Reputation: 10 181

0

Pyke, 19 16 bytes

27Gm<m[D_t+)RK[X

Try it here!

Blue

Posted 2016-08-03T04:42:23.497

Reputation: 26 661

0

Python 2.7, 136 bytes

x=[chr(y) for y in range(65,91)]
for y in range(25):print ''.join(x[:y]+x[y::-1])
for y in range(25,-1,-1):print ''.join(x[:y]+x[y::-1])

Koppany Horvath

Posted 2016-08-03T04:42:23.497

Reputation: 41

for y in list(range(25)+list(range(24))[::-1]:print ''.join(x[:y]+x[y::-1]) – Leaky Nun – 2016-08-03T19:34:40.123

0

Java 169 156bytes

String a="abcdefghijklmnopqrstuvwxyz";
public void alphabetTriangle(){
  for(int i=0;++i<27;){
    System.out.println(a.substring(0,a)+new StringBuilder(a).reverse().substring(1,-i+1));
  }
}

Golfed

String a="abcdefghijklmnopqrstuvwxyz";void l(){for(int i=0;++i<27;){System.out.println(a.substring(0,a)+new StringBuilder(a).reverse().substring(1,-i+1));}}

It is actually same as the batch solution with some shortcuts

Thanks to @Value Ink for saving 15 bytes by shortening the method name.

Roman Gräf

Posted 2016-08-03T04:42:23.497

Reputation: 2 915

Trim your function name to one letter. This is code-golf, you don't need verbose function names! – Value Ink – 2016-08-03T19:41:45.657

I allways miss that. Thanks ;) – Roman Gräf – 2016-08-03T19:44:30.417

I'm sorry, but its not working.. "System.out.println(a.substring(0,a)+new StringBuilder(a).reverse.substring(1,-i+1));" has some errors – Syamesh K – 2016-08-04T10:51:32.687

reverse is a function I suppose and substring does not take string as argument(a.substring(0,a)??) – Syamesh K – 2016-08-04T10:53:14.733

see mine, http://codegolf.stackexchange.com/a/88646/52212

– Syamesh K – 2016-08-04T11:42:31.440

0

Python 2, 98 bytes

This is what I think is a unique approach in that it recursively builds up half a line at a time and calls the alphabet-building function twice to build a full line. Golfing suggestions welcome.

f=lambda a:a and f(a-1)+chr(64+a)or""
for i in range(-26,27):print f(26-abs(i))+f(27-abs(i))[::-1]

Sherlock9

Posted 2016-08-03T04:42:23.497

Reputation: 11 664

0

Convex, 21 bytes

U{[),U&)\¿@\N]}%)\¿@\

Try it online!

GamrCorps

Posted 2016-08-03T04:42:23.497

Reputation: 7 058

0

Pyth, 13 bytes

L+bt_bjyyM._G

Demonstration

L+bt_b Concatenates a thing with its reverse without the first element. Define as y.

._G: Form all prefixes of the alphabet

yM: Apply y to each element.

y: Apply y to the list as a whole.

j: Join on newlines.

isaacg

Posted 2016-08-03T04:42:23.497

Reputation: 39 268

0

Julia, 84 bytes

!()=(- =join;a=-char(65:90);b=[a[1:x+1]*a[x:~0:1]for x=0:25];vcat(b,b[25:~0:1])-"
")

Mama Fun Roll

Posted 2016-08-03T04:42:23.497

Reputation: 7 234

0

Racket, 147 bytes

At least it beats QBasic.

((λ(x)(display(string-join(x(build-list 26(λ(n)(list->string(map integer->char(x(range 65(+ 66 n))))))))"\n")))(λ(m)(append m(cdr(reverse m)))))

Steven H.

Posted 2016-08-03T04:42:23.497

Reputation: 2 841

0

Python, 109 bytes

z="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def a(x):v=z[:x]+z[x-26::-1]+"\n";return v+a(x+1)+v if x<25 else v
print a(0)

Build up a string with a recursive call in the middle to build the triangle out. Might come back to try and get it <100.

greyShift

Posted 2016-08-03T04:42:23.497

Reputation: 221

0

Python 3, 123 101 98 bytes

for i in range(1,52):r=[chr(j+65)for j in range(abs(26*(i//26)-i%26))];print(''.join(r+r[-2::-1]))

lol I am really bad at this

thanks @Leaky Nun for the r[-1::-1] == r[:-1][::-1] tip (:

Alternative solution, with help from @Leaky Nun (8885 bytes)

for i in range(1,52):r=[*map(chr,range(65,91-abs(i-26)))];print(''.join(r+r[-2::-1]))

Jeffrey04

Posted 2016-08-03T04:42:23.497

Reputation: 131

Why do you need lambda :? – Leaky Nun – 2016-08-05T04:14:09.477

was originally this def A(l):r=[chr(i + ord('A'))for i in range(l)];return ''.join(r+r[:-1][::-1]) – Jeffrey04 – 2016-08-05T04:18:42.367

for i in range(1,52):print((lambda r:''.join(r+r[:-1][::-1]))([chr(j+65)for j in range(abs(26*(i//26)-i%26))])) – Leaky Nun – 2016-08-05T04:22:43.303

Also, r[:-1][::-1] can be written as r[-1::-1] – Leaky Nun – 2016-08-05T04:23:19.340

You can shift the whole range instead of shifting j, and then you can use map – Leaky Nun – 2016-08-05T04:33:10.530

I don't get it lol – Jeffrey04 – 2016-08-05T04:35:47.800

r=map(chr,range(65,65+abs(26*(i//26)-i%26))) – Leaky Nun – 2016-08-05T04:42:10.893

OOOOOOOOOOOOOOOOOOH – Jeffrey04 – 2016-08-05T04:43:53.533

abs(26*(i//26)-i%26) is really i>26 and 52-i or i – Leaky Nun – 2016-08-05T04:44:19.217

lol, i was struggling to get that written in and and or operator, but gave up lol – Jeffrey04 – 2016-08-05T04:45:22.177

65+abs(26*(i//26)-i%26) would become i>26and 117-i or 65+i – Leaky Nun – 2016-08-05T04:45:52.693

Which should become 91-abs(i-26) – Leaky Nun – 2016-08-05T04:47:05.813

lol thumb up #salute – Jeffrey04 – 2016-08-05T04:48:52.787

lol, apparently 'abc'[-1::-1] is actually 'cba' instead of 'ba' – Jeffrey04 – 2016-08-05T04:53:36.770

Then just do 'abc'[-2::-1] (Don't you test your answers before updating?) – Leaky Nun – 2016-08-05T04:59:34.880

somehow missed that one :P – Jeffrey04 – 2016-08-05T05:01:52.177

0

Guile, 188 bytes

(define(t d e)(if(= e 27)(apply string-append(map list->string(append(reverse(cdr d))d)))(t(cons(let((a(map integer->char(iota e #x41))))(append a(cdr(reverse a))'(#\newline)))d)(1+ e))))

Or in a readable form:

(define (triangle done depth)
  (if (= depth 27)
    (apply string-append
     (map list->string
      (append (reverse (cdr done))
              done)))
    (triangle 
     (cons (let ((alphabet (map integer->char (iota depth #x41))))
            (append alphabet (cdr (reverse alphabet)) '(#\newline)))
      done)
    (1+ depth))))

Call the program with (triangle '() 1) or (t '() 1), note that srfi-1 needs to be loaded.

The program creates a list of the chars in the alphabet, from a to the last letter in the current line. It then takes that lists, reverses it and removes the original last character, appends the two lists and adds a newline character at the end. It then does that 26 times, from A to Z. It then converts the lists to strings and concats them.

The program returns a string, which then should be passed to display, but this wasn't needed in the challenge.

HugoNikanor

Posted 2016-08-03T04:42:23.497

Reputation: 1

Which version? I get “Wrong number of arguments to #<procedure iota (n)>” with GNU Guile 2.0.11. – manatwork – 2016-08-05T08:45:02.247

Tested with Guile 2.0.12, but that sounds more like srfi-1 isn't loaded. Load it with guile --use-srfi=1 when starting, or as a module with (use-modules (srfi srfi-1)). – HugoNikanor – 2016-08-06T09:38:31.687

Sorry, that srfi-1 related note said nothing to me. Indeed, this way works fine. BTW, if the code needs module/package/library/unit/whatever loaded or requires command line option to turn on non-default processing mode, those should be included in the code length. Can't tell for sure whether it includes this srfi-1 case, but probably yes. – manatwork – 2016-08-06T10:11:46.487

0

JavaScript (177 175 chars)

This is my best attempt at golfing this problem. I cannot find a way to do this with fewer characters

o='';

for(i=1;i<=26;i++){
 l='';
  for(j=1;j<=i;j++){
   l+=String.fromCharCode(j+64);
  }
 o+=l+l.slice(0,l.indexOf(l.slice(-1))).split('').reverse().join('')+"\n";
}

console.log(o);

Richard Hamilton

Posted 2016-08-03T04:42:23.497

Reputation: 101

0

Clojure, 182 bytes

(let[d dec w str c char n \u000A](defn p[x s](if(= x 65)s(p(d x)(w(c(d x))s(c(d x))))))(println(#(if(= % 65)%2(recur(d %)(w(p(d %)(c(d %)))n %2(p(d %)(c(d %)))n)))90(w(p 90 "Z")n))))

My first codegolf :). There is probably a much easier way to do it, but I am very new to clojure.

Ideone

Tyrannosaur

Posted 2016-08-03T04:42:23.497

Reputation: 101

0

Racket 327 bytes

(define(sr s)(list->string(reverse(string->list s))))(let loop((n 0)(s"A")(ol'("A")))(let*((st string)(mr(floor(/(string-length s)2)))
(mc(string-ref s mr))(ss(substring s 0 mr))(ns(string-append ss(st mc)(st(integer->char(+ 65(add1 n))))(st mc)(sr ss))))(if(< n 25)
(loop(add1 n)ns(cons ns ol))(append(reverse ol)(rest ol)))))

Ungolfed:

(define (f)

  (define (sr s)                     ; sub-fn to reverse a string;
    (list->string
     (reverse
      (string->list s))))

  (let loop ((n 0)
             (s "A")
             (ol '("A")))
    (let* ((st string)
           (mr (floor(/(string-length s)2)))
           (mc (string-ref s mr))
           (ss (substring s 0 mr))
           (ns (string-append 
                ss
                (st mc)
                (st (integer->char (+ 65(add1 n))))
                (st mc)
                (sr ss))))
      (if (< n 25)
          (loop (add1 n)
                ns
                (cons ns ol))
          (append(reverse ol)(rest ol))
          ))))

Testing:

(f)

Output:

'("A"
  "ABA"
  "ABCBA"
  "ABCDCBA"
  "ABCDEDCBA"
  "ABCDEFEDCBA"
  "ABCDEFGFEDCBA"
  "ABCDEFGHGFEDCBA"
  "ABCDEFGHIHGFEDCBA"
  "ABCDEFGHIJIHGFEDCBA"
  "ABCDEFGHIJKJIHGFEDCBA"
  "ABCDEFGHIJKLKJIHGFEDCBA"
  "ABCDEFGHIJKLMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNONMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNOPQRSTUVWXYZYXWVUTSRQPONMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNONMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMNMLKJIHGFEDCBA"
  "ABCDEFGHIJKLMLKJIHGFEDCBA"
  "ABCDEFGHIJKLKJIHGFEDCBA"
  "ABCDEFGHIJKJIHGFEDCBA"
  "ABCDEFGHIJIHGFEDCBA"
  "ABCDEFGHIHGFEDCBA"
  "ABCDEFGHGFEDCBA"
  "ABCDEFGFEDCBA"
  "ABCDEFEDCBA"
  "ABCDEDCBA"
  "ABCDCBA"
  "ABCBA"
  "ABA"
  "A")

rnso

Posted 2016-08-03T04:42:23.497

Reputation: 1 635

1You can shorten your names (i.e. (define (a s) rather than (define (sr s), (let l rather than (let loop). In addition, it was required to output that exact text, so you'd have to join with newlines. – Esolanging Fruit – 2017-05-01T03:37:30.190

-1

Jelly, 9 bytes (non-competing)

ØAḣJŒBŒḄY

Try it online!

Erik the Outgolfer

Posted 2016-08-03T04:42:23.497

Reputation: 38 134

@LeakyNun Thanks, although I'll keep it here, since that was a comment. – Erik the Outgolfer – 2017-05-01T15:45:12.483