26
\$\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.

Uppercase letters with no extra output are preferred; however, lowercase letters and/or extra whitespace are acceptable if capitalizing/stripping would lengthen your solution.

EDITED TO ADD: The solution must be complete enough to execute. I should be able to invoke an implementation of the language, paste the code from the answer, and get results, without typing any additional code.

The above question of completeness came up in the context of a C solution. Surely there must be a standing rule or convention about this on a code golfing site? If so, I'll gladly yield to the community guidelines. But this is my take:

  1. With regard to C specifically, you need to include (and count) the main(){...} around the code, since it won't compile otherwise. Warnings because there's no #include <stdio.h> are fine as long as the code still compiles. In general, a compiled language requires a compilable unit.

  2. A bare expression that yields the desired results is acceptable if there's a way to execute the expression directly; for instance, if the language has a REPL. So you can submit Haskell without a main= as long as it actually works as written at e.g. the ghci prompt. But since that means putting let on your declarations, it may be a net win to stick with the runhaskell format.

  3. Similarly, awk scripts should be in BEGIN (or END, with the assumption that stdin is attached to /dev/null) blocks since we're not processing any input.

etc.

\$\endgroup\$
  • 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 '13 at 17:26
  • \$\begingroup\$ And do I have to output only the alphabet? \$\endgroup\$ – Justin Dec 13 '13 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 '13 at 17:44
  • 3
    \$\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 '13 at 17:46
  • \$\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 '13 at 19:44

81 Answers 81

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
    \$\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\$ – Jonathan Frech Jul 9 '18 at 20:09
1
\$\begingroup\$

Attache, 28 bytes

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

Try it online!

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

PC DOS 8086 Assembly, 29 bytes

b11a bb04 04b4 09ba 1901 cd21 fecb 75fa fe06 1901 8adf e2f2 c341 0d0a 24

Ungolfed:

    MOV  CL, 'Z'-'A'+1      ; set up main loop counter (26)
    MOV  BX, 0404H          ; character repeat counter
    MOV  AH, 9              ; DOS display string function
    MOV  DX, OFFSET MSG     ; memory address of string
DISP:
    INT  21H                ; output letter string to display
    DEC  BL                 ; decrement repeat counter
    JNZ  DISP               ; if BL > 0, repeat
    INC  BYTE PTR [MSG]     ; increment ASCII char in memory to next letter
    MOV  BL, BH             ; reset repeat counter
    LOOP DISP               ; go to next letter
    RET                     ; return to DOS
MSG DB 'A',0DH,0AH,'$'

Try it offline! (download ALPHA.COM and run in DOSBox or favorite DOS VM).

Output:

A>ALPHA.COM
A
A
A
A
B
B
B
B
C
C
C
C
...
(you get the idea)
...
X
X
X
Y
Y
Y
Y
Z
Z
Z
Z
\$\endgroup\$
1
\$\begingroup\$

K (oK), 17 16 bytes

Solution:

`0:`c$+,65+&26#4

Try it online!

Explanation:

`0:`c$+,65+&26#4 / the solution
            26#4 / generate a vector of 26 4s
           &     / where, turns this into 0 0 0 0 1 1 1 1 2 2 2 2 etc
        65+      / add 65 to this vector
       ,         / enlist (,:) each-both (')
      +          / flip
   `c$           / convert to characters
`0:              / print to stdout

Notes:

  • -1 byte with thanks to @ngn!
\$\endgroup\$
  • 1
    \$\begingroup\$ ,:' -> +,­­ \$\endgroup\$ – ngn Jan 27 at 15:40
1
\$\begingroup\$

@NUM, 43 bytes

#1@13#0@65|#1$#0$#1$#0$#1$#0$#1$#0$+<90{*0}

(I messed up on some of the code, now it works, but is almost double the size...)

\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to PPCG! Languages are required to have an implementation (interpreter/compiler), so you'll need to either link to one or write one. \$\endgroup\$ – lirtosiast Jan 29 at 2:41
  • \$\begingroup\$ I would call your language implementation an interpreter. Also, I am unsure if a leading newline is valid. Furthermore, I would recommend not to send the execution time to stdout. \$\endgroup\$ – Jonathan Frech Jan 29 at 8:01
1
\$\begingroup\$

Charcoal, 6 bytes

Fα↓×⁴ι

Try it online (verbose) or try it online (pure).

Explanation:

Loop over the characters of the uppercase alphabet:

For(a)
Fα

Repeat the current letter 4 times, and print it in a downward direction:

Print(:Down, Times(4, i));
↓×⁴ι
\$\endgroup\$
  • \$\begingroup\$ Hm, that's 6 characters, but I don't see how you can encode them into 6 bytes. I would change the title to just claim "6" instead of "6 bytes". Sadly, 6 characters is still one more than APL. \$\endgroup\$ – Mark Reed Jan 29 at 17:01
  • \$\begingroup\$ @MarkReed In UTF-8 this would indeed be a bit more than 6 bytes (15 to be exact). However, Charcoal uses, just like most codegolf languages (i.e. Jelly, 05AB1E, etc.), a custom code page for all 256 characters it knows, where each character is encoded as a single byte. \$\endgroup\$ – Kevin Cruijssen Jan 29 at 17:07
  • \$\begingroup\$ Ah, my mistake. Didn't realize it was limited to a single code page. Carry on. :) \$\endgroup\$ – Mark Reed Jan 30 at 4:49
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\$
  • \$\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 at 11:54
  • \$\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 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\$ – KrystosTheOverlord Jan 31 at 12:09
  • \$\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 at 12:18
1
\$\begingroup\$

Cardinal, 68 bytes

%+v
(A+
~ =
([t
' >t*~v
8 v~'n<
D<v< #
-~
~+,
 ,,
 ,,~
 ,,-
 ,~
>^R^

Try it online!

Explanation

%+v
(A+
~ =
([t
' >t*~v
8 v~'n<
**** #

Sets up loops for printing and corrects timing between loops. Right column sets up space to be printed in a loop of 25 times while left column sets up letters of alphabet starting with A to be printed.

D<v<
-~
~+,
 ,,
 ,,~
 ,,-
 ,~
>^R^

Left 2 columns print out each letter in alphabet while right 2 columns print out newlines.

How the loops work:

The inactive value of the pointer is set to the number of times to iterate through the loop. The timing of the loops is set up so that it will print alphabet character then newline four times before decrementing the inactive value of the pointer. The alphabet character to print was selected at the start by assigning the ascii value of A to the active value of the pointer "(A" in the code. After each loop of printing, this active value is incremented by one to print the next character in the alphabet.

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

Q, 16

........

-1@'(,/)4#'.Q.A;
\$\endgroup\$
0
\$\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\$
0
\$\begingroup\$

Bash 28 26

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

///, 207 bytes

A
A
A
A
B
B
B
B
C
C
C
C
D
D
D
D
E
E
E
E
F
F
F
F
G
G
G
G
H
H
H
H
I
I
I
I
J
J
J
J
K
K
K
K
L
L
L
L
M
M
M
M
N
N
N
N
O
O
O
O
P
P
P
P
Q
Q
Q
Q
R
R
R
R
S
S
S
S
T
T
T
T
U
U
U
U
V
V
V
V
W
W
W
W
X
X
X
X
Y
Y
Y
Y
Z
Z
Z
Z
\$\endgroup\$
0
\$\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\$
0
\$\begingroup\$

SOGL V0.12, 5 bytes

Z{4⌡T

Try it Here!

\$\endgroup\$
0
\$\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\$
0
\$\begingroup\$

Tcl, 51 bytes

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

Try it online!

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

Python 2, 39 bytes

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

Try it online!

\$\endgroup\$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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