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

2
\$\begingroup\$

Scala, 42

('A'to'Z')map(x=>List.fill(4)(println(x)))
\$\endgroup\$
0
2
\$\begingroup\$

Q (13)

.........

-1@''4#'.Q.A;
\$\endgroup\$
2
\$\begingroup\$

Javascript 55

for(i=65;i<91;i+=1/4)document.write("&#"+(i|0)+";<br>")

1 character shorter, but outputs to the screen instead of console.

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

F#: 61 62 49

for i in 'A'..'Z'do for j in 0..4 do printfn"%c"i
\$\endgroup\$
2
  • \$\begingroup\$ hm, do you not need ;; at the end? \$\endgroup\$
    – Mark Reed
    Dec 15 '13 at 2:32
  • \$\begingroup\$ @MarkReed If executed from fsi.exe, yes, you would usually need that. However, this is a complete program by itself, so you can simply compile and run it as is. \$\endgroup\$
    – p.s.w.g
    Dec 17 '13 at 23:06
2
\$\begingroup\$

Pyke, 6 bytes (noncompetitive)

G4m*_X

Try it here!

Or 4 bytes without newline separation

G4m*
\$\endgroup\$
2
\$\begingroup\$

CJam, 15 13 characters

'[,65>4f*e_N*

Probably very golf-able; I'm new to CJam and even code golfing.

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

Swift 3, 53

(0...103).map{print(String(UnicodeScalar($0/4+65)!))}

IF one day Apple decided to include Foundation by default, we could have

(0...103).map{print(String(format:"%c",$0/4+65))} //49 bytes

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

Common Lisp, 58 bytes

