130
\$\begingroup\$

Write the shortest code you can that produces an infinite output.

That's all. You code will only be disqualified if it stops producing output at some point. As always in code golf, the shortest code wins.

Here's a list of answers that I think are really clever, so they can get credit:

Leaderboard

var QUESTION_ID=13152,OVERRIDE_USER=8611;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

\$\endgroup\$
  • 125
    \$\begingroup\$ All answers disqualified because at some point the Earth will be swallowed by the sun, and at some point the universe will die :P \$\endgroup\$ – Doorknob Nov 9 '13 at 20:00
  • 19
    \$\begingroup\$ Does "infinite until your computer crashes" count? <_< \$\endgroup\$ – Izkata Nov 10 '13 at 1:39
  • 5
    \$\begingroup\$ If I write mine in Piet, can I count the pixels of the text the other programs used? I believe the smallest possible repeating Piet program would be 6 pixels. That beats Befunge if "off" pixels still count. \$\endgroup\$ – DampeS8N Nov 12 '13 at 20:27
  • 9
    \$\begingroup\$ @Izkata So any answer that crashes your computer is also allowed :D \$\endgroup\$ – ɐɔıʇǝɥʇuʎs Jul 11 '14 at 20:11
  • 7
    \$\begingroup\$ @Doorknob So really, the challenge is to produce infinite output in a finite amount of time. Sounds easy enough. \$\endgroup\$ – Sanchises Apr 10 '15 at 21:15

285 Answers 285

1
4 5
6
7 8
10
1
\$\begingroup\$

Dreaderef, 9 8 7 bytes

5?1 1-1

Try it online!

Explanation:

In a more readable form (which can still be fed into the preprocessor), this program is:

numo 0
deref 1 -1

The numo (numeric output) statement does just about what you'd expect: it outputs 0. I could have used chro, but that makes it output unprintables and doesn't affect the byte count.

To understand the second line, you have to know a little bit about Dreaderef:

  • Programs are loaded into the data space at the beginning of execution.
  • The pointer to the current instruction is located at position -1.

What deref 1 -1 does is:

  • Dereferences 1 (takes the value of the cell at index 1). This always returns 0.
  • Stores the result in cell -1, which is effectively a GOTO to instruction 0.

Dreaderef doesn't have a "load constant" instruction, so the best way to load a constant into a cell is to use some sort of arithmetic instruction or copy it from some other cell with deref, which is what I do here.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Forth, 24 bytes

Defines then calls a word that loops forever, pushing and printing <0> each iteration.

: f begin .s 0 until ; f

Try it online


With a do-loop (25 bytes):

: f 0 0 do 0 .s +loop ; f

Prints <1> 0 forever.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ I know this is a bit late, but technically the do loop isn't infinite, as eventually the counter will wrap around and reach 0 again (albeit it will possibly take years depending on speed and implementation). Use : f begin .s 0 until ; instead (plus it saves a byte) \$\endgroup\$ – reffu Feb 12 '18 at 14:15
  • 1
    \$\begingroup\$ @reffu That's actually a byte longer. You have to call the function. \$\endgroup\$ – mbomb007 Feb 12 '18 at 16:33
  • \$\begingroup\$ good point, I didn't realize this one had slightly different rules than the typical codegolf challenge. \$\endgroup\$ – reffu Feb 12 '18 at 17:07
1
\$\begingroup\$

TIS -n 1 1, 12 bytes

@0
MOV 0 ANY

Try it online!

Just shoves a bunch of 0\n to the output. On TIO, reached the 128KiB cutoff quite quickly. Without the -n flag, prints null bytes instead.

If you are familiar with TIS-100, you will be used to a 3x4 array of computational nodes, however, this solutions only uses one such node, nominally giving the zeroes downward as output.

The only instruction that send data out of a computational node is MOV, and that requires a source and a destination. the smallest possible source is a single digit number, and the smallest possible destination is UP. However, to produce actual output, the data needs to travel downwards, restricting the choice to either DOWN or ANY.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Gol><>, 1 byte

D

Try it online!

D is a command designed for debugging, which prints the entire stack (from bottom to top) between brackets. D on empty stack generates []\n to stdout, and the IP loops through the row endlessly.

Alternative solution, 1 byte

Credits to Jo King

N

Try it online!

Unlike ><>, Gol><> has infinite zeroes at the bottom of the stack, which allows to print the top without pushing anything. Any of Nno will do; N prints 0\n, n prints 0, and o prints null bytes.

