排队,但带有Windows文件!


9

编写一个quine,该quine在运行时会在当前目录中创建一个名为自身的源文件。我们将在其中使用Windows,因此文件名(并因此是quine)必须具有以下限制:

  • 这些字符都不是 \ / : ? * < > |
  • 少于211255个字符

局限性和假设

  • 您的代码必须是完整的程序(毕竟将要运行)。

  • 不能从源文件复制。

  • 您可以假设没有另一个以Quine为名称的文件(因为它将产生Quine(1))。

  • 错误是允许的(只要它们不进入源代码即可)

这是 ,以字节为单位的最短代码胜出!

编辑

也许我不清楚,但带有quine名称的文件实际上必须包含该quine。我的错。


程序中非ASCII字符有哪些限制?(在Windows上,这很可能取决于所安装的Windows语言版本;我忘记了确切的规则以及它们是否随着时间的推移而发生了变化。)

为什么少于211个字节?那是一个任意的限制……
mbomb007 '17

我相信@ mbomb007最大文件名大小。
艾迪生·克朗普


@ mbomb007 Typo,也许吗?
艾迪生·克伦普

Answers:


6

Vitsy,10 27字节

'rddd++&"rdd8++a[v}v1-D);].

如果:允许,我可以将其缩短为11个字节。:(

说明:

'rddd++&"rdd8++a[v}v1-D);].
'                           Capture all instructions as a string until encountering
                              ' again, looping if necessary.
 r                          Reverse the current stack (output is top-down).
  ddd++                     Push char literal ' to the stack.
       &                    Push a new stack to the stack stack.
        "                   Same as ', but " specific.
         r                  Reverse the current stack.
          dd8++             Push char literal " to the stack.
               a            Push 10 to the stack.
                [        ]  Loop forever.
                 v          Capture the top value as a variable.
                  }         Take the bottom item of the stack and put it on the top.
                   v        Dump the variable to the stack.
                    1-      Subtract 1.
                      D     Duplicate the top item.
                       );   Pop n; if n is 0, exit the loop.
               a[v v1-D);]  This is a makeshift for loop with 10 iterations.
                          . Pop the top stack as n, and the second stack as o. 
                              Write a file called "n" with the contents of "o".

最后的两个堆栈相同。在某些Java版本上,FileNotFoundException由于FileInputStream类的不同实现,这可能会抛出a 。

编辑前的先前答案:

&'rddd++}.

说明:

&           Push a new stack to the stack stack.
 'rddd++    Modified standard quine.
        }   Move the ' to the right place.
         .  Pop the top stack as n, and the second stack as o. Write a file called
                 "n" with the contents of "o". (Quine name, no content)

因为我也是如此,所以下面是堆栈中发生的步骤的示意图(每个堆栈由表示[]):

Initial state: [[]]

&              [[], []]
                  Push a new stack to the stack stack.

 '             [[], ["r", "d", "d", "d", "+", "+", "}", ".", "&"]]
                  This stack state occurs because ' will loop around the line
                    until finding the next '.

  r            [[], ["&", ".", "}", "+", "+", "d", "d", "d", "r"]]
                  Reverses the top (last) stack.

   ddd         [[], ["&", ".", "}", "+", "+", "d", "d", "d", "r", 13, 13, 13]
                  Push thirteen thrice.

      ++       [[], ["&", ".", "}", "+", "+", "d", "d", "d", "r", "'"]
                  Because char ' is 39 = 13 + 13 + 13.

        }      [[], [".", "}", "+", "+", "d", "d", "d", "r", "'", "&"]]
                  Takes the bottom item, then puts it on the top.

         .     []
                  Writes a file with content from the second-to-top stack and the
                    name as the concatenation of all elements in the top stack,
                    with top member priority (backwards from my representation).

我实际上不确定这是如何工作的。微小的变化会导致此中断。例如,放置&在不同的其他位置应该只是工作为好,但它会导致ClassCastExceptionS,IOExceptions和ArrayOutOfBoundsExceptions ^取决于你把它。我可能需要进行一些错误修正。


1
为+1 Push a new stack to the stack stack.
Pavel

1
如果您可以将新的堆栈推入堆栈堆栈,请从我这里+1,否则就算了!...开玩笑+1,我也笑了。
魔术章鱼缸

2
@carusocomputing如果我告诉您可以使用该o怎么办?;)
Addison Crump

叹气解开 ...
魔术章鱼缸

1
嗯...我认为生成的文件应该包含代码(即,其内容应等于其文件名)
Leo

5

Node.js,56 52字节

function f(){require('fs').writeFile(f+='f()',f)}f()

这会打印警告

DeprecationWarning:不推荐使用不带回调的异步函数。

如果您想要全绿色,则需要4个字节才能更改writeFilewriteFileSync


2

Lua,96个字节。

s="s=%qs=string.format(s,s)f=io.open(s)f.write(f,s)"s=string.format(s,s)f=io.open(s)f.write(f,s)

在我的手机上输入此字词即可正常使用,但是当我进入计算机时会对其进行测试。


12
我认为至少您需要更改sting.formatstring.format两次。
彼得·泰勒

@PeterTaylor您不喜欢Sting,是吗?
KeyWeeUsr'2

5
@KeyWeeUsr,我个人没有反对他,实际上他为我的抚养付出了代价,但是我认为Lua标准库可能是为熟悉类似API的人们设计的,而不是专门为警察迷设计的。
彼得·泰勒

1

C,134字节

s[255];fd;char p[255]="s[255];fd;char p[255]=%c%s%c;main(){sprintf(s,p,34,p,34);creat(s,0);}";main(){sprintf(s,p,34,p,34);creat(s,0);}

这里的源代码包含所有内容,*因此根据规则,它看起来像是不允许的。
价值墨水

@ValueInk固定。感谢您指出了这一点!
MD XF
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.