54
\$\begingroup\$

Write a script that outputs A to stdout infinitely.

There should be no newlines or separators between the characters.

Standard loopholes apply.

This is . The shortest solution in each language wins.

\$\endgroup\$
20
  • 10
    \$\begingroup\$ @FryAmTheEggman I respectfully disagree with this being marked as duplicate. This has a few almost (but not quite!) trivial distinctions from the other questions. For example, printing to stdout without printing a new line, and in the other challenge, looping without output \$\endgroup\$
    – Tornado547
    Feb 29, 2020 at 1:41
  • 3
    \$\begingroup\$ @FryAmTheEggman The other challenge clearly states "producing no output". This is not "producing no output". \$\endgroup\$
    – S.S. Anne
    Feb 29, 2020 at 1:46
  • 18
    \$\begingroup\$ "Infinite output" is significantly different from "a specific char infinitely many times without new lines". I don't think this is a duplicate. Let's reopen it if this comment gets four upvotes \$\endgroup\$
    – Luis Mendo
    Feb 29, 2020 at 22:00
  • 3
    \$\begingroup\$ @Tornado547 If you update the requirement, you need to notify current answers. Alternatively, you can keep the infinite output requirement, and include a sentence saying something like "The code should theoretically produce infinite output, given enough time and memory, and disregarding any data-type limitations. It is acceptable if in practice the output stops due to some of those limitations" \$\endgroup\$
    – Luis Mendo
    Mar 1, 2020 at 20:56
  • 3
    \$\begingroup\$ I'm surprised no one mentionned this helpful uncyclopedia page yet \$\endgroup\$
    – Oddrigue
    Mar 4, 2020 at 10:29

202 Answers 202

1
2
3 4 5
7
4
\$\begingroup\$

Seed, 8 bytes

3 141509

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Looks an awful lot like Pi now that I think about it. \$\endgroup\$
    – apollyon
    Mar 15, 2022 at 14:40
4
\$\begingroup\$

Windows Batch, 16 bytes

:a
echo a
goto a
\$\endgroup\$
3
\$\begingroup\$

Go, 38 bytes

import."fmt"
func A(){for{Print("A")}}

Try it online!

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

Keg, 3 bytes

