从最少的输入获得最大的输出


16

显然,代码打高尔夫球就是要充分利用最少的代码。谁真正关心实际输出是多少?

尽管我们面临着最高输入输出的挑战,但这是在给定代码长度的情况下要求最有限和确定性输出的要求。具有讽刺意味的是,这个挑战不是

规则:

  1. 编写三个独立的片段(不是完整的程序/功能)。

  2. 片段必须使用相同的语言。

  3. 得分是输出字节的总数。

  4. 输出可以是结果,STDOUT等形式。

  5. 这些片段可能不会引起任何错误。

  6. 这些片段可能导致不同形式的输出。

  7. 尾随换行符不计算在内。

  8. 第一个代码段必须为1个字节或产生至少1个字节输出的最小长度。

  9. 第二个片段必须比该片段长一个字节。

  10. 第三段必须比第一个长两个字节。


5
是的,我认为输出必须限制为理论上的有限,您还应该指定输出应该是确定性的(除非我误解了,您实际上想要的是随机性……)
FryAmTheEggman 2015年

我们是否可以假设每个代码段都在新的REPL实例上运行?
SuperJedi224

@ SuperJedi224是的。
2015年

“不同形式的输出”中的“形式”是什么?
路易斯·门多

@LuisMendo例如,一个片段可能会弹出一个消息框,而另一个则打印到STDOUT。
2015年

Answers:


26

GS2,412 + 5.37×10 902 + 10个10 903.1字节

  1. f推送1\n2\nFizz\n4\nBuzz\n...\nFizzBuzz412-byte字符串。

  2. 打印所有排列,因此显示412! * 412字符。

  3. fôô打印该412!元素列表的所有排列,其中每个元素的长度为412个字符,因此为412 * (412!)!字节。

编辑:放眼看待,这至少是

101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

字节,到目前为止到目前为止,所有其他答案都相形见.。


9

Pyth,26 + 1140850688 +(> 4.37×10 20201781

我不知道是否有可能为第三个程序计算输出的确切长度。我只能给界限。它将在4.37 × 10^202017811.25 × 10^20201790字符之间打印一些内容。

G
yG
yyG

打印:

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

第一个打印字母,第二个打印字母的所有子集,第三个打印字母的子集的子集,这是length的列表2^(2^26) ~= 1.09 × 10^20201781

显然,没有计算机能够计算出这个大列表并将其输出。


1
如果我的计算正确,则应具有2 ^(2 ^ 26-1)*(2 ^ 25 * 26 + 2 ^ 26 * 4)+ 2 ^(2 ^ 26)* 2 = 6.239 * 10 ^ 20201789个字符。请注意,每个字符串出现的次数相同,因此大约只有上限的一半。
jimmy23013 2015年

1
如果@ jimmy23013和我的计算都正确,则 三个 数字的串联应等于第三个程序的输出长度。
LegionMammal978

6

CJam,17 + 34 + 72987060245299200000 = 72987060245299200051输出字节

为了便于比较,这大约是7.3 * 10 19

P
PP
Ke!

印刷品:

3.141592653589793
3.1415926535897933.141592653589793
012345678910111213141516171819012345678910111213141516171918012...

好吧,最后一个包含所有排列[0 1 2 ... 19]在一起的数字,并将它们压在一起。我不建议您尝试一下...(尝试一下就4e!可以品尝一下。)

在此处进行测试:程序1程序2程序3的Sane版本


4

果冻,1.2×10 2568字节的输出

ȷ
ȷ*
ȷ*!

计算10001000 10001000 1000!

在线试用:第一个程序 | 第二个程序 | 第三程序(修改)

为了字节计数,ȷ可以在当前版本的Jelly中将编码为字节0xa0 。

怎么运行的

在Jelly中,ȷ可以在数字文字内部用作Python的e(科学记法)。例如,3ȷ4返回30000。用Jelly的科学计数法,系数默认为1,指数默认为3,所以ȷ1ȷ3并且1000都返回相同的数字。

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

您有相当于APL的商品吗?
2015年

@NBZ是的。APL的等效范围ıR(范围)。ıȷ在Jelly中做一些完全无关的事情。我将在几分钟后添加解释。
丹尼斯

我对果冻的第一次尝试:会ȷRR产生多少输出?
2015年

@NBZ大约2.4兆字节。
丹尼斯

我看ȷRR⍳¨⍳1000。我想要⍳⍳1000。在Dyalog中,⍳⍳7得分91244,⍳⍳8得分803487,⍳⍳9得分7904816,因为它以1×2×3×4×...数组列出所有索引。因此从⍳⍳1000理论上讲(WS FULL!)会生成一个数组,每个数组包含1000个元素的!1000个列表!
2015年

4

六边形,1 + 3 + 6 = 10字节的输出

好吧……分数不是很高,但是至少我可以断言它是最佳的。仅有一个字节是不可能打印内容终止的,所以我们从两个字节开始:

!@

展开的代码是

 ! @
. . .
 . .

这将打印一个字节并终止。

对于三个字节的代码,我们可以输出三个字节的输出。例如:

o!@

或展开:

 o !
@ . .
 . .

版画111。从d到的任何小写字母都可以z工作并打印其字符代码。这些是用3个字节的代码打印3个字节的唯一23种方法。

最后,对于四个字节,有169种方法可以打印6个字节。由于除了简单的解决方案外,没有一个比直接解决方案更有趣(我将介绍):

o!!@

展开:

 o !
! @ .
 . .

你猜到了。它打印111111

我怎么知道这些是最佳的?我修改了为真相机器目录编写的蛮力搜索器,以寻找7000个周期内的最大有限输出(我认为您无法编写一个4字节的繁忙海狸,该海狸可以运行7000个周期,但仍会在以后终止。)


所以...说蛮力公开可用吗?我会对输出12345和停止的暴力破解程序感兴趣。。。只是出于好奇,您才了解。
quintopia,2015年

@quintopia在GitHub存储库中,但是很幸运用它找到一个8字节的程序。;)
Martin Ender 2015年

