146
\$\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\$
16
  • 142
    \$\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
    Commented Nov 9, 2013 at 20:00
  • 27
    \$\begingroup\$ Does "infinite until your computer crashes" count? <_< \$\endgroup\$
    – Izkata
    Commented Nov 10, 2013 at 1:39
  • 7
    \$\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
    Commented Nov 12, 2013 at 20:27
  • 12
    \$\begingroup\$ @Izkata So any answer that crashes your computer is also allowed :D \$\endgroup\$ Commented Jul 11, 2014 at 20:11
  • 11
    \$\begingroup\$ @Doorknob So really, the challenge is to produce infinite output in a finite amount of time. Sounds easy enough. \$\endgroup\$
    – Sanchises
    Commented Apr 10, 2015 at 21:15

341 Answers 341

1
2 3 4 5
12
232
\$\begingroup\$

Befunge (1)

.

Outputs 0 forever. It works because in Befunge lines wrap around, and you get 0 if you pop from the empty stack.

\$\endgroup\$
9
  • 10
    \$\begingroup\$ I think we have a winner. \$\endgroup\$
    – primo
    Commented Nov 9, 2013 at 3:34
  • 114
    \$\begingroup\$ I swear I had a Java class around here somewhere that was shorter. +1 \$\endgroup\$
    – l0b0
    Commented Nov 9, 2013 at 9:22
  • 66
    \$\begingroup\$ This one dot has now gotten me more reputation than my next two answers combined. \$\endgroup\$
    – marinus
    Commented Nov 11, 2013 at 14:32
  • 5
    \$\begingroup\$ Aw... That's not fair :) Let's do it like this: I reduce the size of that image by a couple pixels and we display it very small.. So that it looks like a dot? And call it even? :) \$\endgroup\$ Commented Jan 31, 2014 at 7:47
  • 7
    \$\begingroup\$ Why is this not the accepted answer? \$\endgroup\$
    – Claudiu
    Commented Sep 3, 2014 at 22:30
114
\$\begingroup\$

x86 .COM Executable, 7

in hex:

b8 21 0e cd 10 eb fc

The others need kilobytes or more of system libraries and runtime. Back to basics:

$ echo -ne '\xb8!\xe\xcd\x10\xeb\xfc' > A.COM
$ dosbox A.COM

output

You can change the 2nd byte (0x21, or !) to change the output.

Uses a BIOS interrupt for output; doesn't need DOS, but I didn't have QEMU set up.


Explanation

The machine code corresponds with the following assembly:

        mov     ax, 0x0e21
again:  int     0x10
        jmp     again

The output is all in the int call -- per this reference, int 0x10 with 0x0e in AH will print the byte in AL to the screen.

Knowing that register AX is a 16-bit word comprised of AH in the high byte and AL in the low byte, we can save an extra load (and thereby a byte in the machine code) by loading them together.

\$\endgroup\$
11
  • 2
    \$\begingroup\$ Wow. That's really good \$\endgroup\$
    – tbodt
    Commented Jan 16, 2014 at 1:43
  • 51
    \$\begingroup\$ low machine code length should be worth more points than high level languages. \$\endgroup\$
    – pwned
    Commented Jan 23, 2014 at 11:33
  • 14
    \$\begingroup\$ This is the shortest code in real sense. \$\endgroup\$
    – microbian
    Commented Jan 29, 2014 at 4:51
  • 7
    \$\begingroup\$ Not only does it work, it works faster than all the other entries. :) \$\endgroup\$ Commented Apr 29, 2014 at 19:46
  • 20
    \$\begingroup\$ @ThaneBrimhall Which is of course the most important criteria by far for an infinite loop... If my computer hangs up, I want it to do it in the most efficient way! \$\endgroup\$
    – kratenko
    Commented Apr 30, 2014 at 10:17
106
\$\begingroup\$

Windows Batch file, 2 chars

%0

Calls itself infinitely.

