30
\$\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 '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
  • 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 '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

100 Answers 100

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\$
1
  • \$\begingroup\$ How do you get this to run without a Main? \$\endgroup\$ Nov 18 '20 at 19:43
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\$

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

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 '18 at 20:09
1
\$\begingroup\$

Attache, 28 bytes

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

Try it online!

\$\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
  • 1
    \$\begingroup\$ ,:' -> +,­­ \$\endgroup\$
    – ngn
    Jan 27 '19 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\$
2
  • 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 '19 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\$ Jan 29 '19 at 8:01
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 '19 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 '19 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 '19 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 '19 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\$
1
\$\begingroup\$

Keg, 20 bytes (SBCS on Keg wiki)

AZɧ^(\
(3|$:\
)$(8|,

Push range from A to Z and then 4-speak it.

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

Clojure 41 45 bytes

(doseq[i(range 65 91 0.25)](println(char i)))
\$\endgroup\$
2
  • \$\begingroup\$ except that outputs the letters in reader character syntax (\A, \B, etc). And I don't count leading backslashes as "whitespace". :) Replacing prn with println yields the correct output at a cost of 4 additional characters. \$\endgroup\$
    – Mark Reed
    Dec 16 '13 at 0:42
  • \$\begingroup\$ you'r right, i was too lazy to test it out :D fixed \$\endgroup\$
    – Shlomi
    Dec 16 '13 at 0:52
1
\$\begingroup\$

Charcoal, 6 5 bytes

FαE⁴ι

-1 byte thanks to @Neil.

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

Explanation:

Loop over the characters of the uppercase alphabet:

For(a)
Fα

Create an array of size 4, each mapped to the current letter. (Items of an Array are each printed on a separated line by default.)

Each(4, i)
E⁴ι
\$\endgroup\$
6
  • \$\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 '19 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\$ Jan 29 '19 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 '19 at 4:49
  • 1
    \$\begingroup\$ 5 bytes: FαE⁴ι \$\endgroup\$
    – Neil
    Nov 18 '20 at 15:35
  • \$\begingroup\$ @Neil I see you're going through all my Charcoal answer. :) And nice golf! I didn't even knew the Each/Map builtin could be used like that. \$\endgroup\$ Nov 18 '20 at 15:47
1
\$\begingroup\$

Google Sheets, 40

Output per cell:

=ArrayFormula(CHAR(SEQUENCE(104,1,260)/4

If newlines are important, 49:

=ArrayFormula(JOIN("
",CHAR(SEQUENCE(104,1,260)/4

No, Sequence does not support floating point steps.

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

Excel, 21 bytes

=CHAR(ROW(260:363)/4)

Link to Spreadsheet

I think this would have worked when the question was asked if 104 cells were selected and Ctrl+Shift+Enter were used.

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

Vyxal j, 4 bytes

kA4•

Try it Online!

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

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

Python 3, 46 45 bytes

print(*["\n%c"%(i//4+65)for i in range(104)])

Python 3, 39 bytes

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

I prefer the first solution for being a true one-liner. But a correction of Justin's answer leads to a shorter solution.

\$\endgroup\$
1
  • \$\begingroup\$ You can save a byte with "\n%c"%(i//4+65) on your first program: TIO \$\endgroup\$
    – ovs
    Sep 16 at 13:51
1
\$\begingroup\$

F#, 57 bytes

for i in 97..122 do for _ in 0..3 do printf"%c\n"(char i)

Try it online!

Loop through the alphabet (for i in 97..122), then through 4 times (for _ in 0..3), and finally print the character with a newline (printf"%c\n"(char i)).

Here is another one, 71 bytes:

for i in 97..122 do printf"%s"(String.replicate 4(string(char i)+"\n"))

Ungolfed code:

for i in 97..122 do for _ in 0..3 do printf "%c\n" (char i)
\$\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\$
1
  • \$\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\$

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.