好吧,其中只有7个是未知的,您已经展示了它在寻找真机实现中搜索7字节解决方案的能力...
quintopia 2015年

4

认真地,2025409字节

1个字节:

N

(产生11,756字节的输出)

2个字节:

产生153,717字节的输出

3个字节:

9!!

产生1,859,936字节的输出

严重地还没有诸如“所有子集”或“所有组合”之类的功能,因此得分相对较低。


1
是什么N使它产生了如此多的输出?
geokavel

3
推送99瓶啤酒的歌词
quintopia 2015年

3

Python 3、1 + 22 + 23 = 56

9
id
abs

输出量

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

打印9,然后定义idabs


3

迷宫,1 + 2 + 4 = 7字节

另一个较低的分数,主要是因为我证明它是该语言的最佳选择,我主要在其中发布。

像六角形一样,迷宫不能打印并以单个字节结尾,因此我们以两个字节开头:

!@

打印零并终止。

对于三个字节,我们不能击败幼稚的解决方案:

!!@

这将在终止前打印两个字节。还有其他一些选项,例如-1使用(!@~!@或打印,!@。有一个很酷的解决方案,尽管它使用源代码轮换:

!>@

这将打印一个零,然后将源移动到@!>。在那一点上,它撞到了尽头,转身,然后!在返回的途中再次执行,然后终止。

对于四个字节,这会更有趣,因为打印4个字符的唯一方法是使用上述技巧:

!!>@

打印两个零,移至@!!>,再打印两个零。

在所有这些情况下,我都忽略了您也可以使用\或来打印一个字节.,因为这些将始终仅打印一个字节,而!将至少打印一个,甚至可能打印多个字节。


3

Bash,1726字节

(我现在已解决。请考虑投票。)

1个字节"

输出:

>

307个字节: id

输出:

uid=501(geokavel) gid=20(staff) groups=20(staff),701(com.apple.sharepoint.group.1),12(everyone),61(localaccounts),79(_appserverusr),80(admin),81(_appserveradm),98(_lpadmin),33(_appstore),100(_lpoperator),204(_developer),395(com.apple.access_ftp),398(com.apple.access_screensharing),399(com.apple.access_ssh)

1418个字节: zip打印到STDOUT)