{A,

Try it online!

That was fun! This is literally an infinite loop that prints As over and over

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

Haskell, 20 bytes

main=putStr$cycle"A"

Try it online!

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Also 20 bytes: main=putStr"A">>main \$\endgroup\$
    – cole
    Mar 1, 2020 at 18:45
  • 1
    \$\begingroup\$ 19 bytes: m@main=putStr"A">>m \$\endgroup\$
    – Lynn
    Sep 30, 2020 at 10:34
3
\$\begingroup\$

Ruby, 12 bytes

loop{$><<?A}

Try it online!

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

Jelly, 4 bytes

A niladic link:

”AȮß

Try it online!, or check how it works below. If the "A" could be program input, we could get away with only two bytes: Ȯß

”A   The character literal "A"
  Ȯ  Print it and return it,
   ß and recursively call this same link.
\$\endgroup\$
4
  • \$\begingroup\$ How long does it take for the stack to overflow? \$\endgroup\$ Mar 2, 2020 at 20:49
  • \$\begingroup\$ I didn't run it locally, only on TIO... And it seems TIO stops the execution because of the output size. So maybe the implementation of the recursive call is actually a loop? Because in Python the usual recursion depth is 1000 or 1024 and I manage to output way more than 1024 "A"s..? Just check the TIO link. \$\endgroup\$
    – RGS
    Mar 2, 2020 at 22:01
  • 1
    \$\begingroup\$ Here. The interpreter sets the recursion limit to 1 << 30. \$\endgroup\$
    – user92069
    Mar 3, 2020 at 10:56
  • \$\begingroup\$ Actually, it seems that the tail call is simply optimized out. \$\endgroup\$ Jul 11, 2023 at 18:02
3
\$\begingroup\$

Ruby, 12 bytes

1while$><<?A

Try it online!

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

Brian & Chuck, 8 bytes

A{?
B{.?

Try it online!

Brian:
A   constant "A"
{?  restart Chuck's code

Chuck:
B   (just a filler, this will be ignored)
{   go to start of Brian's code
.   print char
?   toggle to Brian
\$\endgroup\$
3
\$\begingroup\$

Python 2, 19 bytes

This might be cheating as it can only work on a terminal, since each space added in between "A" is removed with a backspace char.

while 1:print'\bA',
\$\endgroup\$
3
\$\begingroup\$

ZX Spectrum machine code, 5 bytes

3E 41 LOOP: LD A, 'A'
D7          RST 16
18 FB       JR LOOP

RST 16 is the Spectrum's character output interrupt. It will prompt you to "scroll?" on the 705th and every subsequent screenful of characters; if you press N, STOP or BREAK it will abort with error D BREAK - CONT repeats.

I've hand-assembled this so the opcodes might be incorrect.

\$\endgroup\$
2
  • \$\begingroup\$ This will also work on the ZX81 as well, wouldn't it? \$\endgroup\$ Jun 1, 2023 at 21:50
  • 1
    \$\begingroup\$ @ShaunBebbington It would just stop once it got to the end of the screen, because the ZX81 has no auto-scroll mechanism. \$\endgroup\$
    – Neil
    Jun 1, 2023 at 23:58
3
\$\begingroup\$

PowerShell 25 23 bytes

for(1){Write-Host -n A}

Try it online!

A works same as "A" and saves 2 bytes.

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

Wolfram Language (Mathematica), 28 bytes

$Output~WriteString~A~Do~∞

Try it online!

Most ways to output in Mathematica will include a trailing newline.

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

TeX (to file), 10 bytes

\def~{A~}~

TeX (to STDOUT), 19 bytes

\def~{\write0{A}~}~
\$\endgroup\$
3
\$\begingroup\$

05AB1E, 4 bytes

'A[?

Try it online!

'A    # push "A"
  [   # repeat forever...
   ?  # output top of stack to STDOUT without newline
      # (implicit) exit infinite loop
\$\endgroup\$
3
\$\begingroup\$

Labyrinth, 5 bytes

65
".

Try it online!

Simple square loop. Push the number 65, pop and print as charcode, and loop through a no-op.

Labyrinth, 5 bytes

<>.56

Try it online!

I think I found a way to loop through single line of program! (Except that the commands are necessarily backwards, and each of <> pops one value from the stack and uses it as an offset, so the loop should begin with <_>_ instead if the stack is non-empty at the boundary.)

<>.56  At start, IP runs "<" which cyclically shifts the row along with the IP
>.56<  Now IP is at the end of the strip, which forces it to run backwards
   6   Run commands in this order, printing an 'A'
  5
 .
>      Cyclically shift the row to the right
<>.56  Continue running to the left, now stepping on "<" again
       which causes IP to wrap through the edge and run in a loop

Labyrinth, 6 bytes

19
`
.

Try it online!

Uses -191 % 256 == 65. Runs back and forth along the linear path .`19, starting at 1 facing right.

Labyrinth, 5 bytes

~9
.1

Try it online!

Another -191.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I mean, why not just _65.? Or *65. to avoid memory filling up \$\endgroup\$
    – Jo King
    Sep 30, 2020 at 7:31
3
\$\begingroup\$

Starry, 41 35 bytes

-6 bytes, thanks to @ovs

Pushing values in Starry is pretty annoying, so the first 33 27 bytes are devoted to pushing the value of 'A' into the stack.

             + +  *      +*` + . +'
    13+    push 13-5
    1+     duplicate
    2*     multiply (top of stack is 64)
    6+     push 6-5
    0*     add (top of stack is 65)
    0`     label 0
    1+     duplicate
    1.     pop and print as char ('A')
    1+     duplicate
    0'     pop 'A', goto label 0

(The number at the beginning of each line signifies the number of spaces)

\$\endgroup\$
4
  • 2
    \$\begingroup\$ Welcome to Code Golf, and nice first answer! I tried running this on the Starry TIO, but it just looped forever producing no output. Additionally, it looks like your explanation contains extra spaces, and one more + and , than the code? \$\endgroup\$ May 11, 2021 at 12:38
  • \$\begingroup\$ I must have typed the original wrong, I'll fix it now. \$\endgroup\$
    – Jay Ryan
    May 11, 2021 at 14:03
  • 1
    \$\begingroup\$ Pushing 65 as 8*8+1 is a bit shorter: tio.run/##Ky5JLCqq/P9fARloA6GCFpStlQDk6Sloq///DwA \$\endgroup\$
    – ovs
    May 13, 2021 at 16:00
  • \$\begingroup\$ I looked at 8*8, but I forgot about duplicating. Thanks! \$\endgroup\$
    – Jay Ryan
    May 14, 2021 at 17:43
3
\$\begingroup\$

CBL, 7 bytes

°¸A;«.»

CBL is a language that I am developing. This answer may not be up-to-date with the latest syntax. I have not coded an interpreter yet.

A breakdown:

°¸A;«.»

°       <; Add following value(s) to current array value
 ¸A;     <; A as it's value(in the CBL codepage)
    « »   <; Loop(since there is no parameter, it loops infinitely)
     .     <; Print current array value

COBOL, 80 bytes

Just for fun.

IDENTIFICATION DIVISION.PROGRAM-ID.A.PROCEDURE DIVISION.A.DISPLAY 'A'.PERFORM A.

https://www.tutorialspoint.com/compile_cobol_online.php

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

Among Us, 83 80 bytes

-3 bytes thanks to ovs

VENTED RED SUS LIME SUS SUS SUS SUS SUS SUS RED SUS BLUE SUS WHO GREEN SUS WHERE

Explanation:

VENTED                          A2 += 10   (A2 = 10)
RED SUS                         A1 += 1    (A1 = 1)
LIME SUS SUS SUS SUS SUS SUS    A1 *= 2 6x (A1 = 64)
RED SUS                         A1 += 1    (A1 = 65 = 'A')
BLUE SUS                        PUSH A1
WHO                             while (A2 != stack_top) {
GREEN SUS                           print(stack_top)
WHERE                           }

Documentation of the language doesn't match the interpreter, this goes off of what runs on the interpreter. (creator, please fix).

Try it online!

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Note that we don't do non-competing anymore. Languages created after the question are fine, as long they weren't designed explicitly for the question itself \$\endgroup\$
    – Jo King
    Aug 15, 2021 at 1:00
  • 1
    \$\begingroup\$ That's a bit sussy \$\endgroup\$
    – lyxal
    Aug 15, 2021 at 3:47
  • \$\begingroup\$ 3 bytes shorter with 65=1*2^6+1: tio.run/… \$\endgroup\$
    – ovs
    Aug 15, 2021 at 16:21
2
\$\begingroup\$

Pyth, 4 bytes

#p\A

Explanation:

#p\A
#    While 1:
 p   Print without newline
  \A Character A

Try it online!

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

AWK, 28 bytes

BEGIN{for(ORS="";;)print"A"}

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I think using the END block instead of the BEGIN block works. \$\endgroup\$ Mar 6, 2020 at 3:45
  • \$\begingroup\$ Using printf instead of print uses only 23 bytes: BEGIN{for(;;)printf"A"} \$\endgroup\$ Jan 13, 2021 at 0:38
2
\$\begingroup\$

05AB1E, 4 bytes

['A?

Try it online!

[         # infinite loop
 'A       # "A"
   ?      # print without a trailing newline
\$\endgroup\$
2
\$\begingroup\$

sed 4.2.2 -z, 14 bytes

s/\n/A/g;:
p
b

Sed 4.2.2 was the last version to support an empty label name.

Try it online!

sed -z, 16 bytes

s/\n/A/g;:r p
br

After that, golfing is slightly more expensive.

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Unfortunately, this prints null bytes between the As (due to the -z flag). \$\endgroup\$
    – user41805
    Mar 5, 2020 at 18:21
  • \$\begingroup\$ What does the g at the end of the substitution help with? \$\endgroup\$
    – Wezl
    Jun 29, 2020 at 18:30
  • \$\begingroup\$ @Wezl Nothing, in this case. It's just a global replacement, and I have a habit of typing it. \$\endgroup\$
    – S.S. Anne
    Jun 29, 2020 at 19:16
2
\$\begingroup\$

Bash, 11 bytes (10 + 1)

printf A;s

Try it online!

This script must be saved in file named s, and that file must be in a directory in your PATH.

I've added 1 byte to the score to account for the required filename, as per https://codegolf.meta.stackexchange.com/a/1072/59825 .

Of course, this recursively forking script is going to run out of resources very quickly, especially if you try running it on TIO :-) .

\$\endgroup\$
6
  • \$\begingroup\$ But of course you can assume infinite resources and time. \$\endgroup\$
    – S.S. Anne
    Mar 1, 2020 at 21:02
  • \$\begingroup\$ Everybody else is assuming unlimited time. This bash solution needs unlimited space too. (In principle, it actually shouldn't need unlimited space, because the recursion is tail recursion, but bash doesn't do anything special to make tail recursion efficient, as far as I can tell.) @S.S.Anne \$\endgroup\$ Mar 1, 2020 at 21:13
  • 1
    \$\begingroup\$ printf A;exec s is a 5 byte longer but doesn't run out of memory \$\endgroup\$ Mar 2, 2020 at 16:51
  • 1
    \$\begingroup\$ @OlivierDulac Good point -- that more or less implements tail recursion, so it won't gobble us space any more as it runs. Of course, both programs are useless, so I'll stick with the shorter one :) ! \$\endgroup\$ Mar 2, 2020 at 18:40
  • \$\begingroup\$ printf A;$0 will remove requirement of filename and being in PATH. \$\endgroup\$
    – Ruslan
    Mar 4, 2020 at 9:40
2
\$\begingroup\$

33, 7 bytes

"A"j[p]
"A"     Put "A" in the source string
   j    Copy the value into the accumulator, so the loop never terminates
    [p] Print infinitely

Try it online!

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

W j, 3 bytes

'AI

Explanation.

  I % Forever:
'A  % Calculate the string "A"
    % Implicit output

Flag:j % Without a newline
```
\$\endgroup\$
2
\$\begingroup\$

F# (.NET Core), 22 bytes

while 1=1 do printf"A"

Try it online!

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

Whitespace, 23 bytes

[N
S S N
_Create_Label_LOOP][S S S T S S S S S T N
_Push_65_A][T   N
S S _Print_as_character_to_STDOUT][N
S N
N
_Jump_to_Label_LOOP]

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

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

Explanation in pseudo-code:

Start LOOP:
  Character c = 'A'
  Print c as character to STDOUT
  Go to next iteration of LOOP
\$\endgroup\$
2
\$\begingroup\$

Batch, 42 bytes

@for /l %%a in (0,0,0) do @set /p="A" <nul 
\$\endgroup\$
2
\$\begingroup\$

Clojure, 18 bytes

(while 1(print\A))

Try it online!

\$\endgroup\$
1
2
3 4 5
7

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.