Alternatively, there are many 2-byte solutions:

  • One of 0-9a-f, l, or m followed by one of NnoD; Try it online!
    • Any of 0-9a-f pushes a hexadecimal digit to the stack, l pushes the current stack size, and m pushes -1.
    • N prints the top as number with newline, n is the same without newline, and o prints as a char.
  • S"; Try it online!
    • Initially S" is interpreted as one command which prints the encountered chars up to ending ". The next loop of S" is interpreted as a literal S and then closing ", which prints a single S to stdout.
  • " followed by any of NnoD; Try it online!
    • Use " as both opening and closing quote, then print the char.
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Ahead, 1 byte

O

Prints 0 forever. O pops the stack and prints that value as a number written out (as opposed to a Unicode character). Like Befunge, the empty stack pops 0, so this will print 0.

Since this is a 1x1 board, the head has nowhere to go and will stay on this cell forever, outputting forever.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Prolog (14 bytes)

a:-write(0),a.

Simple tail recursive predicate in swi-prolog. Called like so a.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Welcome to PPCG! \$\endgroup\$ – Laikoni Jun 6 '18 at 14:16
  • \$\begingroup\$ @Laikoni it's nice to be here :) thank you. \$\endgroup\$ – Khepu Jun 6 '18 at 16:59
1
\$\begingroup\$

Shakespeare Programming Language, 89 bytes

,.Ajax,.Puck,.Act I:.Scene I:.[Enter Ajax and Puck]Scene V:.Ajax:Speak thy!Let usScene V!

Try it online!

I haven't used this language before, this is mostly based on tips from "Tips for golfing in The Shakespeare Programming Language", so I think it can be made shorter.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ You can reduce this to one Scene for 86 bytes \$\endgroup\$ – Jo King Aug 27 '18 at 7:34
1
\$\begingroup\$

Flobnar, 4 bytes

0,_@

Try it online!

Outputs 0x00 bytes indefinitely.

This works because _ is said to get the conditional from the cell on the other side of it, and then use its value to choose between the east and west cells. It is expected to be evaluated from a vertical direction, but it doesn't have to be.

@ indicates the starting point for the program and evaluates to the return value of the cell to its west (_). _ evaluates what's on the other side (0,) to print 0. , always has a return value of 0, however, and this causes the horizontal if to choose the branch to its east. This is @, which evaluates the cell to its west, continuing the cycle.

Flobnar doesn't have decimal output by default, but the linked implementation has a -d flag which enables . for decimal output. This allows a slightly prettier version that outputs printable characters instead.

0._@

Try it online!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

√ å ı ¥ ® Ï Ø ¿ , 3 bytes

(o)

Will output:

===== OUTPUT =====

0 0 0 0 0 etc.

==================

followed by execution information.

TIO Compiler. Enter the code as the first input and None as the second.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ It seems that the language was implemented recently. Should this be marked as non-competing? \$\endgroup\$ – fergusq Mar 13 '17 at 18:47
  • \$\begingroup\$ Oh yeah forgot to do that. Update added \$\endgroup\$ – caird coinheringaahing Mar 13 '17 at 18:48
1
\$\begingroup\$

Taxi, 377 369 bytes

-8 bytes by getting rid of the quotes.

Go to Post Office:w 1 l 1 r 1 l.
[B]
! is waiting at Writer's Depot.
! is waiting at Writer's Depot.
! is waiting at Writer's Depot.
Go to Zoom Zoom:s 1 l 1 l 4 l 2 r.
Go to Writer's Depot:w.
Pickup a passenger going to Post Office.
Pickup a passenger going to Post Office.
Pickup a passenger going to Post Office.
Go to Post Office:n 3 r 2 r 3 r 1 l.
Switch to plan B.

The repetition of the passengers is needed for the driver to get enough fare to get enough gas to continue forever.

Try it online!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Perl 6, 8 bytes

Thanks to nwellnhof for this solution.

.say xx*

Try it online!

Prints (Any) infinitely.

Perl 6, 10 bytes

1...!*.say

Try it online!

Defines a list that increments until the result of printing the current number is false (which never happens).

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Clean, 7 bytes

f=[0:f]

Try it online!

Gives [0,0,0,0,...

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Gol><>, 1 byte

n

There we go, I feel like this cheats a little bit, but it works! Now to golf this more... ;)

Try it online!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Muriel, 39 bytes

A:"\";.A;@\"A:\\\"\"+|A+A";@"A:\""+|A+A

Try it online!

This is near identical to the Muriel quine, except I've changed the print command in the last instruction to an eval command, and the addition of .A; in order to print something (in this case, the shortest thing was a part of the source code ("+|A+A";@"A:\""+|A+A) itself).

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Voovoos, 3 bytes

