# Generate alphabet with 4 copies of each letter

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.

• 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?
– Iszi
Dec 13 '13 at 17:26
• And do I have to output only the alphabet? Dec 13 '13 at 17:33
• @MarkReed Do I need to print it with newlines in between? Why not just print it, but newlines optional? Dec 13 '13 at 17:44
• 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. Dec 13 '13 at 17:46
• 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?
– Iszi
Dec 13 '13 at 19:44

## APL (5)

⍪4/⎕A


Matrix format (⍪) of 4-replication (4/) of alphabet (⎕A).

• Seems unlikely to be beaten. :) Dec 17 '13 at 12:53
• I count 9 bytes. Oct 23 '16 at 4:06
• APL uses a code-page that maps each of the characters it uses to one byte. This code page can be found here, on IBM's website. Oct 23 '16 at 4:08
• @StanStrum I believe the link is dead because of deprecation, but for the sake of code golfing this meta answer should work. Mar 27 '18 at 2:11

# Python - 37

for i in range(104):print chr(i/4+65)


i goes from 0 to 104; it is divided by four and added to the ascii value for A, and the resulting character is printed.

• I take it Python uses integer division by default? Would kinda be nice if PowerShell did right now. As it is, the code necessary to force it into integer division is too long for this trick to help me save anything on my script.
– Iszi
Dec 13 '13 at 17:42
• @lszi - Python takes its cue from the type of the operands. 3/4 is 0, while 3.0/4.0 is 0.75; range() generates integers. Dec 13 '13 at 17:43
• This does not work on newer versions of python. First, the print function must be called with brackets, and / no longer does integer division by default (even if both numbers are integers), which is //'s job Try: for i in range(104):print(chr(i//4+65))
– user10979
Dec 14 '13 at 8:27
• @Consciousness I know that. I deliberately chose to use an old version so that it can be golfed better. If you were to run this at Ideone.com, you'd choose "Python" instead of "Python 3" Dec 14 '13 at 19:48
• @Consciousness - by "newer versions of python", you're referring to "Python 3", which is far from universally adopted at this point. I generally assume that anything claiming to be "Python" without a specified version is Python 2.x until proven otherwise; Python 3 code tends to be explicitly so labeled. Apr 10 '14 at 20:01

# R, 3028 27

write(rep(LETTERS,e=4),1,1)


Former version with 30 bytes:

cat(rep(LETTERS,e=4),sep="\n")

• I think a literal newline is a byte shorter :) Jul 25 '17 at 15:31
• @Giuseppe Can you specify this idea? Jul 25 '17 at 15:34
• Try it online! Jul 25 '17 at 15:36
• @Giuseppe Really good idea! Thanks for pointing out. Jul 25 '17 at 15:37
• You can use 1 instead of "" to specify stdout in write as well, which saves another byte. Mar 16 '18 at 12:53

## C, 59

I submit this, an uncompetitively long answer, simply because I don't see a C submission yet. And that makes me sad. :-/

LATER: Props to @moala for doing a "/4" int version of this, saving 13 chars!

float i;main(){while(i<26)printf("%c\n",65+(int)i),i+=.25;}

• I've edited my answer, now saving even 2 more chars! Dec 17 '13 at 1:37
• and another one! Dec 17 '13 at 2:42

# J: 18 13

4#u:65+i.26 1


I'm still pretty shaky with J, so this could probably be improved

• You can use replicate (#) instead of division like so: 4#u:65+i.26 1. Also, ~ swaps a function's arguments, so if you ever find yourself doing (expression) F value, you can replace that with value F~ expression to save a character. Dec 14 '13 at 1:34
• @marinus Thanks for the tip. I'm still learning J and it's hard to find any good info with those kinds of tricks. Dec 14 '13 at 1:55
• 4#65{26,.\a. for 12 bytes. Oct 29 '17 at 6:59

## Ruby, 23

puts ([*?A..?Z]*4).sort


All credit to @manatwork -- upvote his comment, not this. :)

• Huge. @manatwork, I'll make the edit but obviously I don't deserve any credit! Dec 13 '13 at 19:01
• Better make it puts [*?A..?Z].map{|i|[i]*4} or puts ([*?A..?Z]*4).sort, so the letters get ordered as in the example. Dec 13 '13 at 19:02
• @manatwork: puts (?A..?Z).map{|i|[i]*4} is a character shorter. You can call map directly on a Range, so you don't need the splat in this case. Dec 13 '13 at 19:08

# PowerShell: 32 23

Golfed code:

[char[]](65..90*4)|Sort


Walkthrough:

[char[]](...) takes an array of objects and converts them to ASCII characters.
65..90 are the ASCII codes for A-Z.
*4 repeats the series 4 times.
|Sort sorts the output.

Note:

If you want this written to a file, just throw >, followed by a file name, at the end.

