読者です 読者をやめる 読者になる 読者になる

第一回超絶技巧分科会

Quineを(とりあえず)書く

eval s="print 'eval s='+s.inspect"
$ cat quine.rb
eval s="print 'eval s='+s.inspect"
$ ruby quine.rb
eval s="print 'eval s='+s.inspect"

「Quine」・・「プログラムのソースコード」と「そのプログラムを実行した結果出力」が
一致するようなプログラム。



考えなしにやろうとした結果

print "print "
print "\"print \"\nprint "
print "\"\\\"print \\\"\\nprint \"\nprint "

ちょっと考えて、文字列を使うようにした

$ cat quine_turai2.rb
s = "; print \"s = \" + s + s"; print "s = " + s + s
$ ruby quine_turai2.rb
s = ; print "s = " + s + s; print "s = " + s + s

おしい。
文字列を囲っている""をどうにかする必要がある。

解決法

  • エスケープシーケンス(%cみたいなやつ)を使う
  • 数字->文字の変換をする(.chrとかchr()とか)
  • そのほか、言語特有の機能を使う
スクリプト言語でQuine

asciiコードの対応
" ・・ 34
' ・・ 39
% ・・ 37
$ ・・ 36

あと、スクリプト言語の場合、「exec」 もしくは 「eval」 みたいな「文字列をソースコードとみなして実行する」ということができるので、同じ文字列を二回書かずに済む。

s="s=%c%s%c;print(s%c(34,s,34,37))";print(s%(34,s,34,37))
s='print "s=%c"%39 + s + "%c;exec(s)"%39';exec(s)

115 ・・ "s" のアスキーコード
61 ・・ "=" のアスキーコード

s="; puts 34.chr + s + 34.chr + s"; puts 115.chr + 61.chr + 34.chr + s + 34.chr + s
eval s="print 'eval s='+s.inspect"

ヒアドキュメントを使用した例

s = <<'H'
print ("s = <<'H'\n" + s + "H\n" + s)
H
print ("s = <<'H'\n" + s + "H\n" + s)
eval(
s = <<'H'
print ("eval(\ns = <<'H'\n" + s + "H\n)")
H
)
eval($s='print"eval(".chr(36)."s=".chr(39).$s.chr(39).");"');
コンパイル式の言語(C言語)でQuine
#include<stdio.h>
int main(void){
	char s[500]="#include<stdio.h>\0int main(void){char s[500]=\0;printf(\0%s%c%s%c%s%c0%s%c0%s%c0%s%c0%s%c%s%c%s%c%s%c\0,s,10,s+18,34,s,92,s+18,92,s+46,92,s+55,92,s+100,34,s+46,34,s+55,34,s+100,10);return 0;}";
	printf("%s%c%s%c%s%c0%s%c0%s%c0%s%c0%s%c%s%c%s%c%s%c",s,10,s+18,34,s,92,s+18,92,s+46,92,s+55,92,s+100,34,s+46,34,s+55,34,s+100,10);
	return 0;
}

つらい。
自分で手打ちして作るものではない。

#include<stdio.h> 
#include<string.h>
char h[256]=
	"#include<stdio.h>\n"
	"#include<string.h>\n"
	"char h[256]={";
char t[256]=
	"\nint main(void){\n"
	"	printf(\"%s\",h);\n"
	"	for(int i=0;i<strlen(h);i++){\n"
	"		printf(\"%d,\",h[i]);\n"
	"	}\n"
	"	printf(\"};\\nchar t[256]={\",34);\n"
	"	for(int i=0;i<strlen(t);i++){\n"
	"		printf(\"%d,\",t[i]);\n"
	"	}\n"
	"		printf(\"};%s\",t);"
	"	return 0;\n"
	"}\n";
int main(void){
	printf("%s",h);
	for(int i=0;i<strlen(h);i++){
		printf("%d,",h[i]);
	}
	printf("};\nchar t[256]={",34);
	for(int i=0;i<strlen(t);i++){
		printf("%d,",t[i]);
	}
	printf("};%s",t);
	return 0;
}

わりと人間味のあるソースコードになった。
ちなみに、これによって生成されるクワインは、

#include<stdio.h>
#include<string.h>
char h[256]={35,105,110,99,108,117,100,101,60,115,116,100,105,111,46,104,62,10,35,105,110,99,108,117,100,101,60,115,116,114,105,110,103,46,104,62,10,99,104,97,114,32,104,91,50,53,54,93,61,123,};
char t[256]={10,105,110,116,32,109,97,105,110,40,118,111,105,100,41,123,10,9,112,114,105,110,116,102,40,34,37,115,34,44,104,41,59,10,9,102,111,114,40,105,110,116,32,105,61,48,59,105,60,115,116,114,108,101,110,40,104,41,59,105,43,43,41,123,10,9,9,112,114,105,110,116,102,40,34,37,100,44,34,44,104,91,105,93,41,59,10,9,125,10,9,112,114,105,110,116,102,40,34,125,59,92,110,99,104,97,114,32,116,91,50,53,54,93,61,123,34,44,51,52,41,59,10,9,102,111,114,40,105,110,116,32,105,61,48,59,105,60,115,116,114,108,101,110,40,116,41,59,105,43,43,41,123,10,9,9,112,114,105,110,116,102,40,34,37,100,44,34,44,116,91,105,93,41,59,10,9,125,10,9,9,112,114,105,110,116,102,40,34,125,59,37,115,34,44,116,41,59,9,114,101,116,117,114,110,32,48,59,10,125,10,};
int main(void){
	printf("%s",h);
	for(int i=0;i<strlen(h);i++){
		printf("%d,",h[i]);
	}
	printf("};\nchar t[256]={",34);
	for(int i=0;i<strlen(t);i++){
		printf("%d,",t[i]);
	}
		printf("};%s",t);	return 0;
}
簡単なesolangでQuine

esolangの問題点

  • 文字列を持てないものがある。(s = "hogehuga" みたいなのができない)

基本的な考え方として、

A:「値を積んでいくパート」
B:「Aの部分を(Aで積んだものを破壊することなく)出力するパート」
C:「Aの部分に積んだものに従って出力するパート」

を作ればよい。

  • 前回の記事のアレの場合
  • A
#1#59#64#126#52#49#35#46#64#42#54#35#61#49#35#58#95#64#126#53#50#35#44#46#53#51#35#92#58#64#42#50#49#35#61#48#35#58#43#126#49#35#54#52#35#46
  • B
#1~+:#0=#12*@:\#35.,#25~@_:

ここで、A,Bの部分だけで実行すると、
Aの部分のみがまるまる出力される。
ー> Aの部分でどれだけメモリに数字を積もうとも、Aの部分は出力されるようになる。
あとは、Aの部分で、B,Cの部分の文字列を積んでやればよい。

  • C
#1=#6*@.#14~@;

で、Cで、Aの部分の文字を出力する。

  • Brainf*ckの場合

(全くゴルフしていないので、とても長くなってしまった)

+>>+>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>>>++++++[<+++++++>-]<+>>++++++++[<++++++++>-]<--<.>..<.>.<<<-[+><-[+<<<-]+>[->+>>[>>>]>.<<-[+<<<-]+>]<->>>+>[>>>]>>...<<<-]<[.<<<]
  • A
+>>+>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>>
  • B
>>++++++[<+++++++>-]<+>>++++++++[<++++++++>-]<--<.>..<.>.<<<-[+><-[+<<<-]+>[->+>>[>>>]>.<<-[+<<<-]+>]<->>>+>[>>>]>>...<<<-]
  • c
<[.<<<]
  • 製作過程でできたもの
$ inp.exe myquine.bf
inited
+>>+>+++>>>+++++>>>+++++++>>>
halt
[1,0,0,0,3,0,0,5,0,0,7,(0),0,43,62,0,]
runtime .. 0.002001
+>>+>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>>+++++++++++++++++++++++++++++++++++++++++++>>> //適当に積まれた入力

>>++++++[<+++++++>-]<+ //+をメモリに積む
>>++++++++[<++++++++>-]<-- //>をメモリに積む。
<.>..<.>.<< //先頭の5文字(+>>+>)を出力する

<-[+>
<-[+<<<-]+> //先頭までポインタを戻す
[
		->+>>
		[>>>]
		>.<     //+の出力
	<-[+<<<-]+> //先頭までポインタを戻す
]

//ここまでで、+が出力される。

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

// ここまでで、先頭の部分が文字として出力される。

<
[.<<<]
  • make_bf_quine.rb
source = "+>>+>"
prog = ">>++++++[<+++++++>-]<+>>++++++++[<++++++++>-]<--<.>..<.>.<<<-[+><-[+<<<-]+>[->+>>[>>>]>.<<-[+<<<-]+>]<->>>+>[>>>]>>...<<<-]<[.<<<]"

(1..(prog.size)).each{|x|
	c = prog[prog.size-x]
	for i in 1..(c.ord)
		source += "+"
	end
	source += ">>>"
}

source += prog

print source

prog の部分は、B+Cの文字列が入ってます。

まあ、だいたい似たようなことをやってます。