Write a script that outputs A
to stdout infinitely.
There should be no newlines or separators between the characters.
Standard loopholes apply.
This is code-golf. The shortest solution in each language wins.
Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It only takes a minute to sign up.
Sign up to join this communityA 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.
1 << 30
.
\$\endgroup\$
v->{for(;;)System.out.print("A");}
Massive thanks to @Kevin for the lambda solution. I really need to learn how to do that.
class M{public static void main(String[]args){for(;;)System.out.print("A");}}
It's a full program and can probably be golfed if I knew how lambdas work in java. Oh well.
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
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
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\$
perl -e '$x = A; print $x while 1'
\$\endgroup\$
A
means: it's a file handle. Your program prints $_
to filehandle A
; it doesn't print A
to STDOUT
.
\$\endgroup\$
for(1){Write-Host -n "A"}
-n
parameter for Write-Host
works as -NoNewline
.
Derived from my answer to "Shortest code to produce infinite output".
"A"10ɑbuɒ
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)
$Output~WriteString~A~Do~∞
Most ways to output in Mathematica will include a trailing newline.
'A[?
'A # push "A"
[ # repeat forever...
? # output top of stack to STDOUT without newline
# (implicit) exit infinite loop
65
".
Simple square loop. Push the number 65, pop and print as charcode, and loop through a no-op.
<>.56
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
19
`
.
Uses -191 % 256 == 65
. Runs back and forth along the linear path .`19
, starting at 1 facing right.
~9
.1
Another -191.
_65.
? Or *65.
to avoid memory filling up
\$\endgroup\$
(0)>0
(1)+
(2)Y[65,>1,>0]
(3)p
(4)<0
(2,1)<0
(0,1)<1
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"
-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)
+
and ,
than the code?
\$\endgroup\$
May 11, 2021 at 12:38
65
as 8*8+1
is a bit shorter: tio.run/##Ky5JLCqq/P9fARloA6GCFpStlQDk6Sloq///DwA
\$\endgroup\$
fun main(a:Array<String>){while(0<1)print("A")}
1.) Thanks to @Adam for pointing out the args naming
while(0<1)print("A")
\$\endgroup\$
°¸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
Just for fun.
IDENTIFICATION DIVISION.PROGRAM-ID.A.PROCEDURE DIVISION.A.DISPLAY 'A'.PERFORM A.
-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).
END
block instead of the BEGIN
block works.
\$\endgroup\$
Mar 6, 2020 at 3:45
printf
instead of print
uses only 23 bytes: BEGIN{for(;;)printf"A"}
\$\endgroup\$
-z
, 14 bytess/\n/A/g;:
p
b
Sed 4.2.2 was the last version to support an empty label name.
-z
, 16 bytess/\n/A/g;:r p
br
After that, golfing is slightly more expensive.
A
s (due to the -z
flag).
\$\endgroup\$
Mar 5, 2020 at 18:21
g
at the end of the substitution help with?
\$\endgroup\$
Jun 29, 2020 at 18:30
printf A;s
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 :-) .
printf A;exec s
is a 5 byte longer but doesn't run out of memory
\$\endgroup\$
Mar 2, 2020 at 16:51
printf A;$0
will remove requirement of filename and being in PATH
.
\$\endgroup\$
"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
j
, 3 bytes'AI
I % Forever:
'A % Calculate the string "A"
% Implicit output
Flag:j % Without a newline
```
[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
@for /l %%a in (0,0,0) do @set /p="A" <nul
1?"A";
GOTO 1
Everyone's first program!
Credits:
@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. :)
q
for their macro?
\$\endgroup\$
sed
. I had to use the-z
flag just to even remove one. \$\endgroup\$