\$\endgroup\$
6
  • 18
    \$\begingroup\$ Close second place, man. Well done. I've only ever seen one answer where Batch has won it. \$\endgroup\$
    – unclemeat
    Commented Feb 13, 2014 at 2:21
  • \$\begingroup\$ It's really great!!! \$\endgroup\$
    – Qwertiy
    Commented Nov 20, 2014 at 19:57
  • \$\begingroup\$ This is awesome! \$\endgroup\$ Commented Dec 13, 2015 at 1:16
  • 3
    \$\begingroup\$ @EriktheOutgolfer might? How will this not crash at some point due to infinite recursion? I don't see how this could go on for multiple hours \$\endgroup\$
    – phil294
    Commented Jun 3, 2017 at 4:04
  • 2
    \$\begingroup\$ Actually it will be able to continue indefinitely. Naming a batch file to run without using call replaces the prior batch execution with the new one. So this is a tail-call, not recursion. \$\endgroup\$
    – Miral
    Commented Feb 22, 2018 at 7:03
79
\$\begingroup\$

Befunge 98 - 2

,"

Outputs ",,,,,,,,,,," for eternity.

\$\endgroup\$
8
  • 2
    \$\begingroup\$ Actually somewhat clever. \$\endgroup\$
    – tbodt
    Commented Sep 2, 2014 at 20:16
  • \$\begingroup\$ Thank you. It's strange, the ", version outputs spaces (or ". outputs 32 32 32) using the most common b98 implementation. No idea where it gets it from. \$\endgroup\$
    – AndoDaan
    Commented Sep 2, 2014 at 20:20
  • 1
    \$\begingroup\$ It's too bad it's buried under 82,395 really crappy answers. \$\endgroup\$
    – tbodt
    Commented Sep 3, 2014 at 2:57
  • 8
    \$\begingroup\$ @tbodt Well, according to the spec, my little program has all of eternity to inch its way up. So... fingers crossed... \$\endgroup\$
    – AndoDaan
    Commented Sep 3, 2014 at 3:21
  • \$\begingroup\$ @AndoDaan: ", creates a string of a comma and INT_MAX-2 spaces, and then prints the last space. So the stack will fill itself with a comma INT_MAX-3 spaces, not really efficient. \$\endgroup\$
    – yyny
    Commented Jul 15, 2015 at 9:29
67
\$\begingroup\$

sh, 3 bytes

yes

outputs y continuously

\$\endgroup\$
9
  • 11
    \$\begingroup\$ Though yes is an external binary, and not part of bash (strictly speaking). \$\endgroup\$
    – Bob
    Commented Nov 9, 2013 at 12:35
  • 64
    \$\begingroup\$ In bash, (almost) everything is an external binary. \$\endgroup\$ Commented Nov 10, 2013 at 22:42
  • 5
    \$\begingroup\$ Normally you don't have an alias y=yes and if your system isn't esoteric you can assume that yes is in your $PATH (see GNU Core Utilities). With your logic it is possible to assume weird constellations for every solution. \$\endgroup\$
    – klingt.net
    Commented Nov 28, 2013 at 9:21
  • 6
    \$\begingroup\$ Right, but this is not only a bash capability: I'ts a POSIX shell basic part of core utils. (Ie: please change title for sh: 3 chars ;-) \$\endgroup\$ Commented Jan 29, 2014 at 6:34
  • 2
    \$\begingroup\$ As technosaurus says, in busybox it is a builtin, but in sh it isn't so you must say sh+coreutils instead. \$\endgroup\$ Commented Apr 12, 2016 at 12:53
44
\$\begingroup\$

GHCi + Data.Function, 8 bytes

Old thread, but a fun one is

fix show

in Haskell, it prints

"\"\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\…

forever since it's basically running

let x = show x in x

It knows that x is a string, so the first character is ", so this needs to be escaped with \", but know that \ needs to be escaped so \\\x, and so on and so on.

