# 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.

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.

• 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? – Justin 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? – Justin 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. – Justin 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. :) – Mark Reed Dec 17 '13 at 12:53
• I count 9 bytes. – Oliver Ni 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. – Steven H. Oct 23 '16 at 4:08
• @StevenH. Link is dead – Stan Strum Mar 25 '18 at 22:59
• @StanStrum I believe the link is dead because of deprecation, but for the sake of code golfing this meta answer should work. – Steven H. 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. – Mark Reed 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" – Justin 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. – Mark Reed 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 :) – Giuseppe Jul 25 '17 at 15:31
• @Giuseppe Can you specify this idea? – Sven Hohenstein Jul 25 '17 at 15:34
• Try it online! – Giuseppe Jul 25 '17 at 15:36
• @Giuseppe Really good idea! Thanks for pointing out. – Sven Hohenstein Jul 25 '17 at 15:37
• You can use 1 instead of "" to specify stdout in write as well, which saves another byte. – Giuseppe 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! – moala Dec 17 '13 at 1:37
• and another one! – moala 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. – marinus 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. – p.s.w.g Dec 14 '13 at 1:55
• 4#65{26,.\a. for 12 bytes. – FrownyFrog 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! – Darren Stone 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. – manatwork 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. – Mark Reed 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.

## Haskell, 46

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,


# GolfScript: 17 15 characters

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


# Perl 5, 21

map{print"$_ "x4}A..Z  • It has never occurred to me to put a literal newline inside a double-quoted string in Perl. +1. – Mark Reed 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! – Dom Hastings Dec 14 '13 at 9:00 # 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. – syb0rg Dec 13 '13 at 22:44 • Great! Thanks! Answer edited! – moala Dec 14 '13 at 10:39 • You can replace >>2 by /4. – marinus Dec 17 '13 at 2:37 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. – Pierre Arlaud Dec 17 '13 at 14:14 • thanks for pointing that out, it should print a new line each time now – reblerebel 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 – user902383 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. – David Conrad Jul 20 '16 at 12:09 • @DavidConrad Its awesome then, I think I might start using REPL/JShell. – user902383 Jul 20 '16 at 12:13 ## Forth, 37 'h 0 [do] [i] 4 / 'A + emit cr [loop]  • 35 bytes by avoiding +. – Bubbler 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! – Erik the Outgolfer 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  # Bash: 24 characters printf %s\\n {A..Z}{,,,}  BrainF* ,79 60 +++++++++++++[->++>+>+++++<<<]>>---<[->>>++++[-<.<.>>]<+<<]  • +++++++++++++[>+>+++++>++<<<-]>--->>[<.<.>.<.>.<.>.<.>+>-] – alephalpha 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}. – manatwork 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. – Mark Reed 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... – Mark Reed 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! – Rɪᴋᴇʀ 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!

# 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


# 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. – Mark Reed Dec 15 '13 at 4:43

## 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!

# 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 ++++++[->++>++++>++++++++++<<<]++++>+>++>+++++<[->.<<.>>.<<.>>.<<.>>.+<<.>] – KrystosTheOverlord Jan 31 '19 at 15:17

# Dc: 35 characters

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


# Scala, 42

('A'to'Z')map(x=>List.fill(4)(println(x)))


# Julia, 39, 36

println([char(i/4+64.5)for i=0:103])