49
\$\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
  • 2
    \$\begingroup\$ @FryAm In Brainfuck, the size is more than 5 times that of the original program. In some languages, output without newlines is hard, especially with sed. I had to use the -z flag just to even remove one. \$\endgroup\$
    – S.S. Anne
    Feb 29, 2020 at 15:36
  • 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

175 Answers 175

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\$
3
  • \$\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
3
\$\begingroup\$

Ruby, 12 bytes

1while$><<?A

Try it online!

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

Java (JDK), 85 77 34 bytes

v->{for(;;)System.out.print("A");}

Try it online!

Massive thanks to @Kevin for the lambda solution. I really need to learn how to do that.

Old Answer

class M{public static void main(String[]args){for(;;)System.out.print("A");}}

Try it online!

It's a full program and can probably be golfed if I knew how lambdas work in java. Oh well.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ 77 bytes removes some spaces and uses for(;;) instead of while(0<1). \$\endgroup\$
    – S.S. Anne
    Feb 29, 2020 at 1:19
  • \$\begingroup\$ Full program Java 8+: 71 bytes - args to a and class M{public static to interface M{static. Full program Java 5/6: enum A{A;{for(;;)System.out.print("A");}} (41 bytes); Lambda Java 8+: v->{for(;;)System.out.print("A");} (34 bytes) \$\endgroup\$ Mar 2, 2020 at 9:15
  • \$\begingroup\$ @Kevin How is an enum a full program? \$\endgroup\$
    – S.S. Anne
    Mar 2, 2020 at 22:08
  • 3
    \$\begingroup\$ @S.S.Anne In Java 5/6 there was a bug which executed a codeblock inside an enum even if there wasn't any main-method (here the relevant tip). PS: Lyxal, I once created this program with explanation for someone else on how Java 8+ lambdas work, so maybe it's also useful for you. :) It mostly explains the different type of lambdas, like with/without parameter(s) and/or return. If you have any questions, feel free to ask. \$\endgroup\$ Mar 3, 2020 at 7:25
3
\$\begingroup\$

Perl 5, 15 bytes

print'A'while 1

Try it online!

\$\endgroup\$
6
  • \$\begingroup\$ Did you forget to quote "A" or you taking liberty with the definition of A? :) \$\endgroup\$
    – rrauenza
    Mar 3, 2020 at 22:37
  • \$\begingroup\$ Neither. Perl treats bare words as if they were strings, if the interpreter cannot figure out what else to do with them. You'll see this a lot here. In this particular case, the spaces could have been quote marks with no additional byte cost. In some instances, leaving out the quotes can significantly lower a score. \$\endgroup\$
    – Xcali
    Mar 3, 2020 at 23:14
  • \$\begingroup\$ In the version of Perl I'm using, nothing outputs: perl -e 'print A while 1' This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi \$\endgroup\$
    – rrauenza
    Mar 4, 2020 at 0:29
  • \$\begingroup\$ Although the bare word does work in this context... perl -e '$x = A; print $x while 1' \$\endgroup\$
    – rrauenza
    Mar 4, 2020 at 0:31
  • \$\begingroup\$ @Xcali In the program given, perl can figure out what the bare A means: it's a file handle. Your program prints $_ to filehandle A; it doesn't print A to STDOUT. \$\endgroup\$
    – Abigail
    Mar 4, 2020 at 2:02
3
\$\begingroup\$

Python 3, 25 22 bytes

Saved 3 bytes thanks to Jo King! :)

while 1:print(end='A')
\$\endgroup\$
3
  • \$\begingroup\$ That's a good idea actually. Thing is though it would be 26 bytes, and the question doesn't require efficiency. Sorry :( \$\endgroup\$ Mar 4, 2020 at 9:19
  • \$\begingroup\$ Ok, I'm lost. Could you give me your interpretation / solution? \$\endgroup\$ Mar 4, 2020 at 9:49
  • \$\begingroup\$ Edit: I just realised what you meant, sorry \$\endgroup\$ Mar 4, 2020 at 9:50
3
\$\begingroup\$

PowerShell 27 25 bytes

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

Try it online!

-n parameter for Write-Host works as -NoNewline.

\$\endgroup\$
2
  • 3
    \$\begingroup\$ for() should work as well to save 3 bytes \$\endgroup\$
    – Veskah
    Mar 3, 2020 at 18:18
  • \$\begingroup\$ perhaps not heard. turn up volume: ıııııııııııııııııııııııııııııııııııııııı[]ııı \$\endgroup\$
    – mazzy
    Mar 5, 2020 at 4:18
3
\$\begingroup\$

International Phonetic Esoteric Language, 9 bytes

Derived from my answer to "Shortest code to produce infinite output".

"A"10ɑbuɒ

Explanation:

This works because the ɒ instruction don't do anything with the loop index except to check if index < limit. If it is, it loops back to its associated ɑ. Otherwise it exits the loop (index manipulation is handled with e adn ø).

"A"10ɑbuɒ
"A"       (Push "A")
   10     (Loop bounds: 0 to 1)
     ɑ    (Start loop)
      b   (Copy top)
       u  (Print with no trailing)
        ɒ (End loop)
\$\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\$

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

NDBall, 52 bytes, 7 instructions in 2 dimensions

(0)>0
(1)+
(2)Y[65,>1,>0]
(3)p
(4)<0
(2,1)<0
(0,1)<1

Program

In essence, this just loops the ball on an add 1 loop until it reaches 65, then it bounces back and forth over p repeatedly printing "A"

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

Kotlin, 50 47 bytes

fun main(a:Array<String>){while(0<1)print("A")}

1.) Thanks to @Adam for pointing out the args naming

