Sign up ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Obviously, code golfing is all about making the most of the least code. Who really cares what the actual output is?

While we have had a challenge for highest input-to-output ratio, this is a call for most finite and deterministic output with given code lengths. Ironically, this challenge is then not .

Rules:

  1. Write three independent snippets (not full programs/functions).

  2. The snippets must be in the same language.

  3. Score is total number of outputted bytes.

  4. Outputs may be in the form of a result, STDOUT, etc.

  5. The snippets may not cause any error.

  6. The snippets may cause different forms of output.

  7. Trailing newline characters are not counted.

  8. The first snippet must be 1 byte or the minimum length that produces at least 1 byte of output.

  9. The second snippet must be one byte longer than that.

  10. The third snippet must be two bytes longer than the first.

share|improve this question
3  
Yeah I think the output needs to be restricted to be theoretically finite, you should also probably specify that it should be deterministic (unless I misunderstood and randomness is something you would actually want...) – FryAmTheEggman yesterday
    
Are we allowed to assume that each snippet is run on a fresh REPL instance? – SuperJedi224 yesterday
    
@SuperJedi224 Yes. – NBZ yesterday
    
What's "form" in "different forms of output"? – Luis Mendo yesterday
    
@LuisMendo E.g. one snippet may pop up a message box, while another prints to STDOUT. – NBZ yesterday

17 Answers 17

Pyth, 26 + 1140850688 + (>4.37 × 1020201781)

I have no idea if it is possible to calculate the exact length of the output for the third program. I can only give boundaries. It'll print something between 4.37 × 10^20201781 and 1.25 × 10^20201790 characters.

G
yG
yyG

This prints:

abcdefghijklmnopqrstuvwxyz
['', 'a', 'b', ..., 'abcdefghijklmnopqrstuvwxyz']
[[], [''], ['a'], ['b'], ['c'], ..., ['', 'a', 'b', ..., 'abcdefghijklmnopqrstuvwxyz']]

The first one prints the alphabet, the second one all subsets of the alphabet, and the third one the subsets of the subsets of the alphabet, which is a list of length 2^(2^26) ~= 1.09 × 10^20201781.

Obviously no computer ever will be able to compute this large list and output it.

share|improve this answer
    
If my calculation is correct it should have 2^(2^26-1) * (2^25*26 + 2^26*4) + 2^(2^26)*2 = 6.239 * 10^20201789 characters. Note that each string appeared the same number of times, so it's just about half of your upper bound. – jimmy23013 yesterday
    
If both @jimmy23013's and my calculations are correct, the concatenation of these three numbers should be equal to the output length of the third program. – LegionMammal978 yesterday

CJam, 17 + 34 + 72987060245299200000 = 72987060245299200051 bytes of output

For easier comparison, this is approximately 7.3 * 1019.

P
PP
Ke!

Prints:

3.141592653589793
3.1415926535897933.141592653589793
012345678910111213141516171819012345678910111213141516171918012...

Well, the last one consists of all permutations of [0 1 2 ... 19] with the numbers squished together. I wouldn't recommend trying it out... (Try it as 4e! though to get a taste.)

Test it here: Program 1, Program 2, Sane version of program 3.

share|improve this answer

Jelly, 1.2 × 102568 bytes of output

ȷ
ȷ*
ȷ*!

Calculates 1000, 10001000 and 10001000!.

Try it online: first program | second program | third program (modified)

For byte counting purposes, ȷ can be encoded as the byte 0xa0 in the current version of Jelly.

How it works

In Jelly, ȷ can be used inside number literals as Python's e (scientific notation). For example, 3ȷ4 returns 30000. In Jelly's scientific notation, the coefficient defaults to 1 and the exponent defaults to 3, so ȷ, 1ȷ3 and 1000 all return the same number.

ȷ      Return 1000.
ȷ      Return 1000.
       Parse the remaining code as a program with input 1000.
 *     Hook; compute 1000 ** 1000.
ȷ      Return 1000.
       Parse the remaining code as a program with input 1000.
  !    Return 1000!.
 *     Fork; compute 1000 ** 1000!.
share|improve this answer
    
Do you have an equivalent of APL's ? – NBZ yesterday
    
@NBZ Yes. The equivalent of APL's ı is R (range). ı and ȷ do something entirely unrelated in Jelly. I'll add an explanation in a few minutes. – Dennis yesterday
    
My first attempt at Jelly: How much output does ȷRR cause? – NBZ yesterday
    
@NBZ Roughly 2.4 megabytes. – Dennis yesterday
    
I see ȷRR is ⍳¨⍳1000. I wanted ⍳⍳1000. In Dyalog, ⍳⍳7 scores 91244, ⍳⍳8 scores 803487, ⍳⍳9 scores 7904816, because it lists all the indices in a 1×2×3×4×... array. So ⍳⍳1000 would theoretically (WS FULL!) generate an array of !1000 lists of 1000 elements each! – NBZ yesterday