\$\endgroup\$
2
  • \$\begingroup\$ ... wow. Now I'm wondering if fix$show would have been more aesthetic :-) \$\endgroup\$ Commented Mar 4, 2014 at 5:26
  • 15
    \$\begingroup\$ Because this requires import Data.Function, and because it returns the string rather than printing it, I question the fairness of the character count. Also, the string is actually "\"\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\…". \$\endgroup\$ Commented Feb 20, 2016 at 10:18
35
\$\begingroup\$

Bash, 4 bytes

$0&$

Outputs ./forever2.sh: line 1: $: command not found continuously.

Because $0 is backgrounded, each parent dies after the invalid command $, and so stack/memory is not eaten up, and this should continue indefinitely.

Strangely the output gets slower and slower over time. top reports that system CPU usage is close to 100%, but there are memory- or CPU-hog processes. Presumably some resource allocation in the kernel gets less and less efficient.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ maybe a behavior of stdout or similar... \$\endgroup\$
    – masterX244
    Commented Jun 24, 2014 at 19:08
  • 1
    \$\begingroup\$ freeing resources is competing with forking processes/ To stop it you cannot kill the process as the PID changes only way to stop it is to rename the script so $0 fails. \$\endgroup\$
    – Emmanuel
    Commented Nov 25, 2016 at 14:44
35
\$\begingroup\$

Windows Batch file, 9 characters

:a
goto a
\$\endgroup\$
9
  • 2
    \$\begingroup\$ This does not produce infinite output, does it...? \$\endgroup\$
    – Doorknob
    Commented Nov 9, 2013 at 2:28
  • 44
    \$\begingroup\$ it does...without @echo off, it prints "goto a" until you close it \$\endgroup\$ Commented Nov 9, 2013 at 2:30
  • 12
    \$\begingroup\$ we need mor BAT around here \$\endgroup\$
    – Einacio
    Commented Jan 29, 2014 at 20:44
  • 41
    \$\begingroup\$ I count ten characters: :a\r\ngoto a because Windows uses CRLF \$\endgroup\$
    – wchargin
    Commented Feb 3, 2014 at 23:31
  • 1
    \$\begingroup\$ @WChargin I just checked using a hex editor. 3a 61 0a 67 6f 74 6f 20 works on my windows 8... :P \$\endgroup\$
    – yyny
    Commented Jul 1, 2015 at 22:44
34
\$\begingroup\$

Java, 54 characters

Best attempt in Java:

class A{static{for(int i=0;i<1;)System.out.print(1);}}
\$\endgroup\$
10
  • 7
    \$\begingroup\$ Functional, complies with the rules, golfed. Wondering why it was downvoted. \$\endgroup\$
    – manatwork
    Commented Nov 11, 2013 at 15:03
  • 14
    \$\begingroup\$ Does java forbid the classic for(;;) pattern? What about while(true)? \$\endgroup\$ Commented Nov 21, 2013 at 13:38
  • 21
    \$\begingroup\$ @CodesInChaos, Java doesn't normally disallow those patterns and normally I would consider them cleaner and more idiomatic. Here though we are trying to sneak an infinite loop past the compiler (those forms cause the compiler to complain about the static {} block not exiting). \$\endgroup\$
    – Rich Smith
    Commented Nov 21, 2013 at 17:56
  • 2
    \$\begingroup\$ @Mechanicalsnail Yes, static blocks can't execute alone since java 7. \$\endgroup\$
    – Fabinout
    Commented Feb 4, 2014 at 14:51
  • 1
    \$\begingroup\$ @OliverNi But you can't use the static block. \$\endgroup\$
    – Okx
    Commented Sep 1, 2017 at 15:17
33
\$\begingroup\$

Brainfuck, 4

+[.]

Alternatively,

-[.]
\$\endgroup\$
2
  • 13
    \$\begingroup\$ Neither \x01 nor \xFF are printable characters. I guess that wasn't a requirement, though :-/ \$\endgroup\$ Commented Nov 9, 2013 at 5:37
  • \$\begingroup\$ A way to make it output printable characters would be to replace the + with , It does mean it requires an input though \$\endgroup\$
    – Prismo
    Commented Oct 3, 2018 at 23:01
