– hatena: http://d.hatena.ne.jp/ku-ma-me/ in Japanese – blogger: http://mamememo.blogspot.com/ in English • A committer for Ruby and RubySpec – 1.9.2 assistant release manager • An esoteric programmer 2
programming language – esoteric: 難解な、深遠な、秘伝的な、奥義に達した – ex) brainf**k • 共通の特徴:奇妙な制約 common feature: bizarre constraint – 使える文字 bizarre kind of character used – 使える命令 bizarre instruction set – 命令順序や文字配置 bizarre execution order and placement +++++++++[>++++++++>++++++++++ +>+++++<<<]>.>++.+++++++..+++. >-.------------.<++++++++.---- ----.+++.------.--------.>+. Hello world in brainf**k 4
not only “Hello, world!” but also any program require "1234567890" 316805813369061470447252554255354 816767578747985092956934801232229 450578663292118901228453190669621 8369564670777459615871118090530 7
written in code directly – GC.disable – at_exit – ObjectSpace.each_object(Bignum) – eval 1.8 と 1.9 両方で動く both 1.8 and 1.9 can run this JRuby でも動く(が –X+O オプションが必要) JRuby can also run this, but needs -X+O option; uncool Hello world with number only 10
numbering • ゲーデル数の 6 進数表記をアンダースコアで表す represent each base-6 digit of Gödel number as length of underscores • Ruby の有名黒魔術: method_missing Ruby’s famous black magic: method_missing • you can install: gem install _ Hello world with underscore only 12
code by yourself – http://d.hatena.ne.jp/ku-ma-me/20100709/p1 – You can read it because it is purely written in Ruby that you know! • shinh さんのアイデアがベース based on shinh’s idea (Shin’ichiro Hamaji) – アルファベットと数字だけ Pure Ruby with Alphabet and Number only – http://d.hatena.ne.jp/shinichiro_h/20081109#1226217059 Hello world with purely alphabet only 15
character constraints • おまけ: 1.8 と 1.9 は意外に互換である 1.9 is more compatible with 1.8 than you think • 未解決問題 open problem – 小文字アルファベットだけ lower-case alphabet only – 大文字だけ(不可能?) upper-case only (impossible?) – 「記号だけ」は解決済み FYI: “punctuation only” was resolved http://www.kurimura.com/rsencode/ 16
itself • 実装の基本 implementation basis – 手順 1. 自分自身を文字列として再構成する Step 1. construct a string that is itself – 手順 2. その文字列を出力する Step 2. print it • 出力前に整形すると変な Quine ができる we can write “artistic” Quine by shaping it before printing eval s="puts'eval s='+s.inspect" 18
station name of Japanese Yamanote Loop Rail line • 29 駅で元に戻る we need invoke ruby 29 times (stations) once – 起動速度重要 invoking speed matters – JRuby is 10x slower than MRI (3.3sec vs. 33sec) 19
is itself 2. 次の駅の形に整形してから出力する Step 2. print it after shaping it as the next station name 3. 以上をアスキーアートの形で行う Step 3. write the program in ascii art – フォントデータ(圧縮) font data (compessed) – 駅名(圧縮) station names (compessed) – 圧縮の展開 decompressing – Quine – 整形 shaping – ゴミ padding Yamanote Quine 20
your program with no space and backslash 2. と で囲む enclose it 3. 自由に整形できる you can shape it as you like • 注: %w() は文字列配列のリテラル NOTE: %w() is a literal for Array • = Yamanote Quine eval %w( pu ts “H i” ).join## eval %w (( ).join %w(foo bar) [“foo”, “bar”] 21
and its decoder size • 最適な圧縮方法はデータの規模によって変わる best decoder depends on data size • コルモゴロフ複雑性とか feel Kolmogorov complexity – see Wikipedia Yamanote Quine data size (about) decoder ~ 10 bytes No compression ~ 100 bytes String#to_i(36) ~ 500 bytes Base64 More Zlib + pack デコーダ小 shorter decoder データ大 longer data データ小 shorter data デコーダ大 longer decoder 22
プログラム、を出力する Java プログラム、を出力する C プログラム、を出力する Haskell プログラム、を出力する OCaml プログラム、を出 力する Lua プログラム、を出力する Perl プログラム、を出 力する Python プログラム、を出力する Ruby プログラム、 です • This is a Ruby program that outputs a Python program that outputs a Perl program that outputs a Lua program that outputs a OCaml program that outputs a Haskell program that outputs a C program that outputs a Java program that outputs a brainfuck program that outputs a Whitespace program that outputs a Unlambda program that outputs the program itself. 29
– むだに深淵な背景理論 esoteric theory – 勝つためなら何でもする dirty hack • 教訓 lessons – 1.8 と 1.9 は意外と互換 1.9 is more compatible with 1.8 than you think – 起動速度重要 invoking speed matters for esoteric programming; JRuby is too slow 31