33
\$\begingroup\$

Note that this is not the same as Print the alphabet four times.

This task is to write a program to generate four copies of each letter of the English alphabet, one letter per line, on standard output:

A
A
A
A
B
B
B
B

etc.

The output should include newlines after each letter.

Lowercase letters and/or extra whitespace are acceptable.

The solution must be a complete program.

This is so answers will be scored in bytes with a lower score being the goal.

\$\endgroup\$
5
  • 4
    \$\begingroup\$ I'm slightly confused. Is the challenge here just to output the alphabet with each letter repeated four times, or does the output actually need to be stored in a file as well? \$\endgroup\$
    – Iszi
    Dec 13, 2013 at 17:26
  • \$\begingroup\$ And do I have to output only the alphabet? \$\endgroup\$
    – Justin
    Dec 13, 2013 at 17:33
  • \$\begingroup\$ @MarkReed Do I need to print it with newlines in between? Why not just print it, but newlines optional? \$\endgroup\$
    – Justin
    Dec 13, 2013 at 17:44
  • 4
    \$\begingroup\$ Also, I recommend rephrasing your challenge so that it is more like a challenge and less like telling the story of how you invented your answer. \$\endgroup\$
    – Justin
    Dec 13, 2013 at 17:46
  • 1
    \$\begingroup\$ The last bit muddies the whitespace rules just a tad. Could you please clarify? Particularly, am I reading it right to interpret that extra whitespace is okay but omission of newlines is not? \$\endgroup\$
    – Iszi
    Dec 13, 2013 at 19:44

104 Answers 104

2
\$\begingroup\$

naz, 72 bytes

9a1a2x1v9m2x2v3d2m4a1x1f1a2x3v1o1v1o3v1o1v1o3v1o1v1o3v1o1v1o3v3x2v1l0x1f

Explanation (with 0x commands removed)

9a1a2x1v                                         # Set variable 1 equal to 10 (newline)
9m2x2v                                           # Set variable 2 equal to 90 ("Z")
3d2m4a                                           # Set the register to a value of 64 ("@")
1x1f                                             # Function 1
    1a                                           # Add 1 to the register
      2x3v                                       # Store the new value in variable 3
          1o1v1o3v1o1v1o3v1o1v1o3v1o1v1o         # Output it, then a newline, four times
                                        3v       # Load variable 3 into the register
                                          3x2v1l # Jump back to the start of the function
                                                 # if the register is less than variable 2
1f                                               # Call function 1
\$\endgroup\$
2
\$\begingroup\$

jq -nr, 32 bytes

range(26)+65|[.]|implode|.,.,.,.

Try it online!

.,.,.,. may just be the funniest thing I've written on this site. This language's generator system never ceases to amaze me.

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

Jelly, 7 bytes

ØAṄ4¡€*

Try it online!

Explanation

ØAṄ4¡€*
   ØA: alphabet 
   Ṅ: print w/ new line
   4¡: repeat 4 times
   €: each
   *: to error out(see below)

