終了しますが、Windowsファイルです!


9

実行時に自分自身を現在のディレクトリに、自分自身という名前のソースファイルに作成するクインを書き込みます。ここではWindowsを使用するため、ファイル名(したがってクイン)には次の制限が必要です。

  • これらの文字はどれも \ / : ? * < > |
  • 211 255文字未満

制限と仮定

  • あなたのコードは完全なプログラムでなければなりません(結局それは実行されるでしょう)。

  • ソースファイルからのコピーはありません。

  • 名前にQuineが含まれている別のファイルがないと想定できます(Quine(1)が生成されるため)。

  • エラーは許可されます(エラーがソースコードに入らない限り)

これは、バイト単位の最短コードが優先されます。

編集する

多分私ははっきりしていませんでした、クインの名前のファイルは実際にクインを含まなければなりません。私の悪い。


プログラムの非ASCII文字の制限は何ですか?(Windowsでは、インストールされているWindowsの言語バージョンに依存する可能性があります。正確なルールと、時間の経過とともに変更されたかどうかは忘れます。)

なぜ211バイト未満なのですか?それは一種の恣意的な制限です...
mbomb007

@ mbomb007最大ファイル名サイズだと思います。
Addison Crump 2017

1
@VoteToClose It's 255. stackoverflow.com/a/265782/2415524
mbomb007

@ mbomb007 Typo、たぶん?
Addison Crump 2017

回答:


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

2つのスタックは、最後は同じになります。一部のJavaバージョンでFileNotFoundExceptionは、FileInputStreamクラスの実装が異なるために、これが原因でスローされる場合があります。

編集前の以前の回答:

&'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 forPush a new stack to the stack stack.
Pavel

1
新しいスタックスタックをスタックスタックスタックにプッシュできる場合は、+ 1してください。それ以外の場合は、忘れてください!...冗談+1、私も笑った。
マジックタコの壷

2
@carusocomputingもし私ができると言ったらどうしoますか?;)
Addison Crump 2017

ため息を解凍 ...
マジックタコの壷

1
うーん...生成されたファイルにはコードが含まれているはずです(つまり、その内容はファイル名と同じである必要があります)
Leo

5

Node.js、56 52バイト

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

これは警告を出力します

DeprecationWarning:コールバックなしで非同期関数を呼び出すことは非推奨です。

すべて緑にしたい場合は、に変更writeFileするのに4バイトかかりますwriteFileSync


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.format2回に変更する必要があると思います。
Peter Taylor

@PeterTaylorあなたはスティングが好きではない、そうですか?
KeyWeeUsr 2017

5
@KeyWeeUsr、私は彼に対して個人的には何もありません、そして実際には彼は私の養育費の支払いを手伝いましたが、Lua標準ライブラリはおそらく警察のファンのためではなく、同様のAPIに詳しい人々による一般的な使いやすさのために設計されたと思います。
Peter Taylor

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 2017年
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.