This one is pretty simple.

Write the shortest program you can, while generating the most output.

To make it fun, programs that produce infinite output will be disqualified.

The winner is the program with the largest output size/code size ratio.

The results are based on what works on my computer, which is a Mac running Mac OS X 10.7.5 with an Intel Core i5 and 8GB of memory.

  • \$\begingroup\$ It's not clear exactly what you're asking. Should answers assume unbounded memory, unbounded index sizes, etc? \$\endgroup\$ – Peter Taylor Nov 3 '13 at 23:08
  • \$\begingroup\$ @PeterTaylor I fixed that. \$\endgroup\$ – tbodt Nov 3 '13 at 23:22
  • 5
    \$\begingroup\$ Be blowed if I can figure it out, but I'm sure there is a way to have some interpretter interpret an empty file and produce any content - which would also give an infinite ratio. \$\endgroup\$ – user8777 Nov 4 '13 at 1:24
  • 8
    \$\begingroup\$ @LegoStormtroopr GolfScript fits the bill. Executing an empty script will produce exactly one character of output: \n \$\endgroup\$ – primo Nov 4 '13 at 5:18
  • 1
    \$\begingroup\$ @user2509848 no, because, like I said, infinite output does not count. \$\endgroup\$ – tbodt Jan 10 '14 at 0:35

16 Answers 16


Python: 8 chars code, 387420489 chars output -- Ratio: 48427561.125 : 1


We can have the ratio tend to infinity by adding more **9s:


For example:


which has a ratio of ~10101010108.568 (unimaginably large number).

  • \$\begingroup\$ Better than the other one... \$\endgroup\$ – tbodt Nov 3 '13 at 22:44
  • \$\begingroup\$ @tbodt Why? O_o @arshajii If you add enough **9s, wouldn't it eventually become Infinity? \$\endgroup\$ – Doorknob Nov 3 '13 at 22:45
  • \$\begingroup\$ @Doorknob Sorry, I don't know everything about python. Now the challenge is: Figure out the maximum number of **9s you can put before the output becomes Infinity. \$\endgroup\$ – tbodt Nov 3 '13 at 22:46
  • 1
    \$\begingroup\$ @Doorknob Python ints have arbitrary precision. \$\endgroup\$ – arshajii Nov 3 '13 at 22:47
  • \$\begingroup\$ @tbodt See the comment above. \$\endgroup\$ – arshajii Nov 3 '13 at 22:48

So, these are all good programs that produce lots of output with very little code, but none of them are really short...

brainfuck, 5 characters, 255 bytes of output


I think this is the only use case where brainfuck really excels. I know this one isn't going to win, but I don't think we can possibly do better than the Python example. Not only that, but...

brainfuck, 4 characters, infinite output


I conjecture that this is the shortest infinite-output program out there.

Actually, hold on, my mate's just come up with a really good one.

Python, 80 bytes, unknown amount of output

from datetime import datetime
while datetime.now()!=datetime.max()
 print "This will probably get disqualified"

This program will definitely halt eventually, but will only do so after roughly 8,000 years. The exact number of characters output depends on the rate at which your computer can produce characters.

  • 1
    \$\begingroup\$ I like the python one :D \$\endgroup\$ – Kevin Cox Nov 22 '13 at 3:44
  • 2
    \$\begingroup\$ "I conjecture that this is the shortest infinite-output program out there" nope, this is where Befunge's implicit loop (via wraparound) comes handy: . outputs an infinite stream of 0 characters. \$\endgroup\$ – FireFly Dec 2 '13 at 0:07

Perl - 19 bytes, 187200000000000000 bytes output (9852631578947368.42 : 1)


166 petabyes with a single print statement, using no more than 1.7GB of memory.

There's a few things that made this challenge more interesting that I thought it would be. Perl seems to refuse to allocate more than 1GB of memory to any single list. Hence, the 4-byte scalar reference to the inner string may only be repeated 26e7 ≈ 228 times. $] is the 'old perl version' number which, as a string, is 8 bytes long, resembling 5.016002.

With more system memory, it should be able to go higher. Assuming the full 8GB were actually available, you should be able to use $]x9e8 for the inner string instead, which would output 1.62 exabytes.

  • 16
    \$\begingroup\$ "If you give a 1,000,000 monkeys 1,000,000 typewriters, and give them 1,000,000 years to write stuff, one monkey will eventual write a Java program. The others just produce Perl scripts." That's what I thought when I saw this :P source \$\endgroup\$ – Doorknob Nov 6 '13 at 2:55

Ruby and Python, 13 chars, 599994 char output, ~46153:1 ratio


Simply raises a very large number to the power of another very large number. Takes about 20 seconds to run. I can't increase the numbers because that would make the number become Infinity.

(I did this earlier, I am currently working on making a loop for even longer output)

Edit: I did it!

Ruby, 28 chars, 6e599999 char output, ~6e599998 ratio (I think)

a=999999**99999;a.times{p a}

Untested (for obvious reasons), but I'm pretty sure the first number is about 1e599994, which multiplied by 599994 is about 6e599999. Theoretically it would work, but I'm not sure if it would crash your computer, so disclaimer: I am not responsible if it harms your computer in any way :P

Of course, you can keep going:

Ruby, 37 chars, 6e359992800041 char output, ~6e359992800040 ratio

a=999999**99999;a.times{a.times{p a}}

And so on, but I doubt any computer can handle that :P

  • \$\begingroup\$ That's really a polyglot... \$\endgroup\$ – tbodt Nov 3 '13 at 22:33
  • \$\begingroup\$ @tbodt Hehe, right! When I add my changes it won't be though \$\endgroup\$ – Doorknob Nov 3 '13 at 22:33

If infinite input was allowed,

cat /dev/random

Since it's not,

head -99 /dev/random

(25128 output : 20 input = 1256.4:1)

I'm not on a Linux box, but I imagine you could do something like

timeout 99d cat /dev/random

and get a huge output. (via GigaWatt's response)

  • 2
    \$\begingroup\$ You can substitute one character and make your output 8562 times longer: timeout 99d. Yep, 99 day runtime. Also, I'm not certain on this, but eventually you'll empty the entropy pool with /dev/random and it'll block, so /dev/urandom may be more appropriate. (I managed to get 40 MB/s with urandom and only 128 KB/s with random) \$\endgroup\$ – Mr. Llama Nov 5 '13 at 17:56
  • \$\begingroup\$ @GigaWatt that is awesome. \$\endgroup\$ – tristin Nov 7 '13 at 19:14

HQ9+, 11471


Actual character count varies depending on the interpreter, but probably around 10000 would be right?

  • \$\begingroup\$ What is HQ9+? I've never heard of it. \$\endgroup\$ – tbodt Nov 5 '13 at 19:08
  • \$\begingroup\$ Ahh, sorry, it was mostly a joke since it's not a 'real' programming language, but: esolangs.org/wiki/HQ9%2B \$\endgroup\$ – Dom Hastings Nov 5 '13 at 19:14

C#: 108 chars. Ratio: 742123445489230793057592 : 1

for(ulong i=0;i<ulong.MaxValue;i++){Console.Write(new WebClient().DownloadString(@"http://bit.ly/dDuoI4"));}

It just downloads and prints the wikipedia's List of law clerks of the Supreme Court of the United States (4344904 chars) 18446744073709551615 times.

  • \$\begingroup\$ That requires a URL shortener. I'm not sure about that. \$\endgroup\$ – tbodt Dec 1 '13 at 19:01
  • 1
    \$\begingroup\$ Ok. And what about this: for(ulong i=0;i<ulong.MaxValue;i++){Console.Write(new string('a',int.MaxValue));} 2147483647 chars * 18446744073709551615 times = 39614081238685424720914939905 / 81 => Ratio: 489062731341795366924875801 \$\endgroup\$ – thepirat000 Dec 1 '13 at 20:02
  • \$\begingroup\$ Much better. No URL shortener required. \$\endgroup\$ – tbodt Dec 2 '13 at 1:22

~-~! - Ratio: (6444464)/154 ~= 10101010101.583328920493678


How it works: First, it sets ' to 4^3, or 64. Then, it makes '' a function which sets ' to '^4 * times (where * is it's input). ''' is then made a function which calls '' with the input as '^4. Then, '''' is made a function which calls ''' with '^4 as it's input. '''' is then called with an input of 64. Finally, '' is changed to a function which prints a space * times; this is then called with an input of '.

Turns out, in the end, ' is 6444464, and my program's length is 154; punch that into Wolfram|Alpha and it spits out 10101010101.583328920493678, which it doesn't even bother to calculate. I don't even know how many digits it contains, but 6444 contains 463. Pretty nice for a language that only supports unary explicit numbers and doesn't have an exponent function ;3

I could have made this a lot larger, but, overkill.


Javascript: 27 chars; 260,431,976 char output; 9,645,628.74 ratio


This code recursively encodes the input 61 to Base64 61 times. Encoding any input of length n to Base64 produces an output of length n * 8/6, rounded up to a multiple of 4.

This must be run from a JavaScript console environment that natively supports the Base64-encoding function btoa. (Any modern browser, but not Node.js.) Note Chrome cannot run higher than i=61, while Firefox can only reach i=60. Note also that Chrome's console cannot actually display the output because it is too large, but you can verify the result size by running


If this program were allowed to run for the maximum i=99, it would produce a hypothetical output of size 14,566,872,071,840 (14.5 trillion, 14.5e12) chars, for a hypothetical ratio of around 540 billion (5.39e11).


Ruby, 23 characters - ~500000000000000 (5e14) Output

while rand
puts 0

Ti-Basic 84, 13 characters - ~3000 Output

:Disp 1

Name the program prgmA


ruby, 283 96 44 chars


Not very short, but it compensates for it in output, which is so much I haven't yet been able to measure it.

  • 2
    \$\begingroup\$ by my calculations this would be about 1e127 chars output. anyway, assigning to a variable would cut the code size about in half. also, 1e99 is a bigger number that takes less space. also, use map instead of each, use puts instead of print, remove extra whitespace between print and "ier.... You could also replace that big string with 'a'*999 (or even ?a*999) which is a longer string that takes less space. summary: this is not golfed at all \$\endgroup\$ – Doorknob Nov 4 '13 at 0:01
  • \$\begingroup\$ @Doorknob Thanks. I know nothing about ruby, except chapter 3 of why's poignant guide to ruby. \$\endgroup\$ – tbodt Nov 4 '13 at 0:17
  • \$\begingroup\$ yeah, why don't you just assign (0..1e99).map to a variable? like a=(0...1e99).map;a{a{a{a{a{puts'a'*99}}}}} \$\endgroup\$ – Doorknob Nov 4 '13 at 3:01
  • \$\begingroup\$ My Ruby interpretter ran out of memory evaluating a=(0...1e99).map. You might want to tone that back a bit. 0..1e9 would use about 4GB. \$\endgroup\$ – primo Nov 5 '13 at 17:06

Mathematica 9 chars Ratio: ~ 4564112 : 1

The following is a picture of Mathematica input. I haven't figured how to render it in SE.


Here's a screen shot showing the number of digits in the output. IntegerDigits converts the output to a list of digits. Length counts the number of digits.


Keystrokes to enter: 9, ctrl6, 9, ctrl6, 9, ctrl6, 9, ctrl6, 9....

  • 1
    \$\begingroup\$ What? You can type that into Mathematica? \$\endgroup\$ – tbodt Nov 3 '13 at 23:32
  • \$\begingroup\$ Yes, this is legitimate input to Mathematica. \$\endgroup\$ – DavidC Nov 3 '13 at 23:33
  • \$\begingroup\$ And what keystrokes are required? \$\endgroup\$ – tbodt Nov 3 '13 at 23:34
  • \$\begingroup\$ @tbodt Keystrokes are now shown in the answer. \$\endgroup\$ – DavidC Nov 4 '13 at 0:01
  • 1
    \$\begingroup\$ I don't know if you would have to specify order, but you would want to have it calculate top down: (9^9)^9 is a 78 digit number, but 9^(9^9) is a 369,693,100 digit number (thanks, wolframalpha) \$\endgroup\$ – SeanC Nov 5 '13 at 17:19

Befunge-93: 48 characters, about ((2^32)^2)*10 characters output

Befunge's stack is theoretically infinite, but the numbers that stack stores are limited to the size of an unsigned long integer (here assumed to be 32 bits). Thus, to a Befunge interpreter, (x+1)>x is false for the proper value of x. We use this fact to first push all values from zero to the maximum (twice, with a one every third number), and then for each value on the stack, we output and decrement it, then pop it when it reaches zero. Eventually the stack empties and the program terminates. I may be a bit off on the output size, but it should be somewhere in that ballpark.

>::1# + #1\`# :# _> #- #1 :# :# .# _# .# :# _@

C: 48 chars, approx. (2^32 - 1)*65090 bytes output

main(){for(int i=1<<31;i<~0;)puts("!");main();}

Note that the 65090 is not exact, and depends on stack size. The program will eventually stop when it crashes. Also, I could just put a longer and longer string in puts() to make the ration approach infinity, but that seems rather cheaty.

  • 1
    \$\begingroup\$ that's an infinite loop \$\endgroup\$ – izabera Mar 11 '14 at 0:15
  • \$\begingroup\$ Ouch, you're right, I think. I'll see if I can figure how to fix that. \$\endgroup\$ – Stuntddude Mar 11 '14 at 2:05

java(131): unknown but finite amount

class A{public static void main(String[] args){while(Math.random()>0){for(long l=0;l!=-1;l++){System.out.println("1234567890");}}}}

Using the low chance of Math.random() to get to 0 in a loop and then goin 2^64-1 loops thru a foreach with the output 1234567890;


Python 3, 115 bytes, runs for 7983 years (unknown # of chars)

EDIT: ymbirtt beat me to it ._.

I know, this isn't really short, and I know that the other Python answer is much longer, But I decided to give this a shot.

The program runs for about 8000 years, which, as you know, is a pretty long time.

What it does is continuously get the current time using the datetime.datetime.now() function, and it compares it to 9999-12-31 24:59:59.999999, which is as far as I know the maximum date in Python.

If is is equal, the program stops. If it isn't, it continously outputs a.

import datetime
while 1:
    if str(datetime.datetime.now())=="9999-12-31 24:59:59.999999":exit
  • 1
    \$\begingroup\$ What if you miss that moment? \$\endgroup\$ – C5H8NNaO4 May 14 '16 at 16:28
  • \$\begingroup\$ @C5H8NNaO4 If you leave it on for all 7983 years, you hopefully won't miss it. \$\endgroup\$ – m654 May 14 '16 at 16:31

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