gs2, 412 + 5.37 * 10902 + 1010903.1 bytes

  1. f pushes 1\n2\nFizz\n4\nBuzz\n...\nFizzBuzz as a 412-byte string.

  2. prints all of its permutations, so 412! * 412 characters.

  3. fôô prints all permutations of that 412!-element list, where each element is 412 characters long, so 412 * (412!)! bytes.

share|improve this answer

MATL, 313

The current version of the language (3.1.0) is used, which is earlier than this challenge.

  1. Code (predefined literal: produces number 2, which is implicitly printed):

    H
    

    Output (1 byte):

    2
    
  2. Code (produces number pi, which is implicitly printed with 15 decimals):

    YP
    

    Output (17 bytes):

    3.141592653589793
    
  3. Code (numbers from 1 to 99, which are printed by default with spaces in between):

     99:
    

    Output (295 bytes):

    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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    
share|improve this answer

Python 3, 1 + 22 + 23 = 56

9
id
abs

Output

9
<built-in function id>
<built-in function abs>

Print 9 and then the definition for id and abs.

share|improve this answer

Hexagony, 1 + 3 + 6 = 10 bytes of output

Well... not a very impressive score, but at least I can assert that it's optimal. With a single bytes it's impossible to print something and terminate, so we start with two bytes:

!@

The unfolded code is

 ! @
. . .
 . .

This prints a byte and terminates.

For three bytes of code, we can print three bytes of output. For instance:

o!@

or unfolded:

 o !
@ . .
 . .

prints 111. Any lower-case letter from d to z works and prints its character code. Those are the only 23 ways to print 3 bytes with 3 bytes of code.

Finally, for four bytes, there are 169 ways to print 6 bytes. Since none of them do anything more interesting (except for odd control flow) than the straight-forward solution, I'll present that:

o!!@

Unfolded:

 o !
! @ .
 . .

You guessed it. It prints 111111.