The reason I use the * is to error out the code so it wont print the whole alphabet at the end (I'm very new to jelly). If anyone can tell me what character to use in combination with to achieve this, I would appreciate it!

\$\endgroup\$
3
  • \$\begingroup\$ Welcome to Code Golf, and impressive first answer! Jelly implicitly outputs the final value at the end of the program, and so Jelly programs normally avoid using in favour of printing at the end. For example, rather than printing each one 4 times, you can repeat each letter 4 times (to create 'AAAABBBBCCCC....'), then join by newlines. This approach takes 5 bytes \$\endgroup\$ Sep 5, 2021 at 15:22
  • \$\begingroup\$ thank you for the quick response! I see what you mean about editing te string rather than the output... I learned something new! \$\endgroup\$
    – Baby_Boy
    Sep 5, 2021 at 15:25
  • \$\begingroup\$ If you're interested in learning more Jelly, feel free to drop by the Jelly Hypertraining chat room :) \$\endgroup\$ Sep 5, 2021 at 15:27
2
\$\begingroup\$

Vyxal, 6 bytes

4kA*s⁋

Try it Online!

4      - Literal
 kA    - Uppercase alphabet
   *   - Multiplication
    s  - Sort
     ⁋ - Join by newlines
\$\endgroup\$
2
\$\begingroup\$

Vyxal j, 4 bytes

kA4•

Try it Online!

Multiplies each letter of the alphabet by 4, and joins on newlines.

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

Q, 16

........

-1@'(,/)4#'.Q.A;
\$\endgroup\$
1
\$\begingroup\$

4DOS, 59 (including newlines)

Why? Because not enough people use it any more and it's still the same size as C and shorter than F#!

do i=65 to 90
@for %j in (1 2 3 4) do echo %@CHAR[%i]
enddo
\$\endgroup\$
1
\$\begingroup\$

Bash 28 26

echo {a..z}{,,,}|tr \  \\n
\$\endgroup\$
1
  • \$\begingroup\$ A shame bash doesn't do curly-brace expansion on here-strings. \$\endgroup\$
    – Mark Reed
    Dec 15, 2013 at 4:40
1
\$\begingroup\$

JavaScript (59 56)

for(i=65;i<91;i+=1/4)console.log(String.fromCharCode(i))
\$\endgroup\$
3
  • \$\begingroup\$ Hey @user113215, you can save 1 extra char by doing i|0 instead of i,10! \$\endgroup\$ Dec 14, 2013 at 16:09
  • \$\begingroup\$ @DomHastings No, i,10 prints a newline as well as the letter. i|0 is the same as just i. Considering that console.log adds an implicit newline, however, I suppose this could be shortened to just i. \$\endgroup\$
    – quietmint
    Dec 15, 2013 at 5:19
  • \$\begingroup\$ Ahhh, i see! Apologies, for some reason I thought it was doing some kind of parseInt! \$\endgroup\$ Dec 15, 2013 at 9:09
1
\$\begingroup\$

LINQ, 59 bytes

from i in Enumerable.Range(0, 104)select(char)(65+i/4)+"\n"

LINQ expression, try it with LinqPad. The select part is a bit too C#ist but I guess that fine.

from i                        // for each variable
in Enumerable.Range(0, 104)   // in the range 0, 26*4
select(char)(65+i/4)+"\n"     // get the letter and a newline
\$\endgroup\$
1
\$\begingroup\$

C#, 86 bytes

class P{static void M(){for(var i=65d;i<91;i+=.25)System.Console.WriteLine((char)i);}}

a full program...

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

C#, 88 bytes

var s="";int i,j;for(i=0;i++<26;){for(j=0;j++<4;)s+=(char)(i+64)+"\n";}Console.Write(s);

Try it with this REPL shell: https://csharppad.com/

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

dc, 23 bytes

260[d4/PAP1+d364>M]dsMx

Try it online!

Since precision is 0 by default, 260, 261, 262, and 263 all return 65 when divided by 4. All we need to do, then, is start with 260 on the stack, and continue duplicating the top of stack, dividing by 4, printing that code point and a line feed and then incrementing by one until we hit 364 (91*4).

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

SOGL V0.12, 5 bytes

Z{4⌡T

Try it Here!

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

Taxi, 1215 449 bytes

(I am calling this the Magna Carta byte count)

It turns out to be way shorter to just hard code the text.

'A\nA\nA\nA\nB\nB\nB\nB\nC\nC\nC\nC\nD\nD\nD\nD\nE\nE\nE\nE\nF\nF\nF\nF\nG\nG\nG\nG\nH\nH\nH\nH\nI\nI\nI\nI\nJ\nJ\nJ\nJ\nK\nK\nK\nK\nL\nL\nL\nL\nM\nM\nM\nM\nN\nN\nN\nN\nO\nO\nO\nO\nP\nP\nP\nP\nQ\nQ\nQ\nQ\nR\nR\nR\nR\nS\nS\nS\nS\nT\nT\nT\nT\nU\nU\nU\nU\nV\nV\nV\nV\nW\nW\nW\nW\nX\nX\nX\nX\nY\nY\nY\nY\nZ\nZ\nZ\nZ' is waiting at Writer's Depot.Go to Writer's Depot:w 1 r 3 l 2 l.Pickup a passenger going to Post Office.Go to Post Office:n 1 r 2 r 1 l.

Try it online!

Ungolfed / formatted:

'A\nA\nA\nA\nB\nB\nB\nB\nC\nC\nC\nC\nD\nD\nD\nD\nE\nE\nE\nE\nF\nF\nF\nF\nG\nG\nG\nG\nH\nH\nH\nH\nI\nI\nI\nI\nJ\nJ\nJ\nJ\nK\nK\nK\nK\nL\nL\nL\nL\nM\nM\nM\nM\nN\nN\nN\nN\nO\nO\nO\nO\nP\nP\nP\nP\nQ\nQ\nQ\nQ\nR\nR\nR\nR\nS\nS\nS\nS\nT\nT\nT\nT\nU\nU\nU\nU\nV\nV\nV\nV\nW\nW\nW\nW\nX\nX\nX\nX\nY\nY\nY\nY\nZ\nZ\nZ\nZ' is waiting at Writer's Depot.
Go to Writer's Depot: west 1st right 3rd left 2nd left.
Pickup a passenger going to Post Office.
Go to Post Office: north 1st right 2nd right 1st left.
\$\endgroup\$
1
\$\begingroup\$

Lua, 53 Bytes

Simple solution, we're using the range [260,363] which is 65*4 and 90*4+3 (letter A and Z) to iterate.

Then we just have to do an euclidian division by 4 and print out each letter 4 times this way.

Edit: Approved @MCAdventure10's edit that pointed out a rounding error that made only one Z being printed out, it wasn't deviating from my original idea and didn't change the byte count, thus,I approved it.

for i=260,363 do print(("").char(math.floor(i/4)))end
\$\endgroup\$
1
\$\begingroup\$

Funky, 32 bytes

fori=0i<104i++print("%c"%65+i/4)

Try it online!

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

Tcl, 51 bytes

time {puts [format %c [expr (259+[incr i])/4]]} 104

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Clever use of time to avoid the for loop. \$\endgroup\$
    – Mark Reed
    Feb 26 at 4:19
1
\$\begingroup\$

Pyth - 7 Bytes

VrG1V4N

Explanation

VrG1V4N
V       For each character N in
  G     The alphabet
 r 1    Converted to uppercase:
    V4  For each variable from 0 to 3:
      N Implicitly print N
\$\endgroup\$
1
\$\begingroup\$

F# (.NET Core), 43 bytes

for i in 260..363 do printfn"%c"(char(i/4))

Try it online!

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

Add++, 19 bytes

L,91 65rbU€C4€*JbUn

Try it online!

How it works

L,			; Create an anonymous function
	91 65rbU	; Push [65 ... 90]	STACK = [65 66 ... 89 90]
	€C		; Convert to chars;	STACK = ['A' 'B' ... 'Y' 'Z']
	4€*		; Repeat each 4 times;	STACK = ['AAAA' ... 'ZZZZ']
	JbUn		; Join by newlines;	STACK = ['A\nA\n ... Z\nZ']
\$\endgroup\$
1
\$\begingroup\$

Jelly, 5 bytes

ØAx4Y

Try it online!

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

Python 2.7, 78 bytes

x='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for e in x:
    for d in range(0, 4):
        print e
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Golfing challenge submissions have to make an attempt at golfing. In your code there is unnecessary white space, the variable x is declared once so could be inlined and the last for loop's body is not a compound statement so could be put on the same line. I also suggest reading the Python tips page. \$\endgroup\$ Jul 9, 2018 at 20:09
1
\$\begingroup\$

Attache, 28 bytes

Print@Char=>Flat!4&`&=>65:90

Try it online!

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

Python 2, 39 bytes

i=65;exec('print chr(i);'*4+'i+=1;')*26

Try it online!

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

BRAINF 115 BYTES...

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

I know this isn't going to in any awards for being the smallest, but I just thought it would be funny to use one of the hardest to understand languages.

Breakdown of Code

Cell zero is used for counting for setup, cell 1 and 3 are used to print, and cell two is used to count for the printing sequence

0 1 2 3 [setup][newline char][print counter][output char (set to A to begin)]

++++[->+++>+++>+++<<<]>+>+>+  sets cells 1, 2, and 3 to 13(new line)
<<<++++[->>+++>+++<<<]>>+>+   sets cells 2 and 3 to 26 (length of alphabet)
<<<+++++++++++++[->>>+++<<<]  sets cell  3 to 65(A)
>>[->.<<.>>.<<.>>.<<.>>.<<.>>+<] increments cell 3, prints alternating between cell 1 
                              and 3, and decrements cell 2.

Here is a Brainf compiler to test it (use the one w/out any newlines)

\$\endgroup\$
4
  • 2
    \$\begingroup\$ Is it so hard to just say brainfuck? At the very least brainf*ck if you're that uncomfortable with swearing. Saying BRAINF just makes everyone confused about what you're referring to \$\endgroup\$
    – Jo King
    Jan 31, 2019 at 11:54
  • 1
    \$\begingroup\$ also, the triple exclamation mark is a bit too excitable for almost twice the bytecount of the previous brainfuck answer \$\endgroup\$
    – Jo King
    Jan 31, 2019 at 12:07
  • \$\begingroup\$ @JoKing I wrote this before i realized that there was another Brainfuck program, sorry about that, i never got to fixing it \$\endgroup\$ Jan 31, 2019 at 12:09
  • 1
    \$\begingroup\$ having a longer answer is okay, especially in a language like brainfuck. the tips for golfing in brainfuck page might interest you for future submissions \$\endgroup\$
    – Jo King
    Jan 31, 2019 at 12:18
1
\$\begingroup\$

cQuents, 18 bytes

|
#104&h64+k,Z,Z,Z

Try it online!

Explanation

|
                  use newline as delimiter
#104              default input n = 104
    &             print first n terms in sequence
                  each term is the next term in the comma-delimited sequence, restarting 
                  and incrementing k when the end of the terms list is reached
     h64+k        chr ( 64 + k )
          ,Z,Z,Z  next three terms equal the previous term
\$\endgroup\$
1
\$\begingroup\$

05AB1E, 6 bytes

A€D€D»

Try it online!

Explanation

A        # push lowercase alphabet
 €       # for each char:
  D      # duplicate it
   €D    # duplicate each char again
     »   # join by newlines
         # implicit output
\$\endgroup\$
1
\$\begingroup\$

Brian & Chuck, 32 bytes

A{<?
!{>-_{.>.<.>.<.>.<.+>.>-?

Try it online!

code:

Brian:
A                       ["A", 11, 26] Variables: Letter, newline+1, letter count
{<?                        restart current code portion of Chuck

Chuck:
code 1:
{>-                        go to "newline+1" and decrement it, so it becomes a newline

code 2:
{                          go to letter
.>.<.>.<.>.<               print letter and newline three times
.+                         print and increment letter
>.                         print 4th newline
>-                         decrement counter
?                          if counter > 0, switch to Brian (who just restarts Chuck's code 2)
\$\endgroup\$
1
\$\begingroup\$

GolfScript, 17 bytes

91,65>''+{...}%n*

Try it online!

Explanation

91,65>            # Genearate initial alphabet
      ''+         # Convert to a string
         {...}%   # For every item, copy 3 times
               n* # Join the resulting string by newlines
                  # (because a string is a codepoint array)
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.