\$\endgroup\$
3
  • 1
    \$\begingroup\$ You can save 3 bytes by not naming your args 'args' :) \$\endgroup\$
    – Adam
    Mar 3, 2020 at 15:05
  • 1
    \$\begingroup\$ You can just submit a bare lambda to save lots of bytes. \$\endgroup\$
    – snail_
    Mar 17, 2020 at 8:00
  • \$\begingroup\$ You can even go down to 20 bytes if you compile it as a script then your code only becomes this: while(0<1)print("A") \$\endgroup\$
    – YaMiN
    May 16, 2021 at 3:36
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\$

Go, 38 bytes

import."fmt"
func A(){for{Print("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\$
    – PauloVlw
    Jan 13, 2021 at 0:38
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\$ 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\$
2
\$\begingroup\$

PHP, 16 14 bytes

for(;;)echo A;

Try it online!

  • -1 byte thx to @Kaddath!
\$\endgroup\$
4
  • 1
    \$\begingroup\$ You can save 1 byte with a for loop and echo ;) TIO \$\endgroup\$
    – Kaddath
    Mar 2, 2020 at 7:59
  • \$\begingroup\$ @Kaddath or 14 bytes with another tweak! TIO \$\endgroup\$
    – 640KB
    Mar 2, 2020 at 11:48
  • \$\begingroup\$ @IsmaelMiguel I don't think that's necessary, as command-line is allowed for PHP golf; documentation says: when running in command line mode, the default is 0 (unlimited) \$\endgroup\$
    – Kaddath
    Mar 2, 2020 at 12:06
  • \$\begingroup\$ @Kaddath You're right, I've deleted my comment. \$\endgroup\$ Mar 2, 2020 at 12:11
2
\$\begingroup\$

BASIC, 21 18 17 13 bytes

1?"A";
GOTO 1

Try it online!

Everyone's first program!

Credits:

  • -3 bytes thx to @ceilingcat
  • -1 byte thx to @S.S. Anne
  • -3 bytes more thx again to @ceilingcat!
\$\endgroup\$
5
  • \$\begingroup\$ You can't even get a BASIC link right. Disappointing... \$\endgroup\$
    – S.S. Anne
    Mar 2, 2020 at 1:26
  • \$\begingroup\$ 17 bytes. \$\endgroup\$
    – S.S. Anne
    Mar 2, 2020 at 1:29
  • \$\begingroup\$ Look around you. Look around you. Can you tell what we're looking for? \$\endgroup\$
    – JDL
    Mar 2, 2020 at 10:56
  • 1
    \$\begingroup\$ @JDL huh? I'm not following... \$\endgroup\$
    – 640KB
    Mar 2, 2020 at 12:27
  • \$\begingroup\$ @640KB maybe a reference to the BBC show \$\endgroup\$
    – ceilingcat
    Mar 5, 2020 at 1:25
2
\$\begingroup\$

Vim, 10 bytes

@Noodle9's answer of qqiA^[@q is a good start but is incorrect:

The call of macro-q is using any previous setting of macro-q. This only worked because, in testing, they had previously recorded macro-q to output A, so they were unwittingly relying on saved state.

You can see this by trying to change the A to a different letter, and the first time you test it you will still get 'A's. Or you can first clear macro-q with "qqq"

Here is a correct answer along the same lines:

qqiA^[@qq@q

qq            Record macro-q (the first time)
  i           Insert
   A          Letter 'A'
    ^[        Exit insert mode
      @q      Call macro-q
        qq    Stop recording
          @q  Call macro-q

Although this does require that nothing is in macro-q at the start, which I think is a fair assumption for code golf, that you are starting with a clean slate / fresh install, as opposed to random initialization state. If not, or if you want to test this and have macros set already, you would need to do:

qqqqqiA^[@qq@q

Where the initial 'qqq' will clear the macro-q.

Of course, all of this is much easier to read if you don't use 'q' for the macro. :)

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Does anyone ever use anything other than q for their macro? \$\endgroup\$
    – Neil
    Mar 5, 2020 at 13:25
  • \$\begingroup\$ Heh. I use 'w' sometimes, but that's because I have an odd keyboard. \$\endgroup\$ Mar 5, 2020 at 20:21

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.