版权所有(c)1990-2008 Info-ZIP-键入“ zip“ -L”'作为软件许可证。
邮编3.0(2008年7月5日)。用法:
zip [-选项] [-b路径] [-t mmddyyyyy] [-n后缀] [zip文件列表] [-xi列表]
  默认操作是从列表添加或替换zipfile条目,其中
  可以包含特殊名称-压缩标准输入。
  如果省略zipfile和list,则zip将stdin压缩为stdout。
  -f更新:仅更改文件-u更新:仅更改或新文件
  -d删除zipfile中的条目-m移入zipfile(删除OS文件)
  -r递归到目录-j垃圾(不记录)目录名
  -0仅存储-l将LF转换为CR LF(-ll CR LF转换为LF)
  -1压缩更快-9压缩更好
  -q安静操作-v详细操作/打印版本信息
  -c添加单行注释-z添加zipfile注释
  -@从stdin读取名称-o使zipfile与最新条目一样旧
  -x排除以下名称-i仅包括以下名称
  -F修复zipfile(-FF更加努力)-D不添加目录项
  -A调整自解压exe -J垃圾zipfile前缀(unzipsfx)
  -T测试zip文件的完整性-X排除eXtra文件的属性
  -y将符号链接存储为链接而不是引用文件
  -e加密-n不要压缩这些后缀
  -h2显示更多帮助

让我知道您的想法是错的。只要您不等待太久,它实际上总是会打印相同的内容。最后的千字节数证明了这一点。
geokavel 2015年

这样做有两个问题:1.第一个命令根本不产生任何输出,因为STDERR不是公认的输出方法。2. du的输出取决于当前文件夹中的文件/目录,因此这根本不是自包含的或可复制的。
丹尼斯

@Dennis您如何知道第一个是STDERR(如果只是打印用途)?好的,现在我看看第二个规则如何违反
geokavel 2015年

2
这需要拉链。bash不包含Zip。
noɥʇʎԀʎzɐɹƆ

1
@CrazyPython我可以根据需要更改标题,以使用通用实用工具进行重击或在Mac OS X上使用默认重击。
geokavel

2

马耳他 313

使用当前版本的语言(3.1.0),它比此挑战要早。

  1. 代码(预定义文字:产生数字2,该数字被隐式打印):

    H
    

    输出(1个字节):

    2
    
  2. 代码(产生数字pi,用15个小数点隐式打印):

    YP
    

    输出(17个字节):

    3.141592653589793
    
  3. 代码(从1到99的数字,默认情况下打印,中间带有空格):

     99:
    

    输出(295字节):

    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
    

2

处理中,39个字节

确定性

1个字节

print(X);

产出 0

9个字节

print(PI);

产出 3.1415927

29个字节

print(P3D);

产出 processing.opengl.PGraphics3D

非确定性,> = 129字节

> = 32个字节:

print(g);

产出 processing.awt.PGraphicsJava2D@ + [mem-address]

> = 32个字节:

print( g);

产出 processing.awt.PGraphicsJava2D@ + [mem-address]

> = 65字节:(谢谢@anOKsquirrel的建议。)

print(g,g);

产出

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

在第二部分中,您可以使用1,g或g,g之类的东西吗?甚至g + g?
anOKsquirrel

2

JavaScript,1 + 3 + 18 = 18 22

这不是一个非常有趣的答案,但可能是最好的JavaScript所能提供的。

alert(1)
alert(.1)
alert(1/9)

由于@UndefinedFunction增加了4分!

输出为文本:

1
0.1
0.1111111111111111

如果只写alert(),则输出undefined(至少在Safari中)。
geokavel 2015年

@geokavel真的吗?在Chrome中,它仅显示一个空警报。我还没有检查Firefox。在Safari中,得分会更低。:s
user81655

alert(.1)给出0.1,并且alert(1/9)给出0.1111111111111111
jrich

@UndefinedFunction不错的提示,谢谢!
user81655

写作alert给了我function alert() { [native code] }
ev3commander's

2

Befunge,2 + 4 + 6 = 12

.@
..@
...@

少于长度2的任何代码段要么无法输出,要么无法终止其输出。

在Befunge中,.将堆栈的最高值输出为整数,后跟一个空格。空格不是换行符,因此它包含在计数中。此外,堆栈被“无限”填充为0,因此程序分别输出:

0 
0 0 
0 0 0 

1
..<@打印8个字节。
jimmy23013 '19

2

SmileBASIC,1 + 4 + 10 = 15个字节

程序1:

最简单的打印方法是?(PRINT)和一个字符。这可以是数字,也可以是变量名,这没关系,因为它们的长度都相同。

?1
1

程式2:

现在,我们可以访问更多内容。可以做的最长的表达式是常数#Y,#L或#R之一,它们的值分别为128、256和512。但是,相反,我使用逗号,以便(在这种情况下)打印3个额外的空格。

?1,
1   

程式3:

您可以使用3个字符来写电子注释数字:

?1E9
1000000000

2

HQ9 +,71304

9

打印“ 99瓶啤酒”的11884个字符的歌词

99

两次印刷“ 99瓶啤酒”

999

印刷三遍“ 99瓶啤酒”


2

Japt -Q输出1.0123378918474279e+150字节

完整的号码是

1,012,337,891,847,427,807,734,770,805,740,683,255,348,979,141,331,502,541,182,800,555,980,960,810,784,280,906,237,433,006,787,771,597,919,201,659,212,694,207,520,340,705,280,000,000,000,000,000,000,568

个字节。

#1

M

产出

{"P":3.141592653589793,"Q":1.618033988749895,"T":6.283185307179586}

为67个字节。(贷给毛茸茸的)

#2

产出

[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]

这是501个字节。

(贷方为@Shaggy)

#3

;Eá

输出格式为的95个可打印ASCII字符的所有排列["...","...","..."...],即

1,012,337,891,847,427,807,734,770,805,740,683,255,348,979,141,331,502,541,182,800,555,980,960,810,784,280,906,237,433,006,787,771,597,919,201,659,212,694,207,520,340,705,280,000,000,000,000,000,000,001 bytes of output.


You can get an infinite amount of output bytes if you use the -F flag in Japt. What it does is that if the last expression of the program evaluates to false, it outputs the value specified in the flag instead. So I guess the score for Japt-F"Insert Super Long String Here" is infinity.


You can get 501 bytes out of the second one.
Shaggy

And 4 bytes or a risky 8 out of the first.
Shaggy

A-ha! I knew there was a way to get undefined in 1 byte: $.
Shaggy

@Shaggy Or I could use K and get 26 bytes of output, but your 501 byter is just genius
Embodiment of Ignorance

Does output not have to be deterministic?
Shaggy

2

Malbolge, 1 + 2 + 3 = 6 bytes