x.<

Pretty much just endlessly bounces between the . and <
. pops the top of the stack and prints it, but if you pop an empty stack in voovoos you get 0, so it just endlessly prints 0.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

TI-BASIC, 5 bytes

Disp 1:prgmA

This solution requires that the program's name is prgmA.

Displays 1 on a new line forever, or at least until the calculator runs out of free RAM.


Here's an alternative 7 byte solution that is guaranteed to never terminate:

While 1:Disp 1:End

It has the same output as the above solution.


Notes:

  • Each successive prgmA call uses up 16 bytes of free RAM.

  • If there aren't 16 free bytes, then the program crashes with an ERR:MEMORY error.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

YABALL, 3 bytes

!.?

Try it online!

Explanation

!                  Go off of "reverse mode" (a mode where the IP goes left instead of right) if in reverse mode, otherwise no-op
.                  Print current cell, which is NUL
?                  Go in "reverse mode"

Basically an infinite loop printing NULs.

The commands are executed like so: !.?.!.?.!.? ...

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

MINOL, 5 bytes

GOTO0

Any expression in MINOL that isn't entered as part of a program (that is, isn't assigned a line number by the user) is considered line 0. While seemingly not a part of the official spec (which, as far as I can tell, is a series of letters sent to and subsequently reformatted and published by 'Dr. Dobb's Journal of Computer Calisthenics and Orthodontia' in 1976), lines executed this way always seem to spit out a newline. This obviously wouldn't be the case in a full program, which would take 11 bytes (inc. the trailing CR):

1 PR:GOTO1
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Turing Machine But Way Worse, 27 13 bytes

0 0 0 1 0 1 0

Try it online!

Outputs infinite NUL characters.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Bash, 3 bytes

top

Haven't seen anyone do this yet. It's tied with the yes answer.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Triangular, 4 bytes

,%0/

Prints 0 repeatedly.

Try it online!


Ungolfed:

  ,
 % 0
/
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Underload, 8 bytes

(:S:^):^

Endlessly outputs :S:^

Try it Online!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Pyth, 3 2 bytes

#d

Try it online!

Prints the string " " (single space) until a print instruction produces an error (which, I mean, I guess could happen).

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

PHP, 16 bytes 8 bytes

My first attempt and this Code Golf :)

while(a)

I'm sure I could make it better without that echo? hmm...

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to PPCG! Hope you stick around! \$\endgroup\$ – Rɪᴋᴇʀ Oct 12 '17 at 14:58
  • \$\begingroup\$ Thanks! How was my attempt? Not as good as the others how do thy do it? :L \$\endgroup\$ – Shaun Moore Oct 12 '17 at 16:27
  • \$\begingroup\$ It was pretty good! Best I could have gotten, at least. Most of the other answers are in golfing languages, which are much shorter, but don't let that discourage you! \$\endgroup\$ – Rɪᴋᴇʀ Oct 13 '17 at 15:30
  • 2
    \$\begingroup\$ First, you can leave out the curcly braces, since there is only one statement in the loop anyway: while(1)echo 0;. To golf it further, you can use print instead of echo. Print allways returns 1, so you can then use it inside your while, golfing it to while(print 0);. You can get it even smaller if you're going for infinite error output: while(a);. \$\endgroup\$ – chocochaos Feb 13 '18 at 9:04
1
\$\begingroup\$

TeX, 11 bytes

The following results in an infinite amount of Undefined control sequence. errors (if run in batch mode no human interaction needed):

\def~{\[~}~

TeX, 14 bytes

The following creates a PDF with infinite lines each containing a dot (theoretically that is, since the process never terminates, the file isn't finalized so not really created). I've stopped the process after more than 1000000 pages were output. At some point memory wouldn't suffice anymore for this.

\def~{.\par~}~
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

33, 5 bytes

1a[o]

Explanation:

1a    (Set the accumulator to 1, to allow the loop to continue to run)
  [o] (Print the accumulator, 1, forever)
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

bitch, 3 bytes

>/<

Try it online!


Explanation

>      Begin loop
 /     Print accumulator value (intialised to 0)
  <    Loop back to beginning of loop
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

TSQL, 16 17 bytes

l:PRINT'1'GOTO l

WHILE 1=1PRINT'1'

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

MarioLANG, 7 bytes

>:<
===

Mario will walk back and forth, printing as he does.

Try it online!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Intcode, 8 bytes

4,0,5,0,1

Outputs "4" an infinite number of times.

| improve this answer | |
\$\endgroup\$
1
4 5
6
7 8
10

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