x a=a++a
main=putStr$['A'..'Z']>>=x.x.(:"\n")  • putStr$['A'..'Z']>>=("golf">>).(:"\n") saves 8 bits
– Angs
Oct 23 '16 at 17:03

# Befunge 98 - 18

1+::'g#@_4/'A+,a,


Works by storing a number and ending when it reaches 104. Prints out the corresponding character of the alphabet for the number divided by 4, followed by a newline. But if I need not add a newline after each letter, then it is 16 chars:

1+::'g#@_4/'A+,


Can be reduced if I can print more characters (ie all of them four times)(7 6 chars, even works in Befunge 93):

1+:4/,


With newline:

1+:4/,a,


# C, 4644 43

46:

i;main(){while(i<104)printf("%c\n",65+i++/4);}


44:

i=260;main(j){for(;(j=i++>>2)<91;puts(&j));}


44 too:

i=260;main(j){while(j=i++>>2,j<91)puts(&j);}


Thanks to @marinus, 43:

i=260;main(j){while(j=i++/4,j<91)puts(&j);}


Should I add a bounty for getting to 42? :)

• 50 rep. is needed to comment on anything, and you have 101 at the time of posting this comment. Dec 13 '13 at 22:44
• Great! Thanks! Answer edited! Dec 14 '13 at 10:39
• You can replace >>2 by /4. Dec 17 '13 at 2:37
• 42 bytes Can I get the bounty :-) 2 days ago

# GolfScript: 17 15 characters

26,{65+...}%+n*


Java: 56

for(int i=0;i<104;)System.out.println((char)(i++/4+65));


edit: changed from 'print' to 'println'

• The output should include newlines after each letter. Dec 17 '13 at 14:14
• thanks for pointing that out, it should print a new line each time now Dec 17 '13 at 19:51
• 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. i think your solution violates this condition Jul 20 '16 at 11:58
• @user902383 If you paste it into JShell (the Java REPL in Java 9) it works, and you don't even need the final semicolon. Jul 20 '16 at 12:09
• @DavidConrad Its awesome then, I think I might start using REPL/JShell. Jul 20 '16 at 12:13

## Forth, 37

'h 0 [do] [i] 4 / 'A + emit cr [loop]

• 35 bytes by avoiding +. Oct 12 '19 at 8:41

# Actually, 6 bytes

4ú*SÖi


Try it here!

Explanation

4ú*SÖi

4 *         Do 4 times
ú          Create string of alphabet in lowercase
S        Sort it
Ö       Switch Case
i      Push each character of string


4 Bytes with lowercase and no newline:

4ú*S

• Welcome to PPCG! Jul 21 '16 at 9:56

# 16-bit x86 machine code MS-DOS COM, 25 bytes

In hex:

B409BA160189D7B96800F6C1037502FE05CD21E2F5C3400A24


This is a complete MS-DOS .COM program. Copy the byte sequence to the file with .com extension and run it from DOSBox

Disassembly:

00: B4 09        mov    ah,0x09         ;INT 21h "Write string to STDOUT" function
02: BA 16 01     mov    dx,0x116        ;Address of the string s ('$'-terminated) 05: 89 D7 mov di,dx ;Because there's no way to dereference address in DX 07: B9 68 00 mov cx,104 ;CX=26*4 _0000000A: 0A: F6 C1 03 test cl,0x03 ;When lower two bits are zero... 0D: 75 02 jne _00000011 ;...do not skip the next instruction 0F: FE 05 inc b,[di] ;*s++ _00000011: 11: CD 21 int 21 ;Print the string 13: E2 F5 loop _0000000A ;Until --CX==0 15: C3 retn 16: 40 db 0x40 ;s[0], starts with 'A'-1 17: 0A db 0x0A ;'\n' 18: 24 db '$'             ;Terminator required by the print function


# Jelly, 5 bytes (non-competing?)

ØAx4Y


Try it online!

Explanation:

ØAx4Y Main link
ØA    “ABCDEFGHIJKLMNOPQRSTUVWXYZ”
4  4
x   Repeat each element of x y times
Y Join x with newlines


# brainfuck, 48 bytes

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


Try it online!

Prints in lowercase, separated by carriage returns. Uses wrapping 8 bit cells as well as cells left of the origin, though you can prepend a > to counter the latter.

• I was about to post a new one, but you managed to completely out-do my best, i got 71 bytes with ++++++[->++>++++>++++++++++<<<]++++>+>++>+++++<[->.<<.>>.<<.>>.<<.>>.+<<.>] Jan 31 '19 at 15:17

print"$_ "x4for A..Z  Try it online! # Perl 5 + -M5.10.0, 20 bytes eval"say;"x4for A..Z  Try it online! • It has never occurred to me to put a literal newline inside a double-quoted string in Perl. +1. Dec 14 '13 at 4:44 • I should note, that I didn't either, but @manatwork mentioned it on another answer of mine and it's stuck! Dec 14 '13 at 9:00 # x86-16 ASM, IBM PC DOS, 22 19 bytes Binary: 00000000: 400a 24b8 1109 8bd6 b168 d0c8 102c cd21 @.$......h...,.!
00000010: e2f8 c3                                  ...


