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\$
  • 123
    \$\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
6 7 8 9
10
0
\$\begingroup\$

Tamsin, 15 bytes

main={print 1}.

Try it online!

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

Perl 6, 11 bytes

loop {.say}

Try it online!

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

05AB1E, 2 bytes

Version 1 (3 bytes)

[A,

prints out the alphabet

Version 1 (2 bytes)

[,

Outputs infinite newlines

Try it online!

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

Brian & Chuck, 8 bytes

!{?
!{.?

Try it online!

Brian simply restarts Chuck and Chuck sets Brian's instruction pointer to the left end, prints it and restarts Brian.

Produces endless "!!!!!!..."

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

Brain-Flak, 10 bytes

(()){(())}

Try it online!

I don't know if this counts as a valid answer because Brain-Flak prints the contents of the active stack and this code just fills the stack.

(())    push 1 on stack
{       while top of stack != 0
  (())  push 1 on stack
}
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Lua, 18 bytes

::a::print()goto a

Try it online!

Shortest I was able to came up with (beats any loop). Prints newlines forever.

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

MarioLANG, 7 bytes

>:<
===

Try it online!

Infinitely prints zeroes; not much else to say about it.

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

Element, 5 bytes

!{A`]

This outputs A to the console forever.

TIO

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

MAWP, 4 bytes

1[:]

Explanation:

1     push 1 to stack
[     start of loop
:     print top of stack (1)
]     end of loop

Prints 1 infinitely

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

AlphaBeta, 2 bytes

MN

Try it online!

Outputs infinite null bytes.

Explanation

   # All registers are initialized to 0
M  # Output the number in register 3
 N # If register 3 is 0, goto the position at the position register.
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Vim, 10 bytes

<esc> is the byte typed when you press the escape key

qqiq<esc>@qq@q

This will output q infinitely into your vim buffer.

Here's how it works:

qq          # create macro q
  iq        # enter insert mode and type q
  <esc>     # escape to normal mode
  @q        # make the macro call itself
q           # end macro
@q          # call macro q
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Brainetry --live-output, 55 bytes

Uses the --live-output flag, otherwise output to the console would be deferred to the end of the program, which never happens because we have an infinite loop going on.

a b c d
a b c d e f g h
a b c d e f g
a b c d e f g h i

This is a golfed version of this program:

Lets produce infinite output.
This is really simple, all it takes is:
A cell with a non zero value
and the --live-output flag also needs to be on.

If you want to try this, clone the linked github repo and run python brainetry.py btry/infinite_output.btry --live-output.

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

C, 29 28 26 23 bytes

main(){main(puts(""));}

-2 @steadybox

-3 @rtpatx

gcc won't like it, but it compiles.

Outputs null bytes continuously. You can swap out the 0 for anything 0-9.

You can use 7 if you really hate your speakers.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ 26 bytes: main(){for(;;)putchar(0);} \$\endgroup\$ – Steadybox Dec 25 '17 at 1:55
  • \$\begingroup\$ Suggestion coming a long time later, 23 bytes main(){main(puts(""));} \$\endgroup\$ – rtpax Jun 24 at 19:17
  • \$\begingroup\$ @rtpatx nice! Editing. \$\endgroup\$ – SIGSTACKFAULT Jun 24 at 19:51
-1
\$\begingroup\$

Clojure

(repeat 1)

Returns a lazy seq of 1's '(1 1 1 1 1 1 1 1 1 1 ...)

| improve this answer | |
\$\endgroup\$
  • 2
    \$\begingroup\$ it doesn't output anything \$\endgroup\$ – cliffroot May 23 '16 at 14:01
-2
\$\begingroup\$

C# (72)

using System; class P {static void Main(){for(;;) Console.Write('-');}}

Output enter image description here

| improve this answer | |
\$\endgroup\$
  • 7
    \$\begingroup\$ This can easily be shortened to: class P{static void Main(){for(;;System.Console.Write(1));}} (60); if you insist on - to be outputted it would be 62 (replacing 1 with "1"). \$\endgroup\$ – RobIII May 2 '14 at 12:31
  • 3
    \$\begingroup\$ I have no idea how to code in C# but I can still golf this" class P{static void main{for(;;) Console.Write(0);}} \$\endgroup\$ – MilkyWay90 Feb 13 '19 at 1:52
1
6 7 8 9
10

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