30
\$\begingroup\$

LOLCODE (36)

HAI IZ 1<2? VISIBLE "0" KTHX KTHXBYE 

Thought I'd give LOLCODE a shot, has a surprisingly large amount of functionality.

\$\endgroup\$
2
  • 3
    \$\begingroup\$ Don't need to ask about stdio. \$\endgroup\$
    – cat
    Commented Jul 18, 2016 at 4:13
  • 1
    \$\begingroup\$ In the repl.it version of LOLCODE, you don't need HAI and KTHXBYE \$\endgroup\$
    – MilkyWay90
    Commented May 13, 2019 at 2:58
27
\$\begingroup\$

JavaScript: 14

WARNING: you really don't want to run this in your browser

for(;;)alert()
\$\endgroup\$
6
  • 36
    \$\begingroup\$ Just check "Prevent this site from opening more dialogs". \$\endgroup\$ Commented Nov 11, 2013 at 8:42
  • 1
    \$\begingroup\$ @JohannesKuhn don't check this and you need a reboot \$\endgroup\$ Commented Nov 11, 2013 at 11:48
  • 9
    \$\begingroup\$ Or just do nothing and it don't display any further output. \$\endgroup\$ Commented Nov 11, 2013 at 12:02
  • \$\begingroup\$ just running alert() gives me this error Error: Not enough arguments [nsIDOMWindow.alert] \$\endgroup\$
    – Clyde Lobo
    Commented Mar 10, 2014 at 9:21
  • 4
    \$\begingroup\$ Is it really infinite output, when the process is blocked and execution halted until humanoid interaction? \$\endgroup\$ Commented May 27, 2014 at 15:25
25
\$\begingroup\$

Turing Machine - 6 Characters :

#s->1Rs

where # is blank symbol (on the tape by default), s describes the only existing (start) state, 1 is printing a digit, R means shifting to the right, s at the end is staying in the same state.

\$\endgroup\$
2
  • 3
    \$\begingroup\$ I count 7 chars!? \$\endgroup\$ Commented Nov 10, 2013 at 23:24
  • 11
    \$\begingroup\$ In maybe the most-common 5-tuple notation, this would be written simply as the 5 characters s#1Rs (current-state, current-symbol, symbol-to-write, direction-to-shift, next-state). \$\endgroup\$
    – r.e.s.
    Commented Nov 21, 2013 at 4:17
22
\$\begingroup\$

C, 23 chars

Slightly shorter than the best C/C++ answer so far. Prints empty lines infinitely (but if compiled without optimizations, overflows the stack).

main(){main(puts(""));}
\$\endgroup\$
7
  • 2
    \$\begingroup\$ 22 chars: putc(0) (or 1, or 2, ..., or 9). Would that work? \$\endgroup\$
    – CompuChip
    Commented Mar 10, 2014 at 22:59
  • 1
    \$\begingroup\$ @CompuChip, putc requires 2 parameters. \$\endgroup\$
    – ugoren
    Commented Mar 11, 2014 at 7:26
  • 10
    \$\begingroup\$ @tdbot, Just notice that this is the accepted answer. I appreciate the compliment, but can't understand why. There's an obviously shorter answer \$\endgroup\$
    – ugoren
    Commented Mar 11, 2014 at 7:28
  • \$\begingroup\$ @tbodt, not tdbot. ftfy \$\endgroup\$
    – user344
    Commented Jul 5, 2014 at 12:35
  • 7
    \$\begingroup\$ @nyuszika7h, This way I could show how modest I am, while holding on to the 15 rep. \$\endgroup\$
    – ugoren
    Commented Jul 6, 2014 at 11:20
22
\$\begingroup\$

x86 .COM Executable, 5 bytes

endless ASCII char set output

in hex:

40 CD 29 FF E6

in asm:

inc ax
int 0x29
jmp si

Explanation:

inc ax increments the register AX by one. int 0x29 is the "fast put char" routine of MSDOS, which simply outputs the value in AL (the low part of AX) and advances the cursor by one. jmp si is just a weird way to jump back to the top, since the register SI is 0x100 on almost every DOS-like operating system, which is also where a .com program starts ;) It's also possible to do a short jump instead, which also uses 2 bytes.

Sources:

MSDOS Start Values

Sizecoding WIKI

\$\endgroup\$
0
21
\$\begingroup\$

Haskell, 10

print[1..]

I think this is the shortest code to

  1. Print something out.
  2. Create an infinite Show:able datastructure.

For those interested, it prints:

[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,...
\$\endgroup\$
9
  • 5
    \$\begingroup\$ Is there any reason you chose the magic number 32 to stop at? \$\endgroup\$
    – ike
    Commented Nov 10, 2013 at 16:21
  • 15
    \$\begingroup\$ It seemed nice and round, at it also filled the code-block space as well as possible without the need for a next line. \$\endgroup\$
    – shiona
    Commented Nov 12, 2013 at 1:22
  • 2
    \$\begingroup\$ If the machine has a finite amount of memory, it might terminate when the integer grows too huge to hold in memory? \$\endgroup\$ Commented Nov 29, 2013 at 8:40
  • 3
    \$\begingroup\$ @JeppeStigNielsen Yes. However an integer that would fill even one megabyte of memory would be 2^(2^20), or around 6.7 * 10^315652. Up that to a gigabyte of memory and the number would become 2^(2^30), a monster with almost half a billion digits. I'm quite sure that if we tried printing the series the heat death of the universe would hit us before the memory ran out. And HDD failure way before that. \$\endgroup\$
    – shiona
    Commented Nov 29, 2013 at 10:05
  • 5
    \$\begingroup\$ In the comments below the OP it is mentioned that 'infinite untill your computer crashes' counts as well. \$\endgroup\$
    – 11684
    Commented Nov 29, 2013 at 18:22
18
\$\begingroup\$

Python 3: 15, 17, or 18 characters

mdeitrick's answer is longer in Python 3, which replaces the print statement with a function call (15 chars):

while 1:print()

This remains the shortest I've found in Python 3. However, there are some more-interesting ways of printing in an infinite loop that are only a few characters longer.

  • print() returns None, which != 9, making it an infinite loop; the 8 is a no-op that substitutes for pass (18 chars):

    while print()!=9:8
    
  • iter(print, 9) defines an iterable that returns the output of print() until it equals 9 (which never happens). any consumes the input iterable looking for a true value, which never arrives since print() always returns None. (You could also use set to the same effect.)

    any(iter(print,9))
    
  • Or, we can consumer the iterable by testing whether it contains 8 (17 chars):

    8in iter(print,9)
    
  • Or, unpack it using the splat operator:

    *_,=iter(print,9)
    
  • The weirdest way I thought of is to use splat destructuring inside a function call, function(*iterable). It seems that Python tries to consume the entire iterable before even attempting the function call—even if the function call is bogus. This means that we don't even need a real function, because the type error will only be thrown after the iterable is exhausted (i.e. never):

    8(*iter(print,9))
    
\$\endgroup\$
3
  • \$\begingroup\$ *iter(print,1), works and has only 15 chars, but does consume quite a bit of memory. \$\endgroup\$
    – ivzem
    Commented Sep 25, 2018 at 19:54
  • \$\begingroup\$ while(1):1 has 10 chars, basically an infinite loop \$\endgroup\$
    – Saphereye
    Commented Nov 30, 2021 at 17:49
  • \$\begingroup\$ Using 3.5+, 8(*iter(print,9)) can shorten to *iter(print,9), (dropping 17 down to 15). That trailing comma is mandatory (it makes it a tuple literal using the unpacking generalizations). Matches the while 1:print() for length, though the unpacking will rapidly exhaust all your memory and hopefully crash before it brings your computer to a standstill. \$\endgroup\$ Commented Feb 17, 2023 at 18:59
18
\$\begingroup\$

VBA: 12

Audio is output, right?

do:beep:loop

Put that in your 'favorite' coworker's favorite macro-enabled MS office file for some 'fun'!

Private Sub Workbook_Open()
    Do:Beep:Loop
End Sub

Bonus points if they're using headphones.

\$\endgroup\$
1
  • \$\begingroup\$ Dang, I was looking through the answers to see if anyone had thought about printing the bell char yet. +1 \$\endgroup\$
    – mbomb007
    Commented Apr 10, 2015 at 20:55
18
\$\begingroup\$

Marbelous 4

24MB

Marbelous does surprisingy well here. This will post an infinite amount of dollar signs $, though it will hit the stack limit rather quickly.

How it works.

24 is a language literal, which will fall off the board and be printed to STDOUT as its corresponding ascii character. MB is the name implicitly given to the main board, since the main board has no input, it will fire every tick. And since cells are evaluated from left to right, the literal will always be printed before the next recursive call.

So this is rougly equivalent to this pseudocode:

MB() {
    print('$');
    while(true) MB();
}

A solution without infinite recursion 11

24@0
@0/\..

This one works by looping the literal between two portals @0, whenever the 24 hits the lower @0 it is transported to the cell underneath the upper @0. It the lands on the /\, which is a clone operator, it puts one copy of the marble (literal) on it's left (back on the portal) and another one to its right. This coopy then falls off the board (since .. is an empty cell) and gets printed to STDOUT. In pseudocode, this would translate to:

MB() {
    while(true) print '$'
}

A shorter solution without infinite recursion 9

24
\\/\..

This one constantly tosses the marble around between a cloner and a deflector, putting one copy on the rightmost cell, to be dropped off the board. In pseudocode that would look something like:

MB() {
    List charlist = ['$'];
    while(true) {
        charlist.add(charlist[0];
        charlist.add(charlist[0];
        charlist.pop();
        print(charlist.pop());
        // Wait, what?
    }
}

note

The .. cells are necessary on the two last boards since the marbles would land off the board (and be discarded) otherwise. For some extra fun, you replace the 24 marble by FF and the empty .. cell by a ??, which turns any marble into a marble between 0 and it's current value before dropping it down. Guess what that would look like on STDOUT.

\$\endgroup\$
3
  • \$\begingroup\$ make your "/\/\" "\\/\" to avoid producing an extra marble off the left edge? purely aesthetic improvement. \$\endgroup\$
    – Sparr
    Commented Mar 5, 2015 at 17:07
  • \$\begingroup\$ @Sparr, point taken, I've edited the post. \$\endgroup\$
    – overactor
    Commented Mar 5, 2015 at 21:30
  • 7
    \$\begingroup\$ Shouldn't this solution be 25165824 bytes (24MB)? ;P \$\endgroup\$
    – hyperneutrino
    Commented Oct 12, 2017 at 14:19
16
\$\begingroup\$

perl, 10 chars

Here's another 10 char perl solution with some different tradeoffs. Specifically, it doesn't require the -n flag or user input to start. However, it does keep eating memory ad infinitum.

warn;do$0

save to a file, execute that file and you get eg:

Warning: something's wrong at /tmp/foo.pl line 1.
Warning: something's wrong at /tmp/foo.pl line 1.
Warning: something's wrong at /tmp/foo.pl line 1.
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Couldn't you make this shorter using say (which always prints a newline even if it can't find an argument from anywhere) rather than warn? (This requires the selection of a modern Perl variant using -M5.010, but that doesn't count against your character count.) \$\endgroup\$
    – user62131
    Commented Nov 26, 2016 at 21:54
16
\$\begingroup\$

piet - 3 codels

http://www.pietfiddle.net/img/auQXtFXATg.png?cs=15

Outputs an infinite number of 1's

\$\endgroup\$
16
\$\begingroup\$

Bitxtreme, 0.25 bytes

Binary representation:

00

From the documentation:

The first bit of each pair is a pointer to the memory position which holds the value to subtract from the accumulator. The result is stored in that same memory position pointed to by the operand. If the result is negative (the bits are in two's complement representation) then the second bit of the pair will be added to the current PC, modulo 2.

The program counter and accumulator are initialized to zero; then, the contents of memory location 0 are subtracted from the accumulator. This happens to be 0, leaving the accumulator at zero. Since there was no carry, the second bit is not added to the program counter.

The program counter is then incremented by 2 modulo 2, sending it back to the start, and causing an infinite loop. At each step, the special memory location 0 is modified, causing its contents (a 0) to be written to output.

It can be argued that this program should be scored as 1 byte, because the official interpreter in Python requires zero-padding. However, I don't think the zero-padding is really code.

\$\endgroup\$
15
\$\begingroup\$

><> (Fish), 2

A creative way to use the infinite codebox of fish:

"o

Because the instruction pointer returns back to the beginning of the line after reaching the end, this code can essentially be read as

"o"o

which means 'read the string "o" and then output it'.

You can test the code here

\$\endgroup\$
14
\$\begingroup\$

Z80Golf, 0 bytes

Try it online!

Surprisingly, this is an empty machine code program that produces infinite output.

How it works

Z80Golf machine initializes all the memory and registers to zero, and then loads the code to address 0. But there's nothing to load, so the whole memory becomes a no-op program.

When the PC hits the address $8000 ($ indicates hex in Z80 assembly), putchar is simulated. It consists of printing the register a to stdout and a ret instruction. Initially the stack pointer sp is zero, and ret does pc <- [sp]; sp <- sp + 2. The whole memory is zeroed, so the ret always returns to the start of the program regardless of sp.

The conclusion is that an empty Z80Golf program is a program that infinitely prints null bytes.

\$\endgroup\$
12
\$\begingroup\$

Summary: Ruby - 9, Golfscript - 6, ><> - 2, Whitespace - 19, Perl - 2

One language I know, and two I've never, ever, used before :D
EDIT: Perl one didn't work when I installed Perl to try it :(

Ruby, 9

loop{p 1}

Simply prints 1 on separate lines continually.

Also, a bunch of alternatives:

loop{p''} # prints [ "" ]  on separate lines continually
loop{p p} # prints [ nil ] on separate lines continually

10-char solution:

p 1while 1

I was actually surprised that I could remove the space between the first 1 and the while, but apparently it works

Golfscript, 6

{1p}do

My first Golfscript program! :P

><> (Fish), 2

1n

Whitespace, 19

lssslssstltlsslslsl

Where s represents a space, t represents a tab, and l a linefeed.

\$\endgroup\$
9
  • 12
    \$\begingroup\$ Every time someone types the words, "I don't have Perl," God kills a kitten. \$\endgroup\$
    – primo
    Commented Nov 9, 2013 at 3:37
  • 2
    \$\begingroup\$ @primo :P Well at least now I do. \$\endgroup\$
    – Doorknob
    Commented Nov 9, 2013 at 4:48
  • 2
    \$\begingroup\$ This is code golf. Please create one answer per submission. \$\endgroup\$
    – J B
    Commented Jan 15, 2014 at 8:35
  • 24
    \$\begingroup\$ @primo Good, I hate cats. And I don't have Perl. \$\endgroup\$
    – SQB
    Commented Jan 15, 2014 at 9:12
  • 5
    \$\begingroup\$ The GS program {1p}do only prints 1 and quits, because the do is an exec-pop-test sequence that continues only if it tests true. (Since there's no input, the stack is initially "", which, after exec of 1p, gets popped and tests false.) Just adding a dup will work though, i.e. {1.p}do (at 7 bytes). \$\endgroup\$
    – r.e.s.
    Commented Jan 26, 2014 at 17:22
12
\$\begingroup\$

C, 25 24

main(){main(puts("1"));}
\$\endgroup\$
8
  • 4
    \$\begingroup\$ s/while/main/ \$\endgroup\$
    – ugoren
    Commented Nov 10, 2013 at 14:05
  • 2
    \$\begingroup\$ I am not sure that there are stackoverflow exception in C, but something bad will happen when you run out of memory. \$\endgroup\$ Commented Nov 11, 2013 at 11:46
  • 9
    \$\begingroup\$ Tailcall optimisation ftw. \$\endgroup\$ Commented Nov 28, 2013 at 8:38
  • 5
    \$\begingroup\$ @JohannesKuhn: that's not a tail call. If it'd been return main(puts("1")) then it'd been a tail call. \$\endgroup\$
    – marinus
    Commented Dec 30, 2013 at 13:39
  • 4
    \$\begingroup\$ @psgivens. In c a function without any parameters can take any amount of parameters. Only a signature of methodName(void) accepts exactly zero parameters. \$\endgroup\$ Commented Jan 27, 2014 at 16:59
12
\$\begingroup\$

dc, 7

[pdx]dx

prints 'pdx\n' infinitely many times.

\$\endgroup\$
12
\$\begingroup\$

Minecraft > 1.9 2 + 5 = 7 Bytes

Note that this version of this "language" was created after the question.

Surprisingly good for MineCraft. o-o

This is using this definition of MineCraft scoring.

the system

The command say 1 put inside of a permanently active repeating command block. It will permanently output [@] 1 to the chat.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ I believe this is technically invalid, because it uses a version of the language from after the challenge :P \$\endgroup\$
    – lirtosiast
    Commented Nov 12, 2015 at 22:40
  • \$\begingroup\$ Never mind. I'll mark it as invalid. ;D \$\endgroup\$ Commented Nov 12, 2015 at 22:43
  • \$\begingroup\$ It's valid now; we had a rule change. \$\endgroup\$
    – wizzwizz4
    Commented Jul 31, 2019 at 12:46
11
\$\begingroup\$

Seed, 4 bytes

99 5

Try it online! Outputs 11 infinitely

Generates the following Befunge-98 Program:

[glzgx"Lz^v*M7TW!4:wi/l-[, s44~s;|Sa3zb|u<B/-&<Y a@=nN>Nc%}"gq!kCW $1{2hyzABRj*glr#z(@Zx@xT=>1'.b
/

Try it online!


The relevant part is just this:

[>1'.b
/

b pushes 11 to the stack and . prints it. 1 and 49 are also pushed to the stack, but never actually printed.

Animation of the code running:

enter image description here

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Won't this eventually run out of memory if values are continually pushed to the stack without being popped? \$\endgroup\$ Commented Apr 4, 2018 at 18:54
  • 1
    \$\begingroup\$ @cairdcoinheringaahing You'd be hard pressed to find an answer here that won't run out of memory \$\endgroup\$
    – rydwolf
    Commented Jun 21, 2020 at 2:46
11
\$\begingroup\$

Vyxal, 4 bytes (UTF-8)

🍪

Try it Online!

Outputs cookie forever.

\$\endgroup\$
5
  • 3
    \$\begingroup\$ Cookie. 🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪 \$\endgroup\$
    – lyxal
    Commented Apr 23, 2022 at 2:54
  • 2
    \$\begingroup\$ vyxal genie giveth \$\endgroup\$
    – Razetime
    Commented Apr 23, 2022 at 14:19
  • 1
    \$\begingroup\$ yay! Cookie gooo \$\endgroup\$
    – math scat
    Commented Apr 25, 2022 at 11:13
  • \$\begingroup\$ So a 🍪 takes 4 "bytes" to eat? :3 \$\endgroup\$
    – DialFrost
    Commented Oct 28, 2022 at 7:13
  • \$\begingroup\$ vyxal.pythonanywhere.com/#WyIiLCIiLCJ7LCIsIiIsIiJd 2 bytes, not as cool as a cookie \$\endgroup\$
    – pacman256
    Commented Oct 31, 2022 at 3:51
1
2 3 4 5
12

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.