概要
Orenono gem と banner コマンドを利用して Brainf_ck を意識せずに Brainf_ck の AA を描く
orenono gem って何?
「また、 Brainf__k 派生か。もう飽き飽きだ。 」という意見はごもっともですが、
orenono gem はちょっと毛色が違います。
この gem を利用すると Brainf_ck 派生言語を Ruby の DSL だけで作れます。
わざわざ派生言語を作る価値が下がるのです。
つまり、量産される Brainf_ck 派生の価値を下げる gem です。
詳細はこちらをご確認ください。
- Ruby で Brainf*ck の派生言語を作成するための gem 『orenono』を作成してみた
- Brainf*ck の派生言語作成ツール orenono gem で「修造言語」と「ノノムラー言語」を作ってみる
仕様
以下の文字列を出力する Brainf_ck のコードを AA で出力します。
以下の分は esa.io の説明文から拝借しました。
"Everything is not perfect from the beginning. We want to support the concept of information. Done is better than perfect. Then, update it again and again, shaping it up. After it has been nearly completed, they should be organized and categorized. "
上記の文字列を Brainf_ck のコードに置き換えた後に、以下の AA にあてはめます。
一応、トリのつもりです。
(\('>')/)
ちなみに esa.io の トリ AA 一覧 があります。
今回は、 banner コマンドできれいに出力できるように自分で絵文字を決めました。
手順
banner コマンドで AA を作成
この AA のひな型に後程 Brainf_ck のコードを流し込みます。
出力結果をクリップボードにコピーしておき、後程 AA 生成用のソースコードに張り付けます。
(この部分のロジック作成はさぼります)
$ banner "(\('>')/)"
X X X X X X
X X X X X X X X
X X X X X X X X X
X X X X X X X
X X X X X X X
X X X X X X X
X X X X X X X
X X X X X X X
X X X X X
X X X X
X X X X
出力文字列をもとに Brainf_ck のコードを生成する
orenono gem には Brainf_ck のコード生成機能があるので、それを利用します
$ orenono generate "Everything is not perfect from the beginning. We want to support the concept of information. Done is better than perfect. Then, update it again and again, shaping it up. After it has been nearly completed, they should be organized and categorized." > esa_service.bf
こんなコードが生成されます。
++++++++++[>++++++<-]>+++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++.-----------------.+++++++++++++.+++++++.-----.------------.+.+++++.-------.-----------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++.-----------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+.+++++.------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-----------.+++++++++++++.------------.-.--.+++++++++++++++++.------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++.---.--.-----------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.------------.---.---------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++.++.++.+++++..-----.+++++.-------.---------------------------------------------------------.--------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++.---------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.----------------------.+++++++++++++.++++++.------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-----.-------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++.-----..-.+++.++.------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.------------.---.---------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++.-.-----------.++.+++++++++++.++++.------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---------.----------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++.--------.+++++++++.+++.-----.------------.+++++++++++++++++++.-----------.++++++.-.----------------------------------------------------------------.--------------.++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++.-.---------.---------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++.-----------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++.+++++++++++++++..---------------.+++++++++++++.----------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.------------.-------.+++++++++++++.------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-----------.+++++++++++++.------------.-.--.+++++++++++++++++.----------------------------------------------------------------------.--------------.++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++.---.+++++++++.------------------------------------------------------------------.------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-----.------------.---.+++++++++++++++++++.---------------.---------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++.------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++.------.++++++++.+++++.------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++.----------.--------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++.------.++++++++.+++++.------------------------------------------------------------------.------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-----------.-------.+++++++++++++++.-------.+++++.-------.-----------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++.------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-----.------------------------------------------------------------------.--------------.+++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++.++++++++++++++.---------------.+++++++++++++.----------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++.------------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------.++++++++++++++++++.-----------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++..+++++++++.------------------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.---------.----.+++++++++++++++++.------.+++++++++++++.-----------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++.--.+++.----.-------.+++++++++++++++.---------------.-.--------------------------------------------------------.------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.------------.---.++++++++++++++++++++.-----------------------------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-----------.+++++++.++++++.---------.--------.--------------------------------------------------------------------.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++.---------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++.-----------.------.+++++++++++++.-----.+++++++++++++++++.---------------------.-.--------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++.----------.--------------------------------------------------------------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--.+++++++++++++++++++.---------------.++.++++++++.+++.---------.+++++++++++++++++.---------------------.-.------------------------------------------------------.
変換コードを実行
変換コード: bf_aa_converter.rb
変換コードです。
- banner で生成した文字列を 2 進数に置き換える
__END__
以下は、事前に banner で作成しておいた AA のひな型です。 - AA のテンプレートの文字列を配列化し、1文字ずつ Brainf_ck のコードを埋め込んでいきます
- Brainf_ck のコードを使い切ったら、AA が中途半端にならないようにダミーの文字を埋めます
template = DATA.read.gsub("\n", '')
bit_template = template.chars.map { |e|e == 'X' ? 1 : 0 }
answer_bf = File.read('esa_service.bf')
answer_bf_bytes = answer_bf.chars
dummy = '='
results = []
last = false
loop {
bit_template.each do |char|
c = (char == 0) ? ' ' : last ? dummy : answer_bf_bytes.shift
results << c
last = true if answer_bf_bytes.size == 0
end
break if last
}
print results.each_slice(81).map { |e|e.join + "\n" }.join
__END__
X X X X X X
X X X X X X X X
X X X X X X X X X
X X X X X X X
X X X X X X X
X X X X X X X
X X X X X X X
X X X X X X X
X X X X X
X X X X
X X X X
実行
$ ruby bf_aa_converter.rb > aa_esa_service.bf
出力 (aa_esa_service.bf)
こんな トリ AA の Brainf_ck のコードが完成しました。
+ + + + + +
+ + + + [ > + +
+ + + + < - ] > +
+ + + + + + +
+ . + + + + +
+ + + + + + +
+ + + + + + +
+ + + + + + +
+ + + + +
+ + + +
+ + + +
# 非常に長いので省略します
- - - - - -
- - - - - - - -
- - - - - - - - -
- - - - - - -
- - - - - - -
- - - - - - -
. = = = = = =
= = = = = = =
= = = = =
= = = =
= = = =
完成した Brainf_ck を orenono gem で実行してみます
% orenono e aa_esa_service.bf
Everything is not perfect from the beginning. We want to support the concept of information. Done is better than perfect. Then, update it again and again, shaping it up. After it has been nearly completed, they should be organized and categorized.