Malbolge#
Installation#
Malbolgeインタプリタをコンパイルし, 実行ファイルを生成する.
$ curl -s http://www.lscheffer.com/malbolge_interp.html | sed -n 's/.*<pre>\(.*\)<\/pre>.*/\1/p' | sed 's/<br>/\n/g' | sed 's/<[^>]*>//g' | sed 's/</</g; s/>/>/g; s/amp;//g' > malbolge.c
$ gcc -o malbolge malbolge.c
Example#
hello.mal:
(=<`#9]76ZY327U/.Q210/.-,+*)('&%$#"!~}|{z(Kw%$t"VqpihmlO+M)g`ed#baDlA]\[Z=XW99Nr5p3Im0FEDhHG)?c=<`##8\}Z:9yVC543210/.-,+*)('&%$#c!~}v
$ ./malbolge hello.mal
Hello, World!
Note
hello.malの作成にあたり, reika727さんのビーム探索プログラムを使用しました.
なお, 出力を"Hello World"から"Hello, World!"に変更するために, main.cppの26行目と41行目を以下のように修正しています.
- constexpr std::string_view target = "Hello World";
+ constexpr std::string_view target = "Hello, World!";
- } else if (output.length() > 0 && toupper(output.back()) != toupper(target[output.length() - 1])) {
+ } else if (output.length() > 0 && output.back() != target[output.length() - 1]) {
実際に, Malbolgeで"Hello, World!"するプログラムを探索すると以下のようになります.
$ make test
/usr/bin/g++ -Wall -Wextra -O3 -mtune=native -march=native --std=c++23 -MMD -MP -c -o main.o main.cpp
/usr/bin/g++ -o malbolge-hello.out main.o malbolge.o malbolge_machine_state.o
./malbolge-hello.out
GENERATION #1
GENERATION SIZE: 1
BEST RESULT :
BEST SCORE : 0
GENERATION #2
GENERATION SIZE: 8
BEST RESULT :
BEST SCORE : -1
...
GENERATION #76
GENERATION SIZE: 10000
BEST RESULT : Hello, World!
BEST SCORE : 55
GENERATION #77
GENERATION SIZE: 10000
BEST RESULT : Hello, World!
BEST SCORE : 64
FINAL RESULT : Hello, World!
FINAL SCORE : 64
CODE : (=<`#9]76ZY327U/.Q210/.-,+*)('&%$#"!~}|{z(Kw%$t"VqpihmlO+M)g`ed#baDlA]\[Z=XW99Nr5p3Im0FEDhHG)?c=<`##8\}Z:9yVC543210/.-,+*)('&%$#c!~}v