Shortest code for longest output

9

4

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.

tbodt

Posted 2013-11-03T22:28:35.350

Reputation: 2 176

Question was closed 2016-05-14T15:48:56.613

It's not clear exactly what you're asking. Should answers assume unbounded memory, unbounded index sizes, etc? – Peter Taylor – 2013-11-03T23:08:07.593

@PeterTaylor I fixed that. – tbodt – 2013-11-03T23:22:12.507

5Be 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. – None – 2013-11-04T01:24:15.617

8@LegoStormtroopr GolfScript fits the bill. Executing an empty script will produce exactly one character of output: \n – primo – 2013-11-04T05:18:32.413

Also, it is more or less a more general version of http://codegolf.stackexchange.com/q/12655/1490.

– Howard – 2013-11-04T07:13:08.883

What do you mean by "what works on my computer"? If a huge number is computable (in principle) using less than 8 GB memory, but requires an infeasible execution time, does that "work"? – r.e.s. – 2013-11-06T05:21:35.493

@r.e.s. I interpret "works" to mean that, given enough time, the code would eventually produce output (actual output) of the claimed length, while not consuming more than 8GB of system memory. Although, others seem to have a more liberal interpretation: both for the term "working", and for the term "program." – primo – 2013-11-06T10:28:37.477

@primo - What is "actual" output? Would it "work" if a program requires less than 8 GB of memory and eventually halts, but needs an amount of time exceeding the age of the universe and/or prints more characters than there are atoms in the known universe? – r.e.s. – 2013-11-06T13:26:30.420

@r.e.s. By "actual" output, I mean that the "program", as it were, should contain a statement which actually outputs something, rather than just evaluating an expression which would have the claimed length if actually output. Whether the program is allowed to take longer than the theoretical lifespan of the computer it's running on is a question that needs to be answered by the OP. – primo – 2013-11-07T03:57:43.307

Mac? Then my bluescreen idea won't work :( – osvein – 2013-12-29T09:28:17.407

@anustart My mother's Mac had a bluescreen once. It only happened once, but was the same color blue as Windows. – None – 2014-01-09T04:54:59.077

I read that Befunge can produce infinite output with the character '.' (period). Does that count? – None – 2014-01-09T04:55:43.440

1@user2509848 no, because, like I said, infinite output does not count. – tbodt – 2014-01-10T00:35:48.307

Answers

17

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

'a'*9**9

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

'a'*9**9**9
'a'*9**9**9**9
etc.

For example:

'a'*9**9**9**9**9**9

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

arshajii

Posted 2013-11-03T22:28:35.350

Reputation: 2 142

Better than the other one... – tbodt – 2013-11-03T22:44:26.803

@tbodt Why? O_o @arshajii If you add enough **9s, wouldn't it eventually become Infinity? – Doorknob – 2013-11-03T22:45:46.233

@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. – tbodt – 2013-11-03T22:46:48.163

@Doorknob Python ints have arbitrary precision. – arshajii – 2013-11-03T22:47:15.610

@tbodt See the comment above. – arshajii – 2013-11-03T22:48:05.897

ah, so now the challenge is "figure out when Python errors or the computer crashes" :P – Doorknob – 2013-11-03T22:48:13.413

Well that would depend on the computer, of course :P I'm sure we could imagine a hypothetical computer for which all of this works (i.e. any number of 9s). Based on Python's specification, this should work indeed. – arshajii – 2013-11-03T22:48:40.163

@Doorknob (among others): Things are happening pretty fast here, and it is hard to keep up. – tbodt – 2013-11-03T22:49:04.850

@tbodt You could just upvote both answers (you shouldn't accept answers early - it discourages further answers). – Doorknob – 2013-11-03T22:50:09.047

It would be much bigger if you replace that last 9 by 99. (9**99 )/9.0= 3.279185047850306e+93 – user80551 – 2014-03-11T11:52:02.997

15

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.

ymbirtt

Posted 2013-11-03T22:28:35.350

Reputation: 1 792

1I like the python one :D – Kevin Cox – 2013-11-22T03:44:27.237

2"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. – FireFly – 2013-12-02T00:07:23.947

13

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

print+($]x9e7)x26e7

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.

primo

Posted 2013-11-03T22:28:35.350

Reputation: 30 891

15

"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

– Doorknob – 2013-11-06T02:55:05.743

4

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

999999**99999

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

Doorknob

Posted 2013-11-03T22:28:35.350

Reputation: 68 138

That's really a polyglot... – tbodt – 2013-11-03T22:33:12.447

@tbodt Hehe, right! When I add my changes it won't be though – Doorknob – 2013-11-03T22:33:34.797

4

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)

tristin

Posted 2013-11-03T22:28:35.350

Reputation: 189

1You 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) – Mr. Llama – 2013-11-05T17:56:01.283

@GigaWatt that is awesome. – tristin – 2013-11-07T19:14:57.993

4

HQ9+, 11471

9

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

Dom Hastings

Posted 2013-11-03T22:28:35.350

Reputation: 16 415

What is HQ9+? I've never heard of it. – tbodt – 2013-11-05T19:08:22.430

Ahh, sorry, it was mostly a joke since it's not a 'real' programming language, but: http://esolangs.org/wiki/HQ9%2B

– Dom Hastings – 2013-11-05T19:14:11.290

2

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.

thepirat000

Posted 2013-11-03T22:28:35.350

Reputation: 588

That requires a URL shortener. I'm not sure about that. – tbodt – 2013-12-01T19:01:45.060

1Ok. 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 – thepirat000 – 2013-12-01T20:02:53.653

Much better. No URL shortener required. – tbodt – 2013-12-02T01:22:52.097

2

~-~! - 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.

cjfaure

Posted 2013-11-03T22:28:35.350

Reputation: 4 213

1

ruby, 283 96 44 chars

a=1e99.times;a{a{a{a{a{puts'a'*99}}}}}}}}}}

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

tbodt

Posted 2013-11-03T22:28:35.350

Reputation: 2 176

2by 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 – Doorknob – 2013-11-04T00:01:32.010

@Doorknob Thanks. I know nothing about ruby, except chapter 3 of why's poignant guide to ruby. – tbodt – 2013-11-04T00:17:09.250

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}}}}} – Doorknob – 2013-11-04T03:01:40.027

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. – primo – 2013-11-05T17:06:53.457

1

Mathematica 9 chars Ratio: ~ 4564112 : 1

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

exponents

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.

count

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

DavidC

Posted 2013-11-03T22:28:35.350

Reputation: 24 524

1What? You can type that into Mathematica? – tbodt – 2013-11-03T23:32:28.660

Yes, this is legitimate input to Mathematica. – DavidC – 2013-11-03T23:33:23.010

And what keystrokes are required? – tbodt – 2013-11-03T23:34:47.437

@tbodt Keystrokes are now shown in the answer. – DavidC – 2013-11-04T00:01:27.490

If you would like to use text instead of an image, then just add this code to your answer: 9<sup>9<sup>9<sup>9<sup>9<sup>9<sup>9<sup>9<sup>9</sup></sup></sup></sup></sup></sup></sup></sup> – ProgramFOX – 2013-11-04T17:51:52.157

Thanks. I tried that but the font size becomes illegible. If there were a way to do that while keeping the text readable, I'd do so. – DavidC – 2013-11-04T18:29:22.960

1

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)

– SeanC – 2013-11-05T17:19:27.480

Good point. Mathematica defaults to the second order, so the FullForm of a^b^c is Power[a,Power[b,c]]. – DavidC – 2013-11-05T18:19:25.690

Wow. I'd really love a copy of Mathematica right now. – cjfaure – 2014-03-11T10:12:15.167

You can download a trial version: http://www.wolfram.com/mathematica/ But it tends to be pricey unless you are a student or educator.

– DavidC – 2014-03-11T14:01:30.810

1

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

for(s=i=61;s=btoa(s),i--;)s

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

for(s=i=61;s=btoa(s),i--;)s.length

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).

apsillers

Posted 2013-11-03T22:28:35.350

Reputation: 3 632

1

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

while rand
puts 0
end

Ti-Basic 84, 13 characters - ~3000 Output

:Disp 1
:prgmA

Name the program prgmA

Timtech

Posted 2013-11-03T22:28:35.350

Reputation: 12 038

0

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 :# :# .# _# .# :# _@

MDS

Posted 2013-11-03T22:28:35.350

Reputation: 61

0

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.

Stuntddude

Posted 2013-11-03T22:28:35.350

Reputation: 586

1that's an infinite loop – izabera – 2014-03-11T00:15:47.727

Ouch, you're right, I think. I'll see if I can figure how to fix that. – Stuntddude – 2014-03-11T02:05:27.233

0

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;

masterX244

Posted 2013-11-03T22:28:35.350

Reputation: 3 942

0

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
    else:print("a")

m654

Posted 2013-11-03T22:28:35.350

Reputation: 765

1What if you miss that moment? – C5H8NNaO4 – 2016-05-14T16:28:22.217

@C5H8NNaO4 If you leave it on for all 7983 years, you hopefully won't miss it. – m654 – 2016-05-14T16:31:15.097