Tri-interquine-ループで互いに出力する3つのプログラム


10

関連:Interquine

プログラムAは実行時にプログラムBのコードを出力し、BはCのソースを出力し、CはAのソースを出力します。

今回は2つの文字を交換して再度交換することはできません:)

要件:

  • すべてのプログラムで1つの言語のみ
  • 標準の抜け穴の制限が適用されます
  • プログラムはすべて異なります。自身を出力する1つのプログラムは対象外です。お互いに出力する2つも対象外です。
  • すべてのプログラムは空ではないか、長さが少なくとも1バイトです。
  • stdinが接続されているため、読むものはありません/dev/null(できれば、このルールを悪用することができます)。出力はstdoutに送られます。
  • ランダムな結果を生成する関数を使用しないでください。

追加:

  • 可能であれば説明してください

スコアは最短のものの長さです(短いものから長いプログラムを生成できますか?)。すべてのプログラムの長さを書き、最小の数字を強調表示してください。末尾の改行はカウントされません。最も低いスコアが勝ちます。


2
関連。(同じこと、異なる言語。)
マーティンエンダー2017

回答:


19

Python 3、50バイト

s='s=%r;print(s%%(s,%i*2%%7))';print(s%(s,1*2%7))

オンラインでお試しください!

最後の式は1*2%7to 2*2%7からto 4*2%7に戻り、に戻り1*2%7ます。


6
n-interquineに対する普遍的な解決策のように見えます。7を(2 ^ n)-1に置き換えるだけです。
iBug 2017

4
Python 2では、マッピング1-2/_はを使用して3サイクルを形成(1,-1,3)%ます。これにより、をエスケープする必要がないため、バイトが節約されます。
XNOR

@iBugや大型のためにさらに短くns='s=%r;print(s%%(s,-~%i%%3))';print(s%(s,-~1%3))交換3n
PurkkaKoodari

4

RProgN 212の 8バイト

1
«\2*7%

説明しました

1   # Push the digit to the stack.

«\2*7%
«       # Define a function from here to the matching ». As there is no matching », define it from here to the end of the program, and continue running.
 \      # Flip the function under the constant number.
  2*    # Multiply by 2.
    7%  # Modulo 7.

RProgNがデフォルトで出力する方法の便利な性質により、1行目に1、2、4の間でループする数値が残り、2行目には文字列化されたバージョンの関数が残ります。@LeakyNunPython Answerに触発されました

オンラインでお試しください!


4

CJam、17バイト

{sZZe\6Ye\"_~"}_~

{s6Ze\ZYe\"_~"}_~

{sZ6e\ZYe\"_~"}_~

オンラインでお試しください!

おそらく最適ではありませんが、これは以前の課題に対する私のアプローチの修正です

基本的な考え方は同じですが、2つのスワップを実行しますが、その1つは常に何もしません。影響を受けるインデックスは23および6

1:     {sZZe\6Ye\"_~"}_~
ZZe\             does nothing
       {sZZe\6Ye\"_~"}_~
6Ye\     \   /
          \ /
           X
          / \
         /   \
2:     {s6Ze\ZYe\"_~"}_~
6Ze\      \  /
           \/    doesn't really do anything
           /\
          /  \
       {s6Ze\ZYe\"_~"}_~
ZYe\     \/
         /\
3:     {sZ6e\ZYe\"_~"}_~
Z6e\      \  /
           \/
           /\
          /  \
       {sZZe\6Ye\"_~"}_~
ZYe\     \/      doesn't really do anything 
         /\
1:     {sZZe\6Ye\"_~"}_~

3

CJam、14バイト

{_]3/W="_~"}_~

{_]3/W="_~"}{_]3/W="_~"}_~

{_]3/W="_~"}{_]3/W="_~"}{_]3/W="_~"}_~

オンラインでお試しください!

他のプログラムの長さは、それぞれ26バイトと38バイトです。

説明

さらに別のアプローチ!

{       e# Again, the usual quine framework. In this case, there might
        e# be one or two additional copies of the block on the stack.
  _     e#   Duplicate the top copy of the block.
  ]     e#   Wrap all copies in an array.
  3/    e#   Split into chunks of 3. For the first two programs, this will
        e#   just wrap all of them in an array. For the third program, this
        e#   splits the fourth copy off from the first three.
  W=    e#   Select the last chunk. So `3/W=` does nothing for the first
        e#   two programs, but discards three copies once we get to four.
  "_~"  e#   Push the remainder of the program.
}_~


2

Python 3、127、127、127バイト