(=aN
(&a`M
(=a`_L

Try it online: first, second, third

Outputs:

r
ll
xxx

Brute forced. Assumes \0 is not a valid output character

With \0:

cP
cbO
cbaN

Outputs:

\0
\0\0
\0\0\0

1

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)


1

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

1

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.


1

Javascript, 72 bytes

This works in the Mozilla JSShell Javascript command line interpreter.

1 byte: 1

Outputs 1

35 bytes: gc

Outputs

function gc() {
    [native code]
}

36 bytes: run

Outputs

function run() {
    [native code]
}

So...Node.js?..
CalculatorFeline

@CalculatorFeline I'm not familiar with Node.js, but on my Mac if you type in js on the command line, you get a JavaScript shell.
geokavel

-bash: js: command not found Please specify more.
CalculatorFeline

@CalculatorFeline I'm getting the same message. Maybe they took out js in the latest version of Bash.
geokavel

gc doesn't seem to exist in TIO Node, so please find an implementation or remove this answer.
CalculatorFeline

1

Octave, 2818417 bytes

e

14 bytes for ans = 2.7183\n

pi

14 bytes for ans = 3.1416\n

doc

Display the entire documentation. 2818389 bytes, counted with dd Try it online! because evalc didn't work.


1

SmileBASIC 4, 1 + 13 + 15 = 29 bytes

This is going to be similar to 12Me21's SmileBASIC 3 answer, with a couple adjustments.

1

As before, the shortest amount of code to produce some output is 2 bytes: ? (PRINT) and some single-byte expression. The consensus is that PRINT does not produce a newline when it advances to the next line, due to the way the text screen works. So this results in one byte of output.

?1
1

2

With 3 bytes, we can do something different. SB4 introduces INSPECT, aliased as ??, which prints info about a single value. If we give it an empty string, for example, this can produce much more output than SB3 could. This gets us 13 bytes.

??"
STRING: (0)""

3

We have 4 bytes to work with, so we have to decide what we should do to maximize our output. Going with ?? is a safe bet; we only have 2 bytes to use on our expression, but the additional output of INSPECT is basically free. So I use it to print a label string. This is 15 bytes.

??@A
STRING: (2)"@A"

The total is 29 bytes.


0

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.


Is this deterministic? If I understand you right, it contains varying digits...
Adám

@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

Maybe leave it as-is, but provide an alternate answer that is truly deterministic?
Adám

0

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

"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?
Adám

1
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.
AdmBorkBork

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.
Adám

1
@NBZ True. I would certainly hope that almost every program is deterministic. Are you intending "immutable" perhaps?
AdmBorkBork

0

Javascript, 312 + 318 + 624 = 1254 bytes of output

$
$$
$+$

The two functions $ and $$ are available in all major browsers' consoles, as shortcuts for document.querySelector and document.querySelectorAll respectively. Different browsers have native code coerced to strings somewhat differently from each other, and IE uses plain JS in each function resulting in much longer representation.

For the byte count, I'm taking the length of the string representation of each rather than the sometimes-modified console display, so the total bytes are, for each of the following browsers:

  • Chrome: 56 + 57 + 112 = 225 bytes
  • IE: 312 + 318 + 624 = 1254
  • Firefox: 33 + 33 + 66 = 132

(I'm considering the IE result to be the "official" count because it's the longest.)

For non-console browser environments, the largest outputs come from the following:

1
!1 // Or '{}' if being fed to a function instead of beginning a statement
Map

Results length by browser:

  • Chrome: 1 + 5 (or 15 if {} is usable) + 32 = 38 (or 48) bytes
  • IE: 1 + 5 (or 15 if {} is usable) + 38 = 44 (or 54)
  • Firefox: 1 + 5 (or 15 if {} is usable) + 36 = 42 (or 52)

These two sets of input produce the largest output possible in all of these browsers and consoles. To prove this, let's check all alternatives:

  • Existing variables: We can find all native available variables with maximum three characters with Object.getOwnPropertyNames(window).filter(x=>x.length<=3), and then map them to their string outputs to determine the larger ones. (Note that in some browsers such as Firefox, certain special console variables cannot be accessed this way as they're not a property of the window.)
  • JS has a limited number of types of literals that can be created with so few characters:
    • Per the spec, decimal numbers must be a decimal digit (1234567890) optionally followed by . and more decimal digits and/or an exponent part, or be a . followed by one or more decimal digits and optionally an exponent part. Other kinds of numbers must be either 0o, 0x, or 0b (or uppercase forms), followed by one or more digits. For our purposes, we can deduce the following:
      • There are only ten single-character numbers, which are the integers 0 through 9. The only two-character numbers are integers 0-99 (0-9 by adding a decimal after), and the numbers 0.1 through 0.9 by omitting the initial zero. The only three-character numbers are 0-999, including 0x0-0xf, 0o0-0o7, 0b0, and 0b1, the exponential 1e1 through 9e9 (10 characters), and the numbers 0.1-9.9 and .01 through .99. While not technically a number literal, NaN can also be referenced in three characters.
    • Strings, arrays, and regexps, each of which can take at max only a single character of content. An array could be filled with $, a comma, or a single-digit number. Arrays with only one element are coerced to strings as the element itself. Empty arrays become empty strings.
    • Depending on environment, it may or may not be possible to create simple objects with three characters. Normally, {} alone at the beginning of a script would be treated as an enclosure rather than creating an object. eval({}) returns undefined, eval({$}) returns the $ function. There are insufficient characters to surround the {} in ().
  • There are no keywords that are short enough to use. The keywords if, in, do, new, for, try, var, and let would all require a minimum of two other characters to use, exceeding the limit.
  • Available unary operators include ~, +, -, !, ++, and --. The two-character operators can only be used with a single character variable, of which there is only one ($), which yields NaN. The other four operators can be used with any one- or two- character value, of which there are:
    • Several variables. (On some consoles $, $_, $0, $1, $2, $3, $4, $, $$, $x ). When used with these operators, the results are limited to -1, true, false, and NaN.
    • 109 numbers. Results: Integers -100 through 99, -0.9 through -0.1, true, false.
    • Empty strings. Results: -1, 0 (-0 becomes 0 on toString), true.
    • The results of any of the one-character values above associated with a one-character unary operator. New results: None.
  • Usable binary operators (which must be a single character to have room left for both operands) are +, -, *, /, %, <, >, &, |, ^. They can only be used with a single-character value on each side. Options for values include $ and integers 0-9. Results of all combinations of these include Infinity, some numbers and binary values mentioned above, and numerous fractions which are coerced to strings of 19 characters or less (1/7 is 19 characters, unlike 1/9 suggested above which is only 18), and the text representation of $ preceded or followed by a single-digit integer or itself.
  • Finally, all remaining operators and expressions: The member operator . requires an existing variable and a identifier referring to a property. All uses of this here result in undefined. Surrounding a value in ( ) returns the value, as does assigning it with =. Using () or `` to call a value as a function results in undefined or errors with all available values.

Adding all this up, there are a grand total of 1651 possible outputs when using a Chrome console. The longest outputs for one, two, and three characters are from $, $$, and $+$ respectively.


0

dc, 2+5+18=25 bytes

1: Ff yields (Try it online!):

15

2: Fdf yields (Try it online!):

15
15

3: Fd^f yields (Try it online!)

437893890380859375

None of which are particularly interesting, but dc isn't really great for spitting out piles of output. I do like that each answer builds on the previous. Anyway, F is just the number 15; f prints the entire stack; d duplicates top-of-stack; ^ raises next-to-top-of-stack to the power of top-of-stack (in this case, 15^15). I don't believe this can be topped in dc.


0

Ruby, 3+14+28 = 45 bytes

Why did I do this.

p

Prints nil.

$>

Prints #<IO:<STDOUT>>.

dup

Prints something along the lines of #<Object:0x0000000003610988>.

irb

Launches an instance of Interactive Ruby. Upon exiting, the returned object is #<IRB::Irb: @context=#<IRB::Context:0x0000000003643040>, @signal_status=:IN_EVAL, @scanner=#<RubyLex:0x00000000038900a0>> for 121, but since it requires you to press ^D or something to actually exit the irb instance, I wasn't sure if it'd actually count as a solution in "3 bytes" so I'm not actually including it in the score unless it gets an OK.


0

Perl 6, 53 (17 + 18 + 18) bytes

e
-e
e*e
  1. e outputs e to 15 decimal places
  2. -e outputs e to 15 decimal places
  3. e*e outputs e2, but oddly, it gives one more decimal place

0

Runic Enchantments, 4,000,000 bytes of output

The first program is:

a@

Takes 2 bytes to: push a value to the stack, print a value from the stack, and terminate. In this case it prints 10 (though any integer value from 0 to 16 are also just as valid)

For 3 bytes:

aY@

Prints 10000, Again, a could be 1 through 16 inclusive (in order to generate more output than the original program, 0 is potentially valid under other operators) and there aren't a whole lot of operators that take a single input and produce any output, much less longer output. XCYZ:E are the only real options. aY@ is just the one that results in the most output.

P$!;

According to language specification, this runs infinitely. However as the interpreter has a built in "ok, that's enough" maximum execution limit, this is the most output achievable in 4 characters (and TIO cuts off execution after ~130,000 bytes for exceeding 128kib) and as the interpreter defines the language, this works. And while I have raised that threshold once before (from 10k steps to 1 million), I don't plan on messing with it any time soon.

Bigger?

If I invoke the three assumptions I made here, then sure.

`AA@

Which works out to Ack(65,Ack(65,64)), which aren't terribly large values to go shoving into the Ackerman function initially--certainly smaller than the 255 in the older post--but its ok, we can call Ack twice in 4 instructions.

And only god knows what it'll print.

Note: the A instruction has since then been made the Math meta-instruction, which consumes 3 objects on the stack: a char for what instruction to perform and then two inputs, x and y. As such this program doesn't actually do anything, both because neither A nor @ map to a math function and because two subsequent calls results in a stack underflow.

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.