生成打印长度为n倍的程序


16

给定一个非负整数n,您的解决方案必须以您选择的语言输出一个程序,该程序的输出n字节数与输出程序的字节数相同。

规则

  • 您必须指定解决方案输出的程序的语言和编码,并且不得为解决方案的不同输入选择不同的语言或编码。输出程序的语言可能与解决方案的语言相同,也可能不同。
  • 您提交的内容仅需要处理您语言范围内的整数,但请勿滥用此规则。

这是因此以字节为单位的最短提交会获胜。

假设n是4。然后f_8,我的解决方案输出了一个程序,该程序以我的(虚构的)语言输出j3 1s+/2]!mz。程序输出的长度为3,其输出的长度为3 * 4 = 12,因此该解决方案对于输入4是正确的。

假设它n是1,我的程序输出ffffpfpffp(10个字节)。ffffpfpffp用我选择的语言编写的程序必须产生10 * 1 = 10字节的输出。


目前,这还为数不多。你能提供一些例子吗?
DJMcMayhem

3
我知道我们应该怎么做,但是每次阅读规范时,我就变得不太确定。输出一些文本,该文本的字节数是输出程序的n倍,这似乎意味着我们必须输出文本和程序。所有整数的字符集和语言必须一致。这是指哪个“字符集”?
丹尼斯

没关系,我实际上确实误会了,除了答案之一之外,其他人也都误会了。
丹尼斯

1
@Dennis标题似乎与身体矛盾没有帮助。如果我正确地理解了挑战,那么输出一个输出长度其长度的n倍的程序也许是一个更好的标题(不确定)
Sisyphus

1
我们可以n当作字符串吗?
毛茸茸的

Answers:


7

JavaScript(ES6),38个字节

n=>`(x="${n}")=>(x+1/7+1e9).repeat(x)`

演示版



3

brainfuck,348个字节

--[>+<++++++]>>--[>+<++++++]>++[-<+>]----[>+<----]>---[-<+>]----[>+<----]>-[-<+>]-[>+<---]>++++++[-<+>]-[>+<---]>++++++++[-<+>]--[>+<++++++]>+++[-<+>]<[<],[->.<]>>>>>.<<<.>>.<<<.>>>.<<<.>>>.<<<.>>...>>>.<<....<<.>>>.<<..<<.>>>..<<.......>>>>.<<<..<<.>.....>>>.<<.>>.>>.<<<<<.>>>>.<<.<<.>>.>.<<<.>>.<<<.>>...<<.>>>..>>.<<.>.<<<.>.<<.>>>.>>.<<<..>>>.

在线尝试!或查看Ungolfed版本(即我必须使用的版本)


免责声明

我花了更多的时间进行此操作,这超出了我的想象。我要感谢我的女友让我抛弃她去做这件事。以及我的救世主

它甚至如何工作?

没有线索。

如何运作?

所有输出的尾随代码段都相同:

[->+>+>+<<<]>>>>-[<<+>>-------]<<+-----[<[.-]>->[->+<<<+>>]>[-<+>]<<]

让我们将其分为三个部分 a,b,c

a : [->+>+>+<<<]>>>>               THE DUPLICATOR
b : -[<<+>>-------]<<+-----        THE ADJUSTER
c : [<[.-]>->[->+<<<+>>]>[-<+>]<<] THE PRINTER

输入i简单地以一元形式添加到前端:

iabc

(例如,如果输入为10,则i = '++++++++++'

复制器 -将输入分为两个相同的数字m, n,等效于输入

调节器 -进行调节n,使其等于程序的长度

打印机 -打印m*nASCII字符


请注意,示例中的输入为a newline,其ASCII值为10,因此输入为10。如果要测试其他较小的数字,请,用任意多个替换+



2

Haskell,55个字节

f n=(++)<*>show$"main=putStr$[1.."++show n++"*2]>>'#':"

在线尝试!用法示例:f 1产生以下54个字节的程序:

main=putStr$[1..1*2]>>'#':"main=putStr$[1..1*2]>>'#':"

在线尝试! 产生以下54个字节的输出:

#main=putStr$[1..1*2]>>'#':#main=putStr$[1..1*2]>>'#':

1

Python 3- > HQ9 +,11个字节

'Q'.__mul__

这必须要完成

在线尝试!


在哪里可以测试总部?
泰特斯

1
好吧,Q只打印自己的源代码。您可以在此处进行测试:hq9plus.alwaysdata.net。从来没有想过这是一个严肃的词条
michi7x7

这行不通。如果我输入1,则输出Q,然后输出QQ有长度1,但是您的代码有长度11
NoOneIsHere17年

@NoOneIsHere'其输出的字节数是输出程序的n倍。(不是提交的程序)
michi7x7 '17

1
@NoOneIsHere这不是:almnet.de/esolang/hq9plus.php(语言规范仅声明“打印源代码文件的整个文本”)
michi7x7

1

Java的8,175个 174字节

interface M{static void main(String[]a){System.out.printf("interface M{static void main(String[]a){int i=(88+%s)*%s;for(;i-->0;System.out.print(0));}}",a[0].length(),a[0]);}}

例子:

n=1输出

interface M{static void main(String[]a){int i=(88+1)*1;for(;i-->0;System.out.print(0));}}

(length = 89)输出89个零

00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

n=10输出

interface M{static void main(String[]a){int i=(88+2)*10;for(;i-->0;System.out.print(0));}}

(length = 90)输出900个零

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

n=100输出

interface M{static void main(String[]a){int i=(88+3)*100;for(;i-->0;System.out.print(0));}}

(length = 91)输出9100个零

0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

说明:

interface M{                                // Class:
  static void main(String[]a){              //  Mandatory main method
    System.out.printf("interface M{static void main(String[]a){
                                            //   Print a new program with:
      int i=(88+%s)*%s;                     //    Integer containing (88*A)+B
      for(;i-->0;System.out.print(0));}}",  //    And print that many zeroes
        a[0].length(),                      //     Where A is the length of the number
                                            //     (0-9 = 1; 10-99 = 2; 100-999 = 3; etc.)
        a[0]);}}                            //     and B is the number itself