(dotimes(i 26)(format t"~4@{~c
~:*~}"(code-char(+ 65 i))))

Explanation

(dotimes(i 26) ; loop for i from 0 to 25
(format t"~4@{~c
~:*~} ;output four times character given by (code-char(+ 65 i)) followed by newline

Try it online!

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

Vim, 27 bytes

:h<_
jjYZZPVUqqx4O<C-r>"<esc>jq25@q

Thanks @Lynn for the trick of grabbing the alphabet from helpfiles.

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

Brain-Flak, 122 bytes

(((((()()()()){}){}){}){}())((((()()()){}){}()){}){({}<(()()()()){({}<(({})<((()()()()()){})>)>[()])}{}({}())>[()])}{}{}

this is 120 bytes of source code, and +2 bytes for the -Ar flags.

Try it online!

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

05AB1E, 5 bytes

Aε4F=

Try it online!

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

PHP, 36 bytes

while($i<104)echo"
",chr($i++/4+65);

bonus version, 38 bytes

while($i<104)echo"@K"^chr($i++/4+1).A;

Run with -nr or try it online.

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

Mathematica 50 41 30

With help from alephalpha and Mark S.

Print/@{#,#,#,#}&/@Alphabet[];
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Print /@ {#, #, #, #} & /@ "A"~CharacterRange~"Z"; \$\endgroup\$
    – alephalpha
    Dec 14 '13 at 7:27
  • \$\begingroup\$ The semicolon in @alephalpha's comment is necessary. Also, using a newer version of Mathematica you can use Print/@{#,#,#,#}&/@Alphabet[]; instead of Print/@{#,#,#,#}&/@"A"~CharacterRange~"Z"; \$\endgroup\$
    – Mark S.
    Jul 25 '17 at 23:08
2
\$\begingroup\$

Pyth, 8 bytes

-2 bytes thanks to Mr. Xcoder

VGj*4rN1

Try it online!

Explanation

VG          # For N in G (the alphabet)...
     rN1    # ...convert N to uppercase...
   *4       # ...generate the string NNNN...
  j         # ...join on newlines
            # Implicit print for each iteration
\$\endgroup\$
2
  • 1
    \$\begingroup\$ 8 bytes: VGj*4rN1 \$\endgroup\$
    – Mr. Xcoder
    Aug 20 '17 at 20:29
  • \$\begingroup\$ VrG1NNNN is also 8 bytes and is way simpler... \$\endgroup\$
    – hakr14
    Mar 24 '18 at 16:11
2
\$\begingroup\$

Perl 6, 22 bytes

.say xx 4 for "A".."Z"

Even though this is an old challenge, I found a different approach to the Perl 6 answer, so I decided to post it.

Try it online!

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

///, 73 bytes

/./\/A
A
A
A
\/A\///~/.B.C.D.E.F.G.H.I.J.K.L.M.N.O.P.Q.R.S.T.U.V.W.X.Y.Z.

Try It Online!

This just replace . by /AAAA/A/ to get AAAA/A/B/AAAA/A/C/AAAA... (newlines excluded for legibility). The /~/ is the first part of a dummy replacement which does nothing; it's there to grab initial / from the first replacement. We don't need to worry about the final /A/ (/Z/ by the time the interpreter gets there), because /// simply exits if it encounters EOF while reading a replacement

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

Whitespace, 126 117 bytes

[S S S T    S S S S S S N
_Push_64][S N
S _Duplicate][N
S S S N
_Create_Label_LOOP][S N
N
_Discard_top][S S S T   N
_Push_1][T  S S S _Add][S N
S _Duplicate][S N
S _Duplicate][S S S T   S T T   S T T   N
_Push_91][T S S T   _Subtract][N
T   S S S N
_Jump_to_Label_EXIT_if_0][S S S T   S S N
_Push_4][N
S S T   N
_Create_Label_INNER_LOOP][S S S T   N
_Push_1][T  S S T   _Subtract][S N
S _Duplicate][N
T   T   S N
_Jump_to_Label_LOOP_if_negative][S N
T   _Swap_top_two][S N
S _Duplicate][T N
S S _Print_as_character][S S S T    S T S N
_Push_10][T N
S S _Print_as_character][S N
T   _Swap_top_two][N
S N
T   N
_Jump_to_Label_INNER_LOOP]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (containing raw spaces, tabs and new-lines only).

General explanation in pseudo-code:

Integer i = 64
Start Loop:
  i = i+1
  If i == 91: Exit program with error
  Integer j = 4
  Start Inner Loop:
    j = j-1
    If j is negative: Go to the next iteration of the outer Loop
    Print i as character
    Print new-line
    Go to the next iteration of the Inner Loop

Example run:

Command        Explanation                            Stack            STDOUT    STDERR

SSSTSSSSSSN    Push 64                                [64]
SNS            Duplicate top (64)                     [64,64]
NSSSN          Create Label_LOOP                      [64,64]
 SNN            Discard top                           [64]
 SSSTN          Push 1                                [64,1]
 TSSS           Add (64+1)                            [65]
 SNS            Duplicate top (65)                    [65,65]
 SNS            Duplicate top (65)                    [65,65,65]
 SSSTSTTSTTN    Push 91                               [65,65,65,91]    
 TSST           Subtract (65-91)                      [65,65,-26]
 NTSSSN         If 0: Jump to Label_EXIT              [65,65]
 SSSTSSN        Push 4                                [65,65,4]
 NSSTN          Create Label_INNER_LOOP               [65,65,4]
  SSSTN          Push 1                               [65,65,4,1]
  TSST           Subtract (4-1)                       [65,65,3]
  SNS            Duplicate top (3)                    [65,65,3,3]
  NTTSN          If negative: Jump to Label_LOOP      [65,65,3]
  SNT            Swap top two                         [65,3,65]
  SNS            Duplicate top (65)                   [65,3,65,65]
  TNSS           Print as character                   [65,3,65]        A
  SSSTSTSN       Push 10                              [65,3,65,10]
  TNSS           Print as character                   [65,3,65]        \n
  SNT            Swap top two                         [65,65,3]
  NSNTN          Jump to Label_INNER_LOOP             [65,65,3]

  SSSTN          Push 1                               [65,65,3,1]
  TSST           Subtract (2-1)                       [65,65,2]
  SNS            Duplicate top (2)                    [65,65,2,2]
  NTTSN          If negative: Jump to Label_LOOP      [65,65,2]
  SNT            Swap top two                         [65,2,65]
  SNS            Duplicate top (65)                   [65,2,65,65]
  TNSS           Print as character                   [65,2,65]        A
  SSSTSTSN       Push 10                              [65,2,65,10]
  TNSS           Print as character                   [65,2,65]        \n
  SNT            Swap top two                         [65,65,2]
  NSNTN          Jump to Label_INNER_LOOP             [65,65,2]

  SSSTN          Push 1                               [65,65,2,1]
  TSST           Subtract (2-1)                       [65,65,1]
  SNS            Duplicate top (1)                    [65,65,1,1]
  NTTSN          If negative: Jump to Label_LOOP      [65,65,1]
  SNT            Swap top two                         [65,1,65]
  SNS            Duplicate top (65)                   [65,1,65,65]
  TNSS           Print as character                   [65,1,65]        A
  SSSTSTSN       Push 10                              [65,1,65,10]
  TNSS           Print as character                   [65,1,65]        \n
  SNT            Swap top two                         [65,65,1]
  NSNTN          Jump to Label_INNER_LOOP             [65,65,1]

  SSSTN          Push 1                               [65,65,1,1]
  TSST           Subtract (1-1)                       [65,65,0]
  SNS            Duplicate top (1)                    [65,65,0,0]
  NTTSN          If negative: Jump to Label_LOOP      [65,65,0]
  SNT            Swap top two                         [65,0,65]
  SNS            Duplicate top (65)                   [65,0,65,65]
  TNSS           Print as character                   [65,0,65]        A
  SSSTSTSN       Push 10                              [65,0,65,10]
  TNSS           Print as character                   [65,0,65]        \n
  SNT            Swap top two                         [65,65,0]
  NSNTN          Jump to Label_INNER_LOOP             [65,65,0]

  SSSTN          Push 1                               [65,65,0,1]
  TSST           Subtract (0-1)                       [65,65,-1]
  SNS            Duplicate top (-1)                   [65,65,-1,-1]
  NTTSN          If negative: Jump to Label_LOOP      [65,65,-1]

 (Note: Contains additional trailing `[65,` here, but we'll ignore that for now.)
 SNS            Discard top                           [65]
 SSSTN          Push 1                                [65,1]
 TSSS           Add (65+1)                            [66]
 SNS            Duplicate top (66)                    [66,66]
 SNS            Duplicate top (66)                    [66,66,66]
 SSSTSTTSTTN    Push 91                               [66,66,66,91]    
 TSST           Subtract (66-91)                      [66,66,-25]
 NTSSSN         If 0: Jump to Label_EXIT              [66,66]
 SSSTSSN        Push 4                                [66,66,4]
 NSSTN          Create Label_INNER_LOOP               [66,66,4]
  SSSTN          Push 1                               [66,66,4,1]
  TSST           Subtract (4-1)                       [66,66,3]
  SNS            Duplicate top (3)                    [66,66,3,3]
  NTTSN          If negative: Jump to Label_LOOP      [66,66,3]
  SNT            Swap top two                         [66,3,66]
  SNS            Duplicate top (66)                   [66,3,66,66]
  TNSS           Print as character                   [66,3,66]        B
  SSSTSTSN       Push 10                              [66,3,66,10]
  TNSS           Print as character                   [66,3,66]        \n
  SNT            Swap top two                         [66,66,3]
  NSNTN          Jump to Label_INNER_LOOP             [66,66,3]

  ... etc. etc. for all letters in the alphabet

 SNN            Discard top                           [90]
 SSSTN          Push 1                                [90,1]
 TSSS           Add (90+1)                            [91]
 SNS            Duplicate top (91)                    [91,91]
 SNS            Duplicate top (91)                    [91,91]
 SSSTSTTSTTN    Push 91                               [91,91,91]    
 TSST           Subtract (91-91)                      [91,91,0]
 NTSSSN         If 0: Jump to Label_EXIT              [91,91]                    error
                (Label_EXIT doesn't exit, so exits program with an error to STDERR)
\$\endgroup\$
2
\$\begingroup\$

Pyt, 6 bytes

ʊ4*ąşÁ

Explanation:

ʊ     Pushes "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
4*    Quadruples the string
ą     Convert to array of characters
ş     Sort the array in ascending order
Á     Push contents of the array onto the stack
      implicit output

Try it online!


If outputting it as an array is acceptable:

Pyt, 5 bytes

ʊ4*ąş
\$\endgroup\$
2
\$\begingroup\$

SmileBASIC, 29 bytes

FOR I=260TO 363?CHR$(I/4)NEXT
\$\endgroup\$
1
  • \$\begingroup\$ This is a polyglot, and will function in Yabasic - Try it online! \$\endgroup\$ Jul 9 '18 at 18:23
2
\$\begingroup\$

VBA, 30 bytes

An anonymous VBE immediate window function that takes no input and outputs to the console.

For i=260To 363:?Chr(i\4):Next
\$\endgroup\$
2
\$\begingroup\$

Japt -R, 7 6 bytes

;B²²¬n

Test it

;B²²¬n
;B         :Uppercase alphabet
  ²        :Duplicate
   ²       :Duplicate
    ¬      :Split
     n     :Sort
           :Implicitly join with newlines
\$\endgroup\$
2
\$\begingroup\$

Vyxal j, 5 bytes

kAdds

Try it Online!

Look ma, no Unicode!

kA    # Uppercase output
  dd  # Quadruple
    s # Sorted
      # (j flag) join by newlines
\$\endgroup\$
2
  • 2
    \$\begingroup\$ the explanation here is wrong: clearly, the Adds here is what is adding everything 4 times ;) \$\endgroup\$
    – lyxal
    Jul 8 at 12:55
  • \$\begingroup\$ @lyxal Honestly, this is the first time I've unintentionally done a letters-only answer... \$\endgroup\$
    – emanresu A
    Jul 8 at 20:03
2
\$\begingroup\$

jq -nr, 27 bytes

range(104)/4+65|[.]|implode

Try it online!

implode seems to convert floating point to their floored value, which is quite useful here.

\$\endgroup\$
2
  • \$\begingroup\$ Unless I'm misremembering the rules, I believe command-line options count toward the total, so -nr adds three bytes and takes you to an even 30. :) \$\endgroup\$
    – Mark Reed
    Sep 4 at 20:00
  • 1
    \$\begingroup\$ @MarkReed You're not misremembering, but the rules have changed since 2013 ;). Here is the "new" concensus. In short, jq -nr is considered a different language than jq and the flag is not counted as any amount of bytes \$\endgroup\$
    – ovs
    Sep 4 at 21:02
2
\$\begingroup\$

Julia 0.2, 39, 36

println([char(i/4+64.5)for i=0:103])
\$\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 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 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 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\$
1
\$\begingroup\$

Matlab, 38

x=repmat(char(65:90)',1,4)';disp(x(:))
\$\endgroup\$
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 '13 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 '13 at 5:19
  • \$\begingroup\$ Ahhh, i see! Apologies, for some reason I thought it was doing some kind of parseInt! \$\endgroup\$ Dec 15 '13 at 9:09
1
\$\begingroup\$

PHP, 53

for($i=65;$i<91;$i++)echo str_repeat(chr($i)."\n",4);
\$\endgroup\$
9
  • 3
    \$\begingroup\$ I count 53 chars; where's the 44 from? \$\endgroup\$
    – Mark Reed
    Dec 14 '13 at 5:01
  • \$\begingroup\$ I know a 44 character long solution, but definitely not with that str_repeat(): pastebin.com/decsAZXi \$\endgroup\$
    – manatwork
    Dec 14 '13 at 12:58
  • \$\begingroup\$ @manatwork - that looks like 40, even. Why not post it as an answer? \$\endgroup\$
    – Mark Reed
    Dec 15 '13 at 1:27
  • \$\begingroup\$ Sorry, I didn't count the $i \$\endgroup\$
    – ub3rst4r
    Dec 15 '13 at 3:02
  • \$\begingroup\$ It doesn't includes ZZZZ \$\endgroup\$
    – VarunAgw
    Dec 15 '13 at 12:16
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\$

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.