a='a=%r;b=%r;c=%r;print(b%%(b,a,c))';b='b=%r;a=%r;c=%r;print(c%%(c,a,b))';c='c=%r;a=%r;b=%r;print(a%%(a,b,c))';print(b%(b,a,c))

プリント

b='b=%r;a=%r;c=%r;print(c%%(c,a,b))';a='a=%r;b=%r;c=%r;print(b%%(b,a,c))';c='c=%r;a=%r;b=%r;print(a%%(a,b,c))';print(c%(c,a,b))

プリント

c='c=%r;a=%r;b=%r;print(a%%(a,b,c))';a='a=%r;b=%r;c=%r;print(b%%(b,a,c))';b='b=%r;a=%r;c=%r;print(c%%(c,a,b))';print(a%(a,b,c))

これは、通常のPython quineに基づくInterquine質問に対する私の回答に基づいています。そして、クワッドインタークインの質問を受け取ったときに何をすべきかを正確に知っています;)


1

CJam、14バイト

0{\)3%\"_~"}_~

1{\)3%\"_~"}_~

2{\)3%\"_~"}_~

オンラインでお試しください!

説明

0{      e# Again, the standard CJam quine framework, but this time we have a zero
        e# at the bottom of the stack.
  \     e#   Bring the 0 to the top.
  )     e#   Increment.
  3%    e#   Mod 3 to loop from 2 back to 0.
  \     e#   Put the result underneath the block again.
  "_~"  e#   Push the remainder of the source.
}_~

1

JavaScript(ES6)、63 55バイト

eval(c="`eval(c=${JSON.stringify(c)},n=${++n%3})`",n=0)
eval(c="`eval(c=${JSON.stringify(c)},n=${++n%3})`",n=1)
eval(c="`eval(c=${JSON.stringify(c)},n=${++n%3})`",n=2)

o1.innerText = eval(c="`eval(c=${JSON.stringify(c)},n=${++n%3})`",n=0) 
o2.innerText = eval(c="`eval(c=${JSON.stringify(c)},n=${++n%3})`",n=1)
o3.innerText = eval(c="`eval(c=${JSON.stringify(c)},n=${++n%3})`",n=2)
<pre id="o1"></pre>
<pre id="o2"></pre>
<pre id="o3"></pre>

Function.prototype.toString(cheaty、30バイト)を使用した代替ソリューション

(f=n=>`(f=${f})(${++n%3})`)(1)

1

ラムダ計算、38文字、44バイト

すべてのクインの母に基づくシンプルなソリューション:y-combinator

(λx.(λy.y)(λz.z)xx)(λx.(λy.y)(λz.z)xx)

ベータ削減を使用すると、これが実際にトライインターキンであることがわかります。

(λx.(λy.y)(λz.z)xx)(λx.(λy.y)(λz.z)xx)
(λy.y)(λz.z)(λx.(λy.y)(λz.z)xx)(λx.(λy.y)(λz.z)xx)
(λz.z)(λx.(λy.y)(λz.z)xx)(λx.(λy.y)(λz.z)xx)
(λx.(λy.y)(λz.z)xx)(λx.(λy.y)(λz.z)xx)
etc.

0

Java 8、118バイト

v->{int i=0;String s="v->{int i=%d;String s=%c%s%2$c;return s.format(s,++i%%3,34,s);}";return s.format(s,++i%3,34,s);}

唯一のint i=0;機能/出力の差は、(それはどちらかだで01または2)。

説明:

オンラインでお試しください。

v->{                       // Method with empty unused parameter and String return-type
  int i=0;                 //  Integer, starting at 0, 1 or 2 depending on the version
                           //  (this is the only variation between the functions/outputs)
  String s="v->{int i=%d;String s=%c%s%2$c;return s.format(s,++i%%3,34,s);}";
                           //  String containing the unformatted source code
  return s.format(s,++i%3,s);}
                           //  Quine to get the source code, which we return as result
                           //  ++i%3 is used to cycle 0→1→2→0

追加説明:

-part:

  • String s 未フォーマットのソースコードが含まれています
  • %s この文字列をそれ自体に入れるために使用されます s.format(...)
  • %c%2$cおよび34二重引用符(")をフォーマットするために使用されます
  • %%モジュロ符号(%)をフォーマットするために使用されます
  • s.format(s,...,34,s) すべてをまとめる

出力/機能の違い:

他のほとんどの答えと同じアプローチ:

  • int i01またはのいずれかで始まる2
  • ++i%3これは、次に変換します(0→1; 1→2; 2→0

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