0

RProgN 27 5个字节

«•.* 

尾随空间

解释

«•.* 
«    # Yield a function from the remaining string.
 •.  # Append a space and stringify, which builds the original program (Because stringifying a function removes noops, which spaces are)
   * # Repeat the implicit input times.

在线尝试!


0

CJam,8个 13字节

q_,S\" 8+*S*"

在线尝试

生成的程序输出空格,因此很难分辨。


我认为这是解释有关正确输出文本的程序输出部分的唯一答案,但是如果输入的位数超过一位,则该比率关闭。
丹尼斯

哦,是的,
geokavel'8

0

Ly,29个字节

"\"9>("&onu")[<&s&ol>1-]<;"&o

在线尝试! (由于存在预处理错误,目前无法正常工作)一切正常!


0

Python→TECO,20个字节

答案是使用Python,而生成的代码是使用TECO。Python是VV12345\VV重复返回n次的函数。有关TECO的说明,请参见此处

'VV12345\VV'.__mul__

0

PHP,47 + 1字节

<?="<?=str_pad(_,",strlen($argn)+18,"*$argn);";

打印一个下划线,后跟空格。
与管道一起运行-F; 使用-f或运行输出的程序-F

如果输入的位数超过64位
(远远高于PHP_INT_MAX(此时)),将失败。

但是,如果输入大于PHP_INT_MAX-18 ,它将失败...它仍然符合条件吗?


@HyperNeutrino:对于大于PHP_INT_MAX-18的输入,此操作将失败。那会取消资格吗?
泰特斯(Titus),

不,我要说的很好:)
HyperNeutrino

0

PHP→Python 2,40 + 1字节

print "A"*<?=13+strlen($argn),"*",$argn;

打印一个Python程序,该程序打印重复A的。与一起作为管道运行-F


0

批处理→木炭,22字节

我不确定应该使用哪种编码,因为这些是字节。以下是解释为Windows-1252的字节:

@set/p=Á%1ñªÉñ«Ìñ¹<nul

与PC-850相同的字节:

@set/p=┴%1±¬╔±½╠±╣<nul

木炭代码页中的相同字节:

@set/p=A%1θ×Iθ⁺Lθ⁹<nul

生成的木炭程序为Plus(Length(Cast(n)), 9)字节长:

A       Assign
 %1      (String representation of n)
   θ      To variable q
        Implicitly print a number of `-`s equal to:
×        Product of:
 Iθ       Cast of q to integer
 ⁺        Sum of:
  Lθ       Length of q
  ⁹        Integer constant 9


0

JavaScript(ES8),43 41 39字节

n=>`f=_=>"".padEnd(${n}*(88+f).length)`

测试一下

生成的函数的输出是一串空格,*在此Snippet中将其替换为s。

g=
n=>`f=_=>"".padEnd(${n}*(88+f).length)`

o.innerText=(h=n=>`Function: ${x=g(n)}\nLength:   ${x.length}\nOutput:   "${x=eval(x)().replace(/./g,"*")}"\nLength:   `+x.length)(i.value=10);oninput=_=>o.innerText=h(+i.value)
<input id=i type=number><pre id=o>


0

R,46个字节

function(n)sprintf("cat(rep('a',%d*23),'')",n)

在线尝试!

返回字符串的匿名函数

cat(rep('a',n*23),'')

哪个会打印23次aa后跟一个空格)n。我需要,''因为否则cat将不会打印最后一个空格字符。


0

C,94个字节

main(int c,char**a){if(c>1){c=atoi(a[1]);if(c>0&&c<0xFFFFFF){c*=94;while(c--)printf("r");}}}

这将是94个字节,包括标准C表示应写入的最后\ n。如果程序参数不存在或<= 0或> 0xFFFFF,则以“ r”字符作为(程序长度)*(程序参数)的形式返回

C:\>nameProg.exe 1
rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr

0

MATLAB(63位元组)

a=@(n)['repmat(''a'',1,',num2str(n*(15+numel(num2str(n)))),')']

例如:

>> a(5)

ans =

repmat('a',1,80)

和:

>> repmat('a',1,80)

ans =

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