Build with xxd -r and test in DOSBox or your favorite DOS VM.

Unassembled:

40 0A 24    DB   '@', 0AH, '$' ; the letter + NL + '$' string terminator
B8 0911     MOV  AX, 0911H          ; AH = DOS print string; AL = 0001 0001 bit pattern
8B D6       MOV  DX, SI             ; DX to output string
B1 68       MOV  CL, 26*4           ; Loop 4 times for each letter in alphabet
ALOOP:
D0 C8       ROR  AL, 1              ; roll repeating bit pattern to the right
10 2C       ADC  BYTE PTR[SI], CH   ; add rightmost bit to ASCII character
CD 21       INT  21H                ; print letter to console
E2 F8       LOOP ALOOP              ; continue looping


Notes:

For most flavors of DOS, we know the values of many CPU registers at the start of execution and we know SI is 0100H, and CH is 0. So by placing the output string in the beginning of the program, [SI] will already be pointing to it. These bytes ('@',0AH,'$') decode to two benign instructions (INC AX, OR AH, [SI]), which have no effect on the program. AL contains the bit pattern of 0001 0001 which is bit rolled right each time and the rightmost bit added to the ASCII value of the output char in memory. # Bash: 24 characters printf %s\\n {A..Z}{,,,}  BrainF* ,79 60 +++++++++++++[->++>+>+++++<<<]>>---<[->>>++++[-<.<.>>]<+<<]  • +++++++++++++[>+>+++++>++<<<-]>--->>[<.<.>.<.>.<.>.<.>+>-] Dec 14 '13 at 7:32 AWK, 48 Lets try it with AWK... END{s=65;for(i=104;i--;s+=0==i%4)printf"%c\n",s}  As suggested by manatwork we can get rid of 2 chars AWK, 46 (Edit) END{for(i=104;i--;s+=0==i%4)printf"%c\n",s+65}  AWK,40 (editing MarkReed's code) END{for(;i<104;){printf"%c\n",i++/4+65}}  • By removing the initialization of variable s you can spare 2 characters: END{for(i=104;i--;s+=0==i%4)printf"%c\n",s+65}. Dec 14 '13 at 20:01 • Putting the code in an END block means it requires an input stream (even if it's /dev/null) to work. Does that modify the char count? Anyway, BEGIN{for(;++i<104;){printf"%c\n",i/4+65}} is 5 chars shorter. Dec 15 '13 at 2:36 • @MarkReed Your code isn't working. Check this – Wasi Dec 15 '13 at 9:03 • D'oh. So close! :) But I still don't like the END pattern's requirement for an input stream... Dec 15 '13 at 22:00 ## PowerShell, 21 65..90|%{,[char]$_*4}


A slightly different approach to Iszi's. And shorter :-)

C# LINQ 115 Bytes110 Bytes

Enumerable.Range(65, 26).SelectMany(i => Enumerable.Repeat(i,4))
.ToList().ForEach(i=> Console.WriteLine((char)i));

• Welcome to PPCG! Nice first post! Jul 20 '16 at 14:09

# 05AB1E, 6 bytes

A4×{S»


Explanation:

A       # Push 'abcdefghijklmnopqrstuvwxyz'
4×     # Repeat four times
{    # Sort
S   # Split into list
»  # Join by newlines
# Implicit print


Without newlines, 4 bytes

A4×{


Try it online!

# Perl 6, 32

.say for (('A'..'Z') »xx»4)[*;*]

• I think this is the first time that Perl 6 was the first solution I thought of, but the hyperoperator just seemed a natural fit. Dec 15 '13 at 4:43

# C# (Visual C# Interactive Compiler), 46 bytes

for(var a=259;a++<363;WriteLine((char)(a/4)));


Try it online!

## Canvas, 5 bytes

Ｚ４１＊⟳


Try it here!

Explanation:
Code        | Explanation                                  | Stack
------------+----------------------------------------------+------------------------------
Ｚ          | The uppercase alphabet                       | "ABC..."
４１＊     | Stretched by 4 horizontally and 1 vertically | "AAAABBBBCCCC..."
⟳  | Rotated clockwise                            | "A¶A¶A¶A¶B¶B¶B¶B¶C¶C¶C¶C¶..."
| Print ToS (implicit)                         |


With ¶ replaced with \n upon printing.

# Kotlin, 66 59 bytes

Save 7 bytes removing for loop.

fun main(a:Array<String>){repeat(104){println('A'+(it/4))}}


Try it online!

# Dc: 35 characters

[rdP10Pr1-d1<p]sp65[5lpx+d91>l]dslx