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

109 Answers 109

3
\$\begingroup\$

Canvas, 5 bytes

Z41*⟳

Try it here!

Explanation:
Code        | Explanation                                  | Stack
------------+----------------------------------------------+------------------------------
Z          | The uppercase alphabet                       | "ABC..."
  41*     | 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.

\$\endgroup\$
3
\$\begingroup\$

Kotlin, 66 59 bytes

Save 7 bytes removing for loop.

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

Try it online!

\$\endgroup\$
3
\$\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\$
3
\$\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, 2021 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, 2021 at 21:02
3
\$\begingroup\$

Julia 0.2, 39, 36

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

Raku, 34 21 bytes

('A'..'Z'Xxx 4)».say
\$\endgroup\$
2
  • \$\begingroup\$ 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. \$\endgroup\$
    – Mark Reed
    Dec 15, 2013 at 4:43
  • 1
    \$\begingroup\$ Updated, @JoKing. Thanks! I was able to mostly predict what your re-golfed solution was before looking, now that I have 9 more years of Raku under my belt. Though I got stuck at 22 bytes; didn't think the space before Xxx would be removable. I also left the hyperop as » instead of >>; it's two bytes either way, and I prefer the look of the guillemet . \$\endgroup\$
    – Mark Reed
    May 10, 2022 at 15:37
2
\$\begingroup\$

Dc: 35 characters

[rdP10Pr1-d1<p]sp65[5lpx+d91>l]dslx
\$\endgroup\$
0
2
\$\begingroup\$

Scala, 42

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

Matlab, 38

x=repmat(char(65:90)',1,4)';disp(x(:))
\$\endgroup\$
2
\$\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, 2013 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, 2013 at 12:58
  • \$\begingroup\$ @manatwork - that looks like 40, even. Why not post it as an answer? \$\endgroup\$
    – Mark Reed
    Dec 15, 2013 at 1:27
  • \$\begingroup\$ Sorry, I didn't count the $i \$\endgroup\$ Dec 15, 2013 at 3:02
  • \$\begingroup\$ It doesn't includes ZZZZ \$\endgroup\$
    – user9333
    Dec 15, 2013 at 12:16
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\$
1
  • \$\begingroup\$ (i|0) => ~~i \$\endgroup\$
    – l4m2
    Feb 25, 2022 at 15:54
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, 2013 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, 2013 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\$

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

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, 2017 at 20:29
  • \$\begingroup\$ VrG1NNNN is also 8 bytes and is way simpler... \$\endgroup\$
    – hakr14
    Mar 24, 2018 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\$

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\$
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, 2018 at 18:23
2
\$\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, 2019 at 15:40
2
\$\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, 2019 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, 2019 at 8:01
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\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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