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

1 2 3
4
1
\$\begingroup\$

GolfScript, 17 bytes

91,65>''+{...}%n*

Try it online!

Explanation

91,65>            # Genearate initial alphabet
      ''+         # Convert to a string
         {...}%   # For every item, copy 3 times
               n* # Join the resulting string by newlines
                  # (because a string is a codepoint array)
\$\endgroup\$
1
\$\begingroup\$

Burlesque, 16 bytes

@AZr@4?*{)'
}\mQ

Try it online!

@AZr@ # Array of A-Z as chars
4?*   # 4 of each as strings
{
 )'   # Add a newline between each letter
}\m   # Map for each string of 4 and concatenate
Q     # Pretty print for newlines instead of "\n"
\$\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, 2013 at 0:42
  • \$\begingroup\$ you'r right, i was too lazy to test it out :D fixed \$\endgroup\$
    – Shlomi
    Dec 16, 2013 at 0:52
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\$

Julia 1.0, 26 bytes

@.print((('A':'Z')*"
")^4)

Try it online!

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

Haskell, 43 bytes

main=mapM(putStrLn.pure)$['A'..'Z']<*[1..4]

Try it online!

This has two parts mapM(putStrLn.pure) takes a list of characters and prints each on it's own line.

['A'..'Z']<*[1..4] produces the list of desired characters. It does this with the monadic operator (<*) which works like (>>) except it keeps the values from the first arguement instead of the second.

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

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

Noether, 22 bytes

65~i91(0~l4(iBP?!l)!i)

Try it online!

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

Zsh, 21 bytes

eval '<<<'{A..Z}{,,,}

Attempt This Online!

\$\endgroup\$
1
  • \$\begingroup\$ Nice one, taking advantage of the fact that a bare here-string (or here-doc) in zsh acts like there's a cat in front of it. Clever! \$\endgroup\$
    – Mark Reed
    Feb 25, 2022 at 18:31
1
\$\begingroup\$

Google Sheets, 48 bytes

=flatten(sort(if({1,1,1,1},char(row(A65:A90)))))
\$\endgroup\$
1
  • \$\begingroup\$ you can get this down to 25 bytes if you port over Axuary's Excel answer as =Sort(Char(Row(260:363)/4 (Sheets handles arrays quite differently) or 38 bytes by optimizing your addresses, and removing the if function as =Flatten(Sort(Char({1,1,1,1}*Row(65:90 \$\endgroup\$ Mar 10, 2022 at 23:50
1
\$\begingroup\$

Pip -n, 10 bytes

_MWV(zRL4)

Try It Online!

_MWV(zRL4)
    (zRL4)     ; repeat z="abcde...xyz" 4 times, forming the list [z,z,z,z]
  WV           ; weave the the 4 z's together, forming the string "aaaabbbb...yyyyzzzz"
_M             ; convert to a list
               ; implicitly joined by newlines by the -n flag and printed
\$\endgroup\$
1
\$\begingroup\$

Excel, 28 bytes.

=CHAR(SEQUENCE(104,,65,1/4))

No need to drag it will spill if one uses MS365 or Excel 2021.

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

bash shell, 19 bytes

echo {A..Z}{,,,}'
'
\$\endgroup\$
4
  • \$\begingroup\$ This seems to print \n instead of actual newlines between characters. Try it online! \$\endgroup\$
    – Wheat Wizard
    Feb 25, 2022 at 14:48
  • \$\begingroup\$ @WheatWizard Replace \n with a real line feed. It's more a wrong byte count \$\endgroup\$
    – l4m2
    Feb 25, 2022 at 15:30
  • \$\begingroup\$ You can use ANSI quotes. echo {A..Z}{,,,}$'\n' That takes it to 21 bytes. You also have a leading space before every letter except the first A. You can fix that by using printf %s\\n {A..Z}{,,,} at a cost of taking it to 24 bytes. \$\endgroup\$
    – Mark Reed
    Feb 25, 2022 at 18:39
  • \$\begingroup\$ yeah, thks for that. \$\endgroup\$
    – user111207
    Mar 4, 2022 at 12:31
0
\$\begingroup\$

Factor + sequences.repeating spelling, 38 bytes

ALPHABET 4 repeat 10 interleaved print

Attempt This Online!

ALPHABET       ! "abcdefghijklmnopqrstuvwxyz"
4 repeat       ! "aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnooooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyyzzzz"
10 interleaved ! "a\na\na\na\nb\nb\nb\nb\nc\nc\nc\nc\nd\nd\nd\nd\ne\ne\ne\ne\nf\nf\nf\nf\ng\ng\ng\ng\nh\nh\nh\nh\ni\ni\ni\ni\nj\nj\nj\nj\nk\nk\nk\nk\nl\nl\nl\nl\nm\nm\nm\nm\nn\nn\nn\nn\no\no\no\no\np\np\np\np\nq\nq\nq\nq\nr\nr\nr\nr\ns\ns\ns\ns\nt\nt\nt\nt\nu\nu\nu\nu\nv\nv\nv\nv\nw\nw\nw\nw\nx\nx\nx\nx\ny\ny\ny\ny\nz\nz\nz\nz"
print          ! (print to stdout)
\$\endgroup\$
0
\$\begingroup\$

Wren, 57 bytes

for(c in 65..90)System.write((String.fromByte(c)+"\n")*4)

Try Wren

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

Headascii, 59 bytes

+++++[]]ONE.+++++[]]]]]++^[]]+[U{D-^)!:RP]PRP]PRP]PRP]PN][}

"Try it" on DSO (links to a version which only supports number output, but should get the point across)

Alternatively, try it here, but code will have to be pasted in as shown:

erun("+++++[]]ONE.+++++[]]]]]++^[]]+[U{D-^)!:RP]PRP]PRP]PRP]PN][}")

short breakdown:

+++++[]]O                                        save 10 to global array
         NE                                      go to next code block
.                                                code block separator
+++++[]]]]]++^                                   set r1 to 27
              []]+[                              set r2 to 55
                   U                             grab 10 from the global array
                    {D-^) :                   }  while --r1 + 1 != 0
                           RP                      send out ascii 10 (newline)
                             ]P                    send out ascii 10 + r2 (letter)
                               RP]PRP]PRP]P        (four times total)
                                           N][     r2++
                         !                       finally, print all 'send out' chars

However, I must note that if instead of using erun we run it with lrun, newlines are automatically appended at the end of each print (and ! is no longer required because technically it's a Headass program), making this 38 byter possible:

Headass lrun, 38 bytes

+++++[]]]]]++^+++++[]][{D-^):N][]PPPP}

DSO link, still prints as numbers, must-paste-in-code interpreter link

Which... I guess its just dawning on me that that's a different.. Version? ...But I'm not going to go and mark all my Headas(s|cii) answers based on which "interpreter" they use unless it's actually relevant to the challenge :P

Oh and of course, a breakdown:

+++++[]]]]]++^                          set r1 to 27
              +++++[]][                 set r2 to 64
                       {D-^):        }  while --r1 != 0
                             N][]PPPP     print ++r2 four times
\$\endgroup\$
1 2 3
4

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.