How do I know these are optimal? I adapted the brute forcer I wrote for the truth machine catalogue to look for maximum finite output in 7000 cycles (I don't think you can write a busy beaver with 4 bytes, that runs for 7000 cycles but still terminates later.)

share|improve this answer

Labyrinth, 1 + 2 + 4 = 7 bytes

Another low score, which I'm mainly posting because I've proven it to be optimal for the language.

Like Hexagony, Labyrinth can't print and terminate with a single byte, so we start with two bytes:

!@

Prints a zero and terminates.

For three bytes, we can't beat the naive solution:

!!@

This prints two bytes before terminating. There are a few other options, like printing -1 with (!@ or ~!@ or ,!@. There is one pretty cool solution though which uses source code rotation:

!>@

This prints a zero, then shifts the source to become @!>. At that point it hits a dead end, turns around, and executes the ! again on the way back, before terminating.

For four bytes, it's a bit more fun, because the only way to print 4 characters is to use the above trick:

!!>@

Print two zeroes, shift to @!!>, print another two zeroes.

In all of these cases I'm ignoring that you can also print a byte with \ or ., because those will always print exactly one byte, whereas ! will print at least one and potentially several.

share|improve this answer

Microscript II, 23+47+71=141 bytes

1: C

The stringification of continuations is not strictly defined by the specs, but in the reference implementation this, run on its own, yields a 23 byte string.

<Continuation @t=\d\d\dus> (\d represents a digit, which digits varies).

On my computer, at least, this does, in fact, always take between about 180 and about 400 microseconds to run.

The first use I've ever actually had for this instruction.

2: CP

47 bytes of output- the output from the first one twice with a newline in between.

3: CPP

Fairly straightforward. 71 bytes of output- the output from the first one three times with newlines in between.

share|improve this answer
    
Is this deterministic? If I understand you right, it contains varying digits... – NBZ yesterday
    
@NBZ It does not produce the exact same strings every time, but it has produced strings of the same length every time I've tested it so far. – SuperJedi224 yesterday
    
Maybe leave it as-is, but provide an alternate answer that is truly deterministic? – NBZ yesterday

PowerShell, ~4300 bytes

Approximate output length, given the system that it's run on. All the snippets below are deterministic, in that if given the same initial state of the computer will output the same text, just that in practice the output could change from execution to execution.

Length 1, 107 bytes

?

This is an alias for Where-Object. It will output a user prompt asking for additional information:

cmdlet Where-Object at command pipeline position 1
Supply values for the following parameters:
Property: 

Length 2, 113 bytes

rp

This is an alias for Remove-ItemProperty. It will output a user prompt asking for additional information:

cmdlet Remove-ItemProperty at command pipeline position 1
Supply values for the following parameters:
Path[0]: 

Just barely longer than the length 1 snippet.

Length 3, ~4100 bytes

gps

This is an alias for Get-Process which will output a formatted table of all running processes on the system:

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName                                                                                          
-------  ------    -----      ----- -----   ------     -- -----------                                                                                
     85       8     1232       4452    46     0.14    544 armsvc                                                                                               
    151      10     6800       9888    39     0.58   5116 audiodg                                                                                              
    480      25     6060      17200   124     0.84   4536 AuthManSvr            
...
share|improve this answer
    
"output could change" - that's an understatement. In praxis, it would be impossible to reset the machine to the same state. Maybe a more deterministic alternative to the third? – NBZ yesterday
    
Impracticality does not preclude determinism ... Unless you're meaning a different definition of "deterministic," in which case you should explicitly state so in the challenge. – TimmyD yesterday
    
According to you, almost every program is deterministic, given the exact same machine state. The only exception would be equipment with true RNGs, e.g. based on microphone noise or camera input. – NBZ yesterday
    
@NBZ True. I would certainly hope that almost every program is deterministic. Are you intending "immutable" perhaps? – TimmyD yesterday

JavaScript, 1 + 2 + 15 = 18

Not a very interesting answer but probably the best JavaScript is capable of.

alert(1)
alert(12)
alert(top)

Outputs as text:

1
12
[object Window]
share|improve this answer
    
If you just write alert() you get output of undefined (at least in Safari). – geokavel 22 hours ago
    
@geokavel Oh really? In Chrome it just shows an empty alert. I haven't checked Firefox. In Safari the score would be even less. :s – user81655 22 hours ago

scg, 1 + 27 + 188 = 216

First one:

1

Just prints 1, as the stack is outputted at the end of program.

Second:

.d

Prints debug info, which should look like this:

Stack: []
Array Markers: []

Third:

99r

adds 99 to stack, then uses range function. Outputs 01234567891011.... (this is one of those times I wish I implemented the factorial function. I haven't)

share|improve this answer

Marbelous 1 + 1 + 2 = 4 bytes of output

Marbelous is hamstrung here by having two-byte instructions. Pointless comments or unnecessary whitespace are the only ways to get an odd byte count.

print "A" and terminate:

`A

print "B" and terminate, with an empty EOL comment

`B#

print "CD" and terminate:

`C`D
share|improve this answer
    
@LegionMammal978 fixed – Sparr yesterday

Processing, 39 bytes

Deterministic

1 byte:

print(X);

Outputs 0.

9 bytes:

print(PI);

Outputs 3.1415927

29 bytes:

print(P3D);

Outputs processing.opengl.PGraphics3D

Non-deterministic, >= 129 bytes

>= 32 bytes:

print(g);

Outputs processing.awt.PGraphicsJava2D@ + [mem-address]

>= 32 bytes:

print( g);

Outputs processing.awt.PGraphicsJava2D@ + [mem-address]

>= 65 bytes: (Thank you to @anOKsquirrel for this suggestion.)

print(g,g);

Outputs

processing.awt.PGraphicsJava2D@ + [mem-address]
processing.awt.PGraphicsJava2D@ + [mem-address]
share|improve this answer
    
in the second section could you have used something like 1,g or g,g? or even g+g? – anOKsquirrel yesterday

Javascript, 72 bytes

This works in the command-line version of Javascript

1 byte: 1

Outputs 1

35 bytes: gc

Outputs

function gc() {
    [native code]
}

36 bytes: run

Outputs

function run() {
    [native code]
}
share|improve this answer

Mathematica, 6 + 461 + 763 = 1230 1225 618 163 bytes of output

%  (* -> Out[0] *)

?D  (* ->

D[f, x] gives the partial derivative ∂ f/∂ x. 
                                              n        n
D[f, {x, n}] gives the multiple derivative ∂  f/∂ x . 
D[f, x, y, …] differentiates f successively with respect to x, y, ….
D[f, {{x , x , …}}] for a scalar f
        1   2
     gives the vector derivative (∂ f/∂ x , ∂ f/∂ x , …). 
                                             1             2
D[f, {array}] gives a tensor derivative.

*)

?Do (* ->

Do[expr, {i   }] evaluates expr i    times. 
           max                   max
Do[expr, {i, i   }] evaluates expr with the variable i successively taking on the values 1 through i    (in steps of 1). 
              max                                                                                   max
Do[expr, {i, i   , i   }] starts with i = i   . 
              min   max                    min
Do[expr, {i, i   , i   , di}] uses steps di. 
              min   max
Do[expr, {i, {i , i , …}}] uses the successive values i , i , ….
               1   2                                     1   2
Do[expr, {i, i   , i   }, {j, j   , j   }, …] evaluates expr looping over different values of j, etc. for each i. 
              min   max        min   max

*)

Currently, the last two use Information to get documentation about the symbols, which can output many bytes. Note that this was run on the 10.1 command-line MathKernel.

share|improve this answer

Bash, 1875471 bytes

69 bytes: .

Outputs:

-bash: .: filename argument required
.: usage: . filename [arguments]

937701 bytes: du

Outputs:

2519064 ./.android/avd/Processing-0242.avd
2519072 ./.android/avd
1104    ./.android/cache
....

It outputs the disk usage of every folder on your computer. As long as you don't change any files the output is always the same.

937701 bytes: du

(Same thing with a space at the end.)

share|improve this answer
    
Let me know what you think is wrong with it. As long as you don't wait too long, it really does always print the same thing. The kilobyte count at the end proves it. – geokavel 12 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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