SlideShare a Scribd company logo
1 of 33
Download to read offline
超絶技巧 Ruby Programming
Esoteric, Obfuscated Ruby Programming

   遠藤侑介
   Yusuke Endoh
Who am I?
 • Yusuke Endoh 遠藤侑介
   – twitter: @mametter
   – 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
Esoteric Programming
 • 普通の人 normal programmer
                     puts “Hello, world!”

 • Esoteric Programmer
                              alias|send¥
                        ;$stdin=GC | "%p?"%def#
                  FALSE.gets();(8 | 64).chr+232424.
            to_s(25)+", "+%w|w !   |   *"orlc". next<<012||
      (c).Yusuke end;"oh, 2009"    |    "stegano-X."[0,4].reverse
d,be="whydoes","crypto";:make.     |     %.mains..tr'eams',be.delete(d)


 • 参考: ゴルファー cf. code-golfer (14B)
                           #!../s/grb -eh

                                http://d.hatena.ne.jp/kurimura/20090929/1254257912

                                                                                3
Esoteric Programming Language (esolang)
 • 読み書きしにくいように作られた言語
  obfuscated, confusing and unreadable programming language
   – esoteric: 難解な、深遠な、秘伝的な、奥義に達した
   – ex) brainf**k      +++++++++[>++++++++>++++++++++
                                       +>+++++<<<]>.>++.+++++++..+++.
                                       >-.------------.<++++++++.----
                                       ----.+++.------.--------.>+.

 • 共通の特徴:奇妙な制約                             Hello world in brainf**k
  common feature: bizarre constraint
   – 使える文字 bizarre kind of character used
   – 使える命令 bizarre instruction set
   – 命令順序や文字配置 bizarre execution order and placement

                                                                      4
Theme: Enjoy esolang with Ruby!
 • 制約を課せば Ruby も esolang として楽しめる
  Ruby with constraint can be an esolang
    – 1. 使用文字制約に勝つ ( ○○文字だけで Ruby を書けるか?)
          beat “character constraints” (Can you write Ruby with __ character-only?)
    – 2. 文字配置制約に勝つ (アスキーアート Quine)
          beat “shape constraints” (ASCII-art Quine)


 • 見所 Highlights
                                         • ゲーデル数 Gödel numbering
    – むだに深淵な背景理論                         • コルモゴロフ複雑性 Kolmogorov complexity
      esoteric theory                    • チューリング完全性 Turing completeness

    – 勝つためなら何でもする                        • Ruby の黒魔術 Ruby’s black magic
                                         • コードゴルフ code golf
      dirty hack                         • 文法や意味論の悪用 abuse of syntax/semantics

                                                                                      5
1. Hello world with __ Character-
only

                                    6
Hello world with Number only

require "1234567890"

316805813369061470447252554255354
816767578747985092956934801232229
450578663292118901228453190669621
8369564670777459615871118090530
 任意のプログラムが書けます
  you can write not only “Hello, world!” but also any program



                                                                7
Hello world with number only
実装 internal
 • ゲーデル数化 Encoding: Gödel numbering
 • Ruby の黒魔術 Ruby’s black magic

 • you can install: gem install 1234567890_




                                                     8
Hello world with number only
ゲーデル数による符号化 Gödel numbering




                                        9
Hello world with number only
黒魔術 Ruby’s black magic
 • コードに書かれただけの数字の参照を引っぱり出す
  How to gain number 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



                                                                  10
Hello, world with underscore only

require "_"
____ _ _____ ____ __ ____ ____
__ ___ ____ __ __ _ ______ _____
___ _ _ ___ _____ ______ ____ _
_ ____ _ _ ____ _ ____ __ __ ___
_ ______ ___ ____ __ ______ ____
_ ____ ____ __ _ ____ _ _ ___
_____ _____ _ ______ ____ _
______ _____

                                    11
Hello world with underscore only
実装 internal
 • プログラムのゲーデル数化 (“number only” と同じ)
  also uses Gödel 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 _




                                                                         12
Hello world with underscore only
なぜ 6 進数?why base-6?




                                            13
class                                        String
                                                    def                                         inspect
                                                    concat   begin   dup ensure replace String      nil
                                                    concat      concat      concat     concat      size
                                                    concat                  concat                 size
                                                    concat                  concat                 size
                                                    concat                                         size
                                                    concat begin size ensure replace String nil end end




Hello world with purely Alphabet only
                                                    concat   begin   dup ensure replace String      nil
                                                    concat concat concat concat concat concat size
                                                    concat                                         size
                                                    concat begin size ensure replace String nil end end
                                                    concat   begin   dup ensure replace String      nil
                                                    concat                  concat                 size
                                                    concat      concat      concat     concat      size
                                                    concat          concat         concat          size
                                                    concat begin size ensure replace String nil end end
                                                    concat   begin   dup ensure replace String      nil
                                                    concat                  concat                 size
                                                    concat          concat         concat          size
                                                    concat                  concat                 size



   class                                        String
                                                    concat



                                                    concat
                                                    concat
                                                             begin
                                                                    concat         concat

                                                                     dup ensure replace String
                                                                            concat
                                                                            concat
                                                                                                   size
                                                    concat begin size ensure replace String nil end end
                                                    concat                                          nil
                                                                                                   size
                                                                                                   size
                                                    concat      concat      concat     concat      size



   def                                         inspect
                                                    concat

                                                    concat
                                                    concat
                                                    concat
                                                             begin
                                                                            concat

                                                                     dup ensure replace String

                                                                    concat
                                                                            concat
                                                                                   concat
                                                                                                   size
                                                    concat begin size ensure replace String nil end end
                                                                                                    nil
                                                                                                   size
                                                                                                   size
                                                    concat                  concat                 size



   concat   begin   dup ensure replace String      nil
                                                    concat
                                                    concat
                                                    concat
                                                                            concat
                                                                            concat
                                                                                                   size
                                                                                                   size
                                                                                                   size
                                                    concat begin size ensure replace String nil end end
                                                    concat   begin   dup ensure replace String      nil
                                                    concat                  concat                 size



   concat      concat      concat     concat      size
                                                    concat
                                                    concat
                                                    concat
                                                    concat
                                                    concat
                                                                    concat
                                                                            concat

                                                                            concat
                                                                            concat
                                                                                   concat
                                                                                                   size
                                                                                                   size
                                                                                                   size
                                                                                                   size
                                                                                                   size
                                                    concat begin size ensure replace String nil end end



   concat                  concat                 size
                                                    concat   begin   dup ensure replace String
                                                    concat concat concat concat concat concat size
                                                                                                    nil

                                                    concat begin size ensure replace String nil end end
                                                    concat
                                                    concat
                                                             begin   dup ensure replace String
                                                                    concat         concat
                                                                                                    nil
                                                                                                   size
                                                    concat                  concat                 size



   concat                  concat                 size
                                                    concat



                                                    concat
                                                    concat
                                                             begin
                                                                    concat         concat

                                                                     dup ensure replace String

                                                                    concat
                                                                            concat
                                                                                   concat
                                                                                                   size
                                                    concat begin size ensure replace String nil end end
                                                    concat                                          nil
                                                                                                   size
                                                                                                   size
                                                    concat                  concat                 size



   concat                                         size
                                                    concat
                                                    concat
                                                    concat

                                                    concat   begin
                                                                            concat
                                                                            concat



                                                                     dup ensure replace String
                                                                                                   size
                                                                                                   size
                                                                                                   size
                                                    concat begin size ensure replace String nil end end
                                                                                                    nil
                                                    concat                  concat                 size



   concat begin size ensure replace String nil end end
                                                    concat
                                                    concat
                                                    concat
                                                                    concat

                                                                    concat
                                                                            concat
                                                                                   concat

                                                                                   concat
                                                                                                   size
                                                                                                   size
                                                                                                   size
                                                    concat begin size ensure replace String nil end end
                                                    concat   begin   dup ensure replace String      nil
                                                    concat                  concat                 size



   concat   begin   dup ensure replace String      nil
                                                    concat
                                                    concat
                                                    concat
                                                                    concat

                                                                    concat
                                                                            concat
                                                                                   concat

                                                                                   concat
                                                                                                   size
                                                                                                   size
                                                                                                   size
                                                    concat begin size ensure replace String nil end end
                                                    concat   begin   dup ensure replace String      nil
                                                    concat                  concat                 size



   concat concat concat concat concat concat size   concat
                                                    concat
                                                    concat
                                                                concat
                                                                    concat
                                                                            concat     concat
                                                                                   concat
                                                                                                   size
                                                                                                   size
                                                                                                   size
                                                    concat begin size ensure replace String nil end end
                                                    concat   begin   dup ensure replace String      nil
                                                    concat      concat      concat     concat      size



   concat                                         size
                                                    concat



                                                    concat
                                                    concat
                                                                concat      concat     concat

                                                                     dup ensure replace String
                                                                concat      concat
                                                                            concat
                                                                                       concat
                                                                                                   size
                                                    concat begin size ensure replace String nil end end
                                                    concat   begin                                  nil
                                                                                                   size
                                                                                                   size
                                                    concat                  concat                 size



   concat begin size ensure replace String nil end end
                                                    concat

                                                             begin   dup ensure replace String
                                                    concat concat concat concat concat concat size
                                                                                                   size
                                                    concat begin size ensure replace String nil end end
                                                    concat                                          nil

                                                    concat begin size ensure replace String nil end end
                                                    concat   begin   dup ensure replace String      nil
                                                    concat                  concat                 size




  • require がない
                                                    concat                  concat                 size
                                                    concat      concat      concat     concat      size
                                                    concat                  concat                 size
                                                    concat                                         size
                                                    concat begin size ensure replace String nil end end
                                                    concat   begin   dup ensure replace String      nil
                                                    concat                  concat                 size
                                                    concat                  concat                 size




   there is no “require”
                                                    concat          concat         concat          size
                                                    concat          concat         concat          size
                                                    concat begin size ensure replace String nil end end
                                                    concat   begin   dup ensure replace String      nil
                                                    concat                  concat                 size
                                                    concat                  concat                 size
                                                    concat          concat         concat          size
                                                    concat          concat         concat          size
                                                    concat                                         size
                                                    concat begin size ensure replace String nil end end
                                                    concat   begin   dup ensure replace String      nil
                                                    concat                  concat                 size
                                                    concat                  concat                 size
                                                    concat    concat   concat   concat   concat    size



                                                    exit                     end
                                                                                14
                                                    concat begin size ensure replace String nil end end
                                                    eval                                           self
                                                                                                    end
                                                    copyright MMX Yusuke Endoh             p String nil
Hello world with purely alphabet only
実装 internal
 • 自分で読んでください
  no time to explain; please read 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




                                                                            15
対「文字制約」まとめ
summary of anti-character constraints
  • Ruby は使用文字制約に結構強い
   Ruby beats 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
2. Ruby for Quine in ASCII-art


                                 17
Quine とは                What’s Quine?

• 自分自身を出力するプログラム                                 a program that outputs itself

       eval s="puts'eval s='+s.inspect"

• 実装の基本 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



                                                                           18
山手Quine   Yamanote Quine




              • 実行すると隣の駅名になる
               This program transforms the next 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
Yamanote Quine
実装 internal
 1. 自分自身を再構成する
   Step 1. construct a string that 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
                                                                          20
Yamanote Quine
アスキーアートでプログラムを書く
How to write “shaped” Ruby program
 1. 空白とバックスラッシュなしでプログラムを書く
       write your program with no space and backslash
 2. eval %w と ).join                         で囲む        enclose it
       ((
 3. 自由に整形できる                                              eval %w(
       you can shape it as you like
                                                          pu
                                                            ts
 • 注: %w() は文字列配列のリテラル                                        “H
     NOTE: %w() is a literal for Array
                                                                i”
 •    %w(foo bar)        =    [“foo”, “bar”]
                                                          ).join##



                                                                        21
Yamanote Quine
圧縮 compression
 • データサイズとデコーダサイズのトレードオフ
  trade off between compressed data size and its decoder size

 デコーダ小 shorter decoder                        データ小 shorter data
  データ大 longer data                           デコーダ大 longer decoder
 • 最適な圧縮方法はデータの規模によって変わる
  best decoder depends on data size
                                      data size (about)   decoder
                                      ~ 10 bytes          No compression
 • コルモゴロフ複雑性とか
  feel Kolmogorov complexity          ~ 100 bytes         String#to_i(36)

   – see Wikipedia                    ~ 500 bytes         Base64
                                      More                Zlib + pack



                                                                            22
15quzzle
 Quine でパネル移動後の盤面が出てくる
 This prints new board that space was moved to specified direction

                eval$s=%w[b=0   x40e1359a76cb   d8f2;i=(m=0.. 15).find{|i|1
                >b&m=15<<4*i}   ;t=m|n=m<<4*o   =("AdABrBlBAu A"=~/(.)#{ARG
                V*''}¥1/||04|   |0)-4;(n<1||n   >1<<64||[255< <12]&[t>>040|
                |___________2   |__________15   |___________8 |__________13

                |0,t>>16,t]!=   [])?t=0:i+=o;   ;s="eval$s=%%   w[b=0x%016x"%
                (b^=t.&b|m&b>   >o*4)+$s.gsub   (/(¥|_+¥d+)+/   ,'')[/;.*/]+"
                ]*''||0"<<92|   |1;z=s=s.scan   (/.{13}/);3.t   imes{|j|s[(i|
                |__________11   |__________12   |___________6   |___________7

                |0)/4*8+i+j*4   ,0]=m=(z=32.c   hr)*13};c=b;4   .times{puts((
                0..3.times{pu   ts((s.slice!(   0,4)*z).rstri   p)}).map{j=c%
                16;c/=16;;(0|   |0)<(j)?"|"+j   .to_s.rjust(1   2,"_"):m}*(z|
                |__________10   |___________9   |___________5   |___________3

                |0),z)};b==0x   fedcba9876543                   21&&("%b"%"1t
                v7c1th0wylel7   3ba35knw3t".t                   o_i(36)).tr("
                01",".#").sca   n(/.{25}/){pu                   ts$&}]*''||0¥
                |___________1   |__________14                   |___________4

                                                                                23
tic-tac-toe (○×ゲーム)
 (たぶん)世界初、思考ルーチン組み込み対戦型 Quine
 (maybe) the world’s first Quine with embedded AI




                                                    24
Quine Reversi
 思考ルーチン組み込み、勝たないと Quine してくれない
 Quine with embedded AI, it does Quine only when you win




                                                           25
Merry Quine-mas
 クリスマスソング演奏機能組み込み Quine
 Quine with wave composer (plays a song before printing itself)




                                                                  26
qng と qif
 画像自身を出力する画像
 images that draws a program that prints the image itself




             png




             gif


                                                            27
Quine relay
# ruby
l=92.chr;eval s="s=s.dump[r=1..-
2].gsub(/("+l*4+"){4,}(?!¥")/){|t|'¥"+l*%d+¥"'%(t.size/2)};5.times{s=s.dump[r]};puts¥"#
python¥¥nprint(¥¥¥"# perl¥¥¥¥nprint(¥¥¥¥¥¥¥"# lua"+l*4+"nprint("+l*7+"¥"(* ocaml
*)"+l*8+"nprint_endline"+l*15+"¥"-- haskell"+l*16+"nimport Data.List;import Data.Bits;import
Data.Char;main=putStrLn("+l*31+"¥"/* C */"+l*32+"n#include<stdio.h>"+l*32+"nint
main(void){char*s[501]={"+l*31+"¥"++intercalate"+l*31+"¥","+l*31+"¥"(c(tail(init(show("+l*31+"¥
"/* Java */"+l*32+"npublic class QuineRelay{public static void
main(String[]a){String[]s={"+l*31+"¥"++intercalate"+l*31+"¥","+l*31+"¥"(c("+l*31+"¥"brainfuck"+
l*64+"n++++++++[>++++<-]+++++++++>>++++++++++"+l*31+"¥"++(concat(snd(mapAccumL h
2("+l*31+"¥"110"+l*31+"¥"++g(length )++"+l*31+"¥"22111211100111112021111102011112120012"+l*31+"
¥"++concatMap("+l*32+"c->let d=ord c in if
d<11then"+l*31+"¥"21002"+l*31+"¥"else"+l*31+"¥"111"+l*31+"¥"++g++"+l*31+"¥"22102"+l*31+"¥")s++"
+l*31+"¥"21002111010120211222211211101000120211021120221102111000110120211202"+l*31+"¥"))))))++
"+l*31+"¥","+l*63+"¥""+l*64+"n"+l*63+"¥"};int
i=0;for(;i<94;i++)System.out.print(s[i]);}}"+l*31+"¥")))))++"+l*31+"¥",0};int
i=0;for(;s[i];i++)printf("+l*63+"¥"%s"+l*63+"¥",s[i]);puts("+l*63+"¥""+l*63+"¥");return
0;}"+l*31+"¥");c s=map("+l*32+"s-
>"+l*31+"¥""+l*63+"¥""+l*31+"¥"++s++"+l*31+"¥""+l*63+"¥""+l*31+"¥")(unfoldr t s);t[]=Nothing;t
s=Just(splitAt(if length s>w&&s!!w=='"+l*31+"¥"'then 501else w)s);w=500;f 0=Nothing;f
x=Just((if x`mod`2>0then '0'else '1'),x`div`2);g x= reverse (unfoldr f x);h p c=let d=ord c-
48in(d,replicate(abs(p-d))(if d<p then '<'else '>')++"+l*31+"¥"."+l*31+"¥");s="+l*31+"¥"#
ruby"+l*32+"n"+l*31+"¥"++"+l*31+"¥"l=92.chr;eval
s=¥"+(z=l*31)+¥"¥¥¥"¥"+s+z+¥"¥¥¥""+l*31+"¥"++"+l*31+"¥""+l*32+"n"+l*31+"¥""+l*15+"¥""+l*7+"¥")"
+l*4+"n¥¥¥¥¥¥¥")¥¥¥")¥"########### (c) Yusuke Endoh, 2009 ###########¥n"




                                                                                             28
Quine relay
 • このプログラムは、このプログラム自身を出力する
   Unlambda プログラム、を出力する Whitespace プログラ
   ム、を出力する brainfuck プログラム、を出力する 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
対「文字配置制約」まとめ
summary of anti-shape constraints
  • Ruby は文字配置制約+Quine に滅法強い
   Ruby beats shape constraints and Quine
     – あやしい言語機能に感謝                    thanks to weird language features
         • %w, %q
         • BEGIN
         • eval
     – 文字列整形も強い also useful methods for string shaping
         • String#rjust, split, gsub!, slice!, rstrip
         • to_i / to_s / Integer#[]
         • unpack / pack / zlib




                                                                          30
結論 conclusion
 • Why don’t you enjoy esolang with Ruby?
    – むだに深淵な背景理論 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
最後に aside
 • 来年 RubyKaigi 併設で IORCC やりたい
  I hope IORCC to be held in conjunction with the next RubyKaigi
   – International Obfuscated Ruby Code Contest



 __END__



                                                                   32
実行に 5 分かかる Quine
Quine that takes five minutes




                                33

More Related Content

What's hot

エンジニアの個人ブランディングと技術組織
エンジニアの個人ブランディングと技術組織エンジニアの個人ブランディングと技術組織
エンジニアの個人ブランディングと技術組織Takafumi ONAKA
 
[CEDEC 2021] 運用中タイトルでも怖くない! 『メルクストーリア』におけるハイパフォーマンス・ローコストなリアルタイム通信技術の導入事例
[CEDEC 2021] 運用中タイトルでも怖くない! 『メルクストーリア』におけるハイパフォーマンス・ローコストなリアルタイム通信技術の導入事例[CEDEC 2021] 運用中タイトルでも怖くない! 『メルクストーリア』におけるハイパフォーマンス・ローコストなリアルタイム通信技術の導入事例
[CEDEC 2021] 運用中タイトルでも怖くない! 『メルクストーリア』におけるハイパフォーマンス・ローコストなリアルタイム通信技術の導入事例Naoya Kishimoto
 
Where狙いのキー、order by狙いのキー
Where狙いのキー、order by狙いのキーWhere狙いのキー、order by狙いのキー
Where狙いのキー、order by狙いのキーyoku0825
 
初心者向け負荷軽減のはなし
初心者向け負荷軽減のはなし初心者向け負荷軽減のはなし
初心者向け負荷軽減のはなしOonishi Takaaki
 
Mercari JPのモノリスサービスをKubernetesに移行した話 PHP Conference 2022 9/24
Mercari JPのモノリスサービスをKubernetesに移行した話 PHP Conference 2022 9/24Mercari JPのモノリスサービスをKubernetesに移行した話 PHP Conference 2022 9/24
Mercari JPのモノリスサービスをKubernetesに移行した話 PHP Conference 2022 9/24Shin Ohno
 
MQTTとAMQPと.NET
MQTTとAMQPと.NETMQTTとAMQPと.NET
MQTTとAMQPと.NETterurou
 
Dockerを使ったローカルでの開発から本番環境へのデプロイまで
Dockerを使ったローカルでの開発から本番環境へのデプロイまでDockerを使ったローカルでの開発から本番環境へのデプロイまで
Dockerを使ったローカルでの開発から本番環境へのデプロイまでRyo Nakamaru
 
オブジェクト指向できていますか?
オブジェクト指向できていますか?オブジェクト指向できていますか?
オブジェクト指向できていますか?Moriharu Ohzu
 
Apache Kafka 0.11 の Exactly Once Semantics
Apache Kafka 0.11 の Exactly Once SemanticsApache Kafka 0.11 の Exactly Once Semantics
Apache Kafka 0.11 の Exactly Once SemanticsYoshiyasu SAEKI
 
なかったらINSERTしたいし、あるならロック取りたいやん?
なかったらINSERTしたいし、あるならロック取りたいやん?なかったらINSERTしたいし、あるならロック取りたいやん?
なかったらINSERTしたいし、あるならロック取りたいやん?ichirin2501
 
Dockerfile を書くためのベストプラクティス解説編
Dockerfile を書くためのベストプラクティス解説編Dockerfile を書くためのベストプラクティス解説編
Dockerfile を書くためのベストプラクティス解説編Masahito Zembutsu
 
「実践ドメイン駆動設計」 から理解するDDD (2018年11月)
「実践ドメイン駆動設計」 から理解するDDD (2018年11月)「実践ドメイン駆動設計」 から理解するDDD (2018年11月)
「実践ドメイン駆動設計」 から理解するDDD (2018年11月)A AOKI
 
Redisの特徴と活用方法について
Redisの特徴と活用方法についてRedisの特徴と活用方法について
Redisの特徴と活用方法についてYuji Otani
 
マイクロにしすぎた結果がこれだよ!
マイクロにしすぎた結果がこれだよ!マイクロにしすぎた結果がこれだよ!
マイクロにしすぎた結果がこれだよ!mosa siru
 
Dockerの期待と現実~Docker都市伝説はなぜ生まれるのか~
Dockerの期待と現実~Docker都市伝説はなぜ生まれるのか~Dockerの期待と現実~Docker都市伝説はなぜ生まれるのか~
Dockerの期待と現実~Docker都市伝説はなぜ生まれるのか~Masahito Zembutsu
 
ドメインオブジェクトの設計ガイドライン
ドメインオブジェクトの設計ガイドラインドメインオブジェクトの設計ガイドライン
ドメインオブジェクトの設計ガイドライン増田 亨
 
ストリーム処理を支えるキューイングシステムの選び方
ストリーム処理を支えるキューイングシステムの選び方ストリーム処理を支えるキューイングシステムの選び方
ストリーム処理を支えるキューイングシステムの選び方Yoshiyasu SAEKI
 
超絶技巧プログラミングの世界(FTD2015)
超絶技巧プログラミングの世界(FTD2015)超絶技巧プログラミングの世界(FTD2015)
超絶技巧プログラミングの世界(FTD2015)mametter
 

What's hot (20)

エンジニアの個人ブランディングと技術組織
エンジニアの個人ブランディングと技術組織エンジニアの個人ブランディングと技術組織
エンジニアの個人ブランディングと技術組織
 
[CEDEC 2021] 運用中タイトルでも怖くない! 『メルクストーリア』におけるハイパフォーマンス・ローコストなリアルタイム通信技術の導入事例
[CEDEC 2021] 運用中タイトルでも怖くない! 『メルクストーリア』におけるハイパフォーマンス・ローコストなリアルタイム通信技術の導入事例[CEDEC 2021] 運用中タイトルでも怖くない! 『メルクストーリア』におけるハイパフォーマンス・ローコストなリアルタイム通信技術の導入事例
[CEDEC 2021] 運用中タイトルでも怖くない! 『メルクストーリア』におけるハイパフォーマンス・ローコストなリアルタイム通信技術の導入事例
 
Where狙いのキー、order by狙いのキー
Where狙いのキー、order by狙いのキーWhere狙いのキー、order by狙いのキー
Where狙いのキー、order by狙いのキー
 
初心者向け負荷軽減のはなし
初心者向け負荷軽減のはなし初心者向け負荷軽減のはなし
初心者向け負荷軽減のはなし
 
Mercari JPのモノリスサービスをKubernetesに移行した話 PHP Conference 2022 9/24
Mercari JPのモノリスサービスをKubernetesに移行した話 PHP Conference 2022 9/24Mercari JPのモノリスサービスをKubernetesに移行した話 PHP Conference 2022 9/24
Mercari JPのモノリスサービスをKubernetesに移行した話 PHP Conference 2022 9/24
 
MQTTとAMQPと.NET
MQTTとAMQPと.NETMQTTとAMQPと.NET
MQTTとAMQPと.NET
 
Dockerを使ったローカルでの開発から本番環境へのデプロイまで
Dockerを使ったローカルでの開発から本番環境へのデプロイまでDockerを使ったローカルでの開発から本番環境へのデプロイまで
Dockerを使ったローカルでの開発から本番環境へのデプロイまで
 
オブジェクト指向できていますか?
オブジェクト指向できていますか?オブジェクト指向できていますか?
オブジェクト指向できていますか?
 
Apache Kafka 0.11 の Exactly Once Semantics
Apache Kafka 0.11 の Exactly Once SemanticsApache Kafka 0.11 の Exactly Once Semantics
Apache Kafka 0.11 の Exactly Once Semantics
 
なかったらINSERTしたいし、あるならロック取りたいやん?
なかったらINSERTしたいし、あるならロック取りたいやん?なかったらINSERTしたいし、あるならロック取りたいやん?
なかったらINSERTしたいし、あるならロック取りたいやん?
 
Dockerfile を書くためのベストプラクティス解説編
Dockerfile を書くためのベストプラクティス解説編Dockerfile を書くためのベストプラクティス解説編
Dockerfile を書くためのベストプラクティス解説編
 
Docker Compose 徹底解説
Docker Compose 徹底解説Docker Compose 徹底解説
Docker Compose 徹底解説
 
「実践ドメイン駆動設計」 から理解するDDD (2018年11月)
「実践ドメイン駆動設計」 から理解するDDD (2018年11月)「実践ドメイン駆動設計」 から理解するDDD (2018年11月)
「実践ドメイン駆動設計」 から理解するDDD (2018年11月)
 
Redisの特徴と活用方法について
Redisの特徴と活用方法についてRedisの特徴と活用方法について
Redisの特徴と活用方法について
 
マイクロにしすぎた結果がこれだよ!
マイクロにしすぎた結果がこれだよ!マイクロにしすぎた結果がこれだよ!
マイクロにしすぎた結果がこれだよ!
 
Dockerの期待と現実~Docker都市伝説はなぜ生まれるのか~
Dockerの期待と現実~Docker都市伝説はなぜ生まれるのか~Dockerの期待と現実~Docker都市伝説はなぜ生まれるのか~
Dockerの期待と現実~Docker都市伝説はなぜ生まれるのか~
 
ドメインオブジェクトの設計ガイドライン
ドメインオブジェクトの設計ガイドラインドメインオブジェクトの設計ガイドライン
ドメインオブジェクトの設計ガイドライン
 
ストリーム処理を支えるキューイングシステムの選び方
ストリーム処理を支えるキューイングシステムの選び方ストリーム処理を支えるキューイングシステムの選び方
ストリーム処理を支えるキューイングシステムの選び方
 
超絶技巧プログラミングの世界(FTD2015)
超絶技巧プログラミングの世界(FTD2015)超絶技巧プログラミングの世界(FTD2015)
超絶技巧プログラミングの世界(FTD2015)
 
Hadoop入門
Hadoop入門Hadoop入門
Hadoop入門
 

Viewers also liked

Quine・難解プログラミングについて
Quine・難解プログラミングについてQuine・難解プログラミングについて
Quine・難解プログラミングについてmametter
 
Optcarrot: A Pure-Ruby NES Emulator
Optcarrot: A Pure-Ruby NES EmulatorOptcarrot: A Pure-Ruby NES Emulator
Optcarrot: A Pure-Ruby NES Emulatormametter
 
Test Context Arrangement Recipebook
Test Context Arrangement RecipebookTest Context Arrangement Recipebook
Test Context Arrangement RecipebookKyosuke MOROHASHI
 
Rk10trailer
Rk10trailerRk10trailer
Rk10trailermseki
 
Highlights from ExL Pharma's 5th Data Monitoring Committees
Highlights from ExL Pharma's 5th Data Monitoring CommitteesHighlights from ExL Pharma's 5th Data Monitoring Committees
Highlights from ExL Pharma's 5th Data Monitoring CommitteesExL Pharma
 
Real-Time Coherence Monitoring in Integrated Environments
Real-Time Coherence Monitoring in Integrated EnvironmentsReal-Time Coherence Monitoring in Integrated Environments
Real-Time Coherence Monitoring in Integrated EnvironmentsSL Corporation
 
אקטיביזם תקשורתי וירטואלי2
אקטיביזם תקשורתי וירטואלי2אקטיביזם תקשורתי וירטואלי2
אקטיביזם תקשורתי וירטואלי2hagitmt
 
Pelota al cesto
Pelota al cestoPelota al cesto
Pelota al cestomaricel
 
2011 Kia Sorento For Sale at Keffer Kia in Charlotte, North Carolina
2011 Kia Sorento For Sale at Keffer Kia in Charlotte, North Carolina2011 Kia Sorento For Sale at Keffer Kia in Charlotte, North Carolina
2011 Kia Sorento For Sale at Keffer Kia in Charlotte, North CarolinaCourtney Boone
 
Cv100705
Cv100705Cv100705
Cv100705spears9
 
September 1 speech and writing
September 1 speech and writingSeptember 1 speech and writing
September 1 speech and writingJessica Visseau
 
2011 Eclipse For Sale at Keffer Mitsubishi, Charlotte North Carolina
2011 Eclipse For Sale at Keffer Mitsubishi, Charlotte North Carolina2011 Eclipse For Sale at Keffer Mitsubishi, Charlotte North Carolina
2011 Eclipse For Sale at Keffer Mitsubishi, Charlotte North CarolinaCourtney Boone
 
Epithelial tissue identification
Epithelial tissue identificationEpithelial tissue identification
Epithelial tissue identificationM. Carol Carlisle
 
Highlights from ExL Pharma's 2nd Digital Pharma Europe
Highlights from  ExL Pharma's 2nd Digital Pharma EuropeHighlights from  ExL Pharma's 2nd Digital Pharma Europe
Highlights from ExL Pharma's 2nd Digital Pharma EuropeExL Pharma
 

Viewers also liked (20)

Quine・難解プログラミングについて
Quine・難解プログラミングについてQuine・難解プログラミングについて
Quine・難解プログラミングについて
 
Optcarrot: A Pure-Ruby NES Emulator
Optcarrot: A Pure-Ruby NES EmulatorOptcarrot: A Pure-Ruby NES Emulator
Optcarrot: A Pure-Ruby NES Emulator
 
Test Context Arrangement Recipebook
Test Context Arrangement RecipebookTest Context Arrangement Recipebook
Test Context Arrangement Recipebook
 
Rk10trailer
Rk10trailerRk10trailer
Rk10trailer
 
Highlights from ExL Pharma's 5th Data Monitoring Committees
Highlights from ExL Pharma's 5th Data Monitoring CommitteesHighlights from ExL Pharma's 5th Data Monitoring Committees
Highlights from ExL Pharma's 5th Data Monitoring Committees
 
Real-Time Coherence Monitoring in Integrated Environments
Real-Time Coherence Monitoring in Integrated EnvironmentsReal-Time Coherence Monitoring in Integrated Environments
Real-Time Coherence Monitoring in Integrated Environments
 
אקטיביזם תקשורתי וירטואלי2
אקטיביזם תקשורתי וירטואלי2אקטיביזם תקשורתי וירטואלי2
אקטיביזם תקשורתי וירטואלי2
 
Urinary system
Urinary systemUrinary system
Urinary system
 
Pelota al cesto
Pelota al cestoPelota al cesto
Pelota al cesto
 
Conclusion
ConclusionConclusion
Conclusion
 
Footscray park
Footscray parkFootscray park
Footscray park
 
挪威的去機構化:過程、挑戰與因應
挪威的去機構化:過程、挑戰與因應挪威的去機構化:過程、挑戰與因應
挪威的去機構化:過程、挑戰與因應
 
2011 Kia Sorento For Sale at Keffer Kia in Charlotte, North Carolina
2011 Kia Sorento For Sale at Keffer Kia in Charlotte, North Carolina2011 Kia Sorento For Sale at Keffer Kia in Charlotte, North Carolina
2011 Kia Sorento For Sale at Keffer Kia in Charlotte, North Carolina
 
Cv100705
Cv100705Cv100705
Cv100705
 
Digestive system
Digestive systemDigestive system
Digestive system
 
September 1 speech and writing
September 1 speech and writingSeptember 1 speech and writing
September 1 speech and writing
 
2011 Eclipse For Sale at Keffer Mitsubishi, Charlotte North Carolina
2011 Eclipse For Sale at Keffer Mitsubishi, Charlotte North Carolina2011 Eclipse For Sale at Keffer Mitsubishi, Charlotte North Carolina
2011 Eclipse For Sale at Keffer Mitsubishi, Charlotte North Carolina
 
Greek Gods & Religion
Greek Gods & ReligionGreek Gods & Religion
Greek Gods & Religion
 
Epithelial tissue identification
Epithelial tissue identificationEpithelial tissue identification
Epithelial tissue identification
 
Highlights from ExL Pharma's 2nd Digital Pharma Europe
Highlights from  ExL Pharma's 2nd Digital Pharma EuropeHighlights from  ExL Pharma's 2nd Digital Pharma Europe
Highlights from ExL Pharma's 2nd Digital Pharma Europe
 

Similar to 超絶技巧 Ruby プログラミング - Esoteric, Obfuscated Ruby Programming

Kink: invokedynamic on a prototype-based language
Kink: invokedynamic on a prototype-based languageKink: invokedynamic on a prototype-based language
Kink: invokedynamic on a prototype-based languageTaku Miyakawa
 
Kink: プロトタイプベースの俺々 JVM 言語
Kink: プロトタイプベースの俺々 JVM 言語Kink: プロトタイプベースの俺々 JVM 言語
Kink: プロトタイプベースの俺々 JVM 言語Taku Miyakawa
 
ng-japan 2015 TypeScript+AngularJS 1.3
ng-japan 2015 TypeScript+AngularJS 1.3ng-japan 2015 TypeScript+AngularJS 1.3
ng-japan 2015 TypeScript+AngularJS 1.3Masahiro Wakame
 
Coq for Moblie Phone @ ML名古屋
Coq for Moblie Phone @ ML名古屋Coq for Moblie Phone @ ML名古屋
Coq for Moblie Phone @ ML名古屋Hiroki Mizuno
 
Cookpad 17 day Tech internship 2017 言語処理系入門 Rubyをコンパイルしよう
Cookpad 17 day Tech internship 2017 言語処理系入門 RubyをコンパイルしようCookpad 17 day Tech internship 2017 言語処理系入門 Rubyをコンパイルしよう
Cookpad 17 day Tech internship 2017 言語処理系入門 RubyをコンパイルしようKoichi Sasada
 
ちゃんとWeb会議スライド『Coffee script』
ちゃんとWeb会議スライド『Coffee script』ちゃんとWeb会議スライド『Coffee script』
ちゃんとWeb会議スライド『Coffee script』H2O Space. Co., Ltd.
 
コンパイルターゲット言語としてのWebAssembly、そしてLINEでの実践
コンパイルターゲット言語としてのWebAssembly、そしてLINEでの実践コンパイルターゲット言語としてのWebAssembly、そしてLINEでの実践
コンパイルターゲット言語としてのWebAssembly、そしてLINEでの実践LINE Corporation
 
もしも… Javaでヘテロジニアスコアが使えたら…
もしも… Javaでヘテロジニアスコアが使えたら…もしも… Javaでヘテロジニアスコアが使えたら…
もしも… Javaでヘテロジニアスコアが使えたら…Yasumasa Suenaga
 
中3女子でもわかる constexpr
中3女子でもわかる constexpr中3女子でもわかる constexpr
中3女子でもわかる constexprGenya Murakami
 
kyotolisp#1 LT3 美しいLispの書き方 (1)
kyotolisp#1 LT3 美しいLispの書き方 (1)kyotolisp#1 LT3 美しいLispの書き方 (1)
kyotolisp#1 LT3 美しいLispの書き方 (1)hayato_hashimoto
 
20130228 Goノススメ(BPStudy #66)
20130228 Goノススメ(BPStudy #66)20130228 Goノススメ(BPStudy #66)
20130228 Goノススメ(BPStudy #66)Yoshifumi Yamaguchi
 
Ruby を用いた超絶技巧プログラミング(夏のプログラミングシンポジウム 2012)
Ruby を用いた超絶技巧プログラミング(夏のプログラミングシンポジウム 2012)Ruby を用いた超絶技巧プログラミング(夏のプログラミングシンポジウム 2012)
Ruby を用いた超絶技巧プログラミング(夏のプログラミングシンポジウム 2012)mametter
 
C,Javaと比較しながらRubyに入門する話 - e-ZUKA Rails拡大号vol1
C,Javaと比較しながらRubyに入門する話 - e-ZUKA Rails拡大号vol1C,Javaと比較しながらRubyに入門する話 - e-ZUKA Rails拡大号vol1
C,Javaと比較しながらRubyに入門する話 - e-ZUKA Rails拡大号vol1耕平 谷口
 
中3女子が狂える本当に気持ちのいい constexpr
中3女子が狂える本当に気持ちのいい constexpr中3女子が狂える本当に気持ちのいい constexpr
中3女子が狂える本当に気持ちのいい constexprGenya Murakami
 
SSDとTokyoTyrantやMySQLの性能検証
SSDとTokyoTyrantやMySQLの性能検証SSDとTokyoTyrantやMySQLの性能検証
SSDとTokyoTyrantやMySQLの性能検証勲 國府田
 
Start!! Ruby
Start!! RubyStart!! Ruby
Start!! Rubymitim
 

Similar to 超絶技巧 Ruby プログラミング - Esoteric, Obfuscated Ruby Programming (20)

Kink: invokedynamic on a prototype-based language
Kink: invokedynamic on a prototype-based languageKink: invokedynamic on a prototype-based language
Kink: invokedynamic on a prototype-based language
 
Clojure
ClojureClojure
Clojure
 
詳解! Decimal
詳解! Decimal詳解! Decimal
詳解! Decimal
 
Kink: プロトタイプベースの俺々 JVM 言語
Kink: プロトタイプベースの俺々 JVM 言語Kink: プロトタイプベースの俺々 JVM 言語
Kink: プロトタイプベースの俺々 JVM 言語
 
ng-japan 2015 TypeScript+AngularJS 1.3
ng-japan 2015 TypeScript+AngularJS 1.3ng-japan 2015 TypeScript+AngularJS 1.3
ng-japan 2015 TypeScript+AngularJS 1.3
 
Coq for Moblie Phone @ ML名古屋
Coq for Moblie Phone @ ML名古屋Coq for Moblie Phone @ ML名古屋
Coq for Moblie Phone @ ML名古屋
 
Cookpad 17 day Tech internship 2017 言語処理系入門 Rubyをコンパイルしよう
Cookpad 17 day Tech internship 2017 言語処理系入門 RubyをコンパイルしようCookpad 17 day Tech internship 2017 言語処理系入門 Rubyをコンパイルしよう
Cookpad 17 day Tech internship 2017 言語処理系入門 Rubyをコンパイルしよう
 
ちゃんとWeb会議スライド『Coffee script』
ちゃんとWeb会議スライド『Coffee script』ちゃんとWeb会議スライド『Coffee script』
ちゃんとWeb会議スライド『Coffee script』
 
コンパイルターゲット言語としてのWebAssembly、そしてLINEでの実践
コンパイルターゲット言語としてのWebAssembly、そしてLINEでの実践コンパイルターゲット言語としてのWebAssembly、そしてLINEでの実践
コンパイルターゲット言語としてのWebAssembly、そしてLINEでの実践
 
もしも… Javaでヘテロジニアスコアが使えたら…
もしも… Javaでヘテロジニアスコアが使えたら…もしも… Javaでヘテロジニアスコアが使えたら…
もしも… Javaでヘテロジニアスコアが使えたら…
 
中3女子でもわかる constexpr
中3女子でもわかる constexpr中3女子でもわかる constexpr
中3女子でもわかる constexpr
 
kyotolisp#1 LT3 美しいLispの書き方 (1)
kyotolisp#1 LT3 美しいLispの書き方 (1)kyotolisp#1 LT3 美しいLispの書き方 (1)
kyotolisp#1 LT3 美しいLispの書き方 (1)
 
20130228 Goノススメ(BPStudy #66)
20130228 Goノススメ(BPStudy #66)20130228 Goノススメ(BPStudy #66)
20130228 Goノススメ(BPStudy #66)
 
Ruby を用いた超絶技巧プログラミング(夏のプログラミングシンポジウム 2012)
Ruby を用いた超絶技巧プログラミング(夏のプログラミングシンポジウム 2012)Ruby を用いた超絶技巧プログラミング(夏のプログラミングシンポジウム 2012)
Ruby を用いた超絶技巧プログラミング(夏のプログラミングシンポジウム 2012)
 
Kotlin
KotlinKotlin
Kotlin
 
C,Javaと比較しながらRubyに入門する話 - e-ZUKA Rails拡大号vol1
C,Javaと比較しながらRubyに入門する話 - e-ZUKA Rails拡大号vol1C,Javaと比較しながらRubyに入門する話 - e-ZUKA Rails拡大号vol1
C,Javaと比較しながらRubyに入門する話 - e-ZUKA Rails拡大号vol1
 
中3女子が狂える本当に気持ちのいい constexpr
中3女子が狂える本当に気持ちのいい constexpr中3女子が狂える本当に気持ちのいい constexpr
中3女子が狂える本当に気持ちのいい constexpr
 
SSDとTokyoTyrantやMySQLの性能検証
SSDとTokyoTyrantやMySQLの性能検証SSDとTokyoTyrantやMySQLの性能検証
SSDとTokyoTyrantやMySQLの性能検証
 
Start!! Ruby
Start!! RubyStart!! Ruby
Start!! Ruby
 
Vert.x.tari.tari
Vert.x.tari.tariVert.x.tari.tari
Vert.x.tari.tari
 

More from mametter

error_highlight: User-friendly Error Diagnostics
error_highlight: User-friendly Error Diagnosticserror_highlight: User-friendly Error Diagnostics
error_highlight: User-friendly Error Diagnosticsmametter
 
クックパッド春の超絶技巧パンまつり 超絶技巧プログラミング編 資料
クックパッド春の超絶技巧パンまつり 超絶技巧プログラミング編 資料クックパッド春の超絶技巧パンまつり 超絶技巧プログラミング編 資料
クックパッド春の超絶技巧パンまつり 超絶技巧プログラミング編 資料mametter
 
Enjoy Ruby Programming in IDE and TypeProf
Enjoy Ruby Programming in IDE and TypeProfEnjoy Ruby Programming in IDE and TypeProf
Enjoy Ruby Programming in IDE and TypeProfmametter
 
TypeProf for IDE: Enrich Development Experience without Annotations
TypeProf for IDE: Enrich Development Experience without AnnotationsTypeProf for IDE: Enrich Development Experience without Annotations
TypeProf for IDE: Enrich Development Experience without Annotationsmametter
 
Ruby 3の型解析に向けた計画
Ruby 3の型解析に向けた計画Ruby 3の型解析に向けた計画
Ruby 3の型解析に向けた計画mametter
 
emruby: ブラウザで動くRuby
emruby: ブラウザで動くRubyemruby: ブラウザで動くRuby
emruby: ブラウザで動くRubymametter
 
Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3mametter
 
型プロファイラ:抽象解釈に基づくRuby 3の静的解析
型プロファイラ:抽象解釈に基づくRuby 3の静的解析型プロファイラ:抽象解釈に基づくRuby 3の静的解析
型プロファイラ:抽象解釈に基づくRuby 3の静的解析mametter
 
Ruby 3の型推論やってます
Ruby 3の型推論やってますRuby 3の型推論やってます
Ruby 3の型推論やってますmametter
 
マニアックなRuby 2.7新機能紹介
マニアックなRuby 2.7新機能紹介マニアックなRuby 2.7新機能紹介
マニアックなRuby 2.7新機能紹介mametter
 
A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3mametter
 
A Plan towards Ruby 3 Types
A Plan towards Ruby 3 TypesA Plan towards Ruby 3 Types
A Plan towards Ruby 3 Typesmametter
 
Ruby 3 の型解析に向けた計画
Ruby 3 の型解析に向けた計画Ruby 3 の型解析に向けた計画
Ruby 3 の型解析に向けた計画mametter
 
A Type-level Ruby Interpreter for Testing and Understanding
A Type-level Ruby Interpreter for Testing and UnderstandingA Type-level Ruby Interpreter for Testing and Understanding
A Type-level Ruby Interpreter for Testing and Understandingmametter
 
本番環境で使える実行コード記録機能
本番環境で使える実行コード記録機能本番環境で使える実行コード記録機能
本番環境で使える実行コード記録機能mametter
 
Transcendental Programming in Ruby
Transcendental Programming in RubyTranscendental Programming in Ruby
Transcendental Programming in Rubymametter
 
Cookpad Hackarade #04: Create Your Own Interpreter
Cookpad Hackarade #04: Create Your Own InterpreterCookpad Hackarade #04: Create Your Own Interpreter
Cookpad Hackarade #04: Create Your Own Interpretermametter
 
Ruby 3のキーワード引数について考える
Ruby 3のキーワード引数について考えるRuby 3のキーワード引数について考える
Ruby 3のキーワード引数について考えるmametter
 
TRICK 2018 results
TRICK 2018 resultsTRICK 2018 results
TRICK 2018 resultsmametter
 
Type Profiler: An Analysis to guess type signatures
Type Profiler: An Analysis to guess type signaturesType Profiler: An Analysis to guess type signatures
Type Profiler: An Analysis to guess type signaturesmametter
 

More from mametter (20)

error_highlight: User-friendly Error Diagnostics
error_highlight: User-friendly Error Diagnosticserror_highlight: User-friendly Error Diagnostics
error_highlight: User-friendly Error Diagnostics
 
クックパッド春の超絶技巧パンまつり 超絶技巧プログラミング編 資料
クックパッド春の超絶技巧パンまつり 超絶技巧プログラミング編 資料クックパッド春の超絶技巧パンまつり 超絶技巧プログラミング編 資料
クックパッド春の超絶技巧パンまつり 超絶技巧プログラミング編 資料
 
Enjoy Ruby Programming in IDE and TypeProf
Enjoy Ruby Programming in IDE and TypeProfEnjoy Ruby Programming in IDE and TypeProf
Enjoy Ruby Programming in IDE and TypeProf
 
TypeProf for IDE: Enrich Development Experience without Annotations
TypeProf for IDE: Enrich Development Experience without AnnotationsTypeProf for IDE: Enrich Development Experience without Annotations
TypeProf for IDE: Enrich Development Experience without Annotations
 
Ruby 3の型解析に向けた計画
Ruby 3の型解析に向けた計画Ruby 3の型解析に向けた計画
Ruby 3の型解析に向けた計画
 
emruby: ブラウザで動くRuby
emruby: ブラウザで動くRubyemruby: ブラウザで動くRuby
emruby: ブラウザで動くRuby
 
Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3
 
型プロファイラ:抽象解釈に基づくRuby 3の静的解析
型プロファイラ:抽象解釈に基づくRuby 3の静的解析型プロファイラ:抽象解釈に基づくRuby 3の静的解析
型プロファイラ:抽象解釈に基づくRuby 3の静的解析
 
Ruby 3の型推論やってます
Ruby 3の型推論やってますRuby 3の型推論やってます
Ruby 3の型推論やってます
 
マニアックなRuby 2.7新機能紹介
マニアックなRuby 2.7新機能紹介マニアックなRuby 2.7新機能紹介
マニアックなRuby 2.7新機能紹介
 
A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3
 
A Plan towards Ruby 3 Types
A Plan towards Ruby 3 TypesA Plan towards Ruby 3 Types
A Plan towards Ruby 3 Types
 
Ruby 3 の型解析に向けた計画
Ruby 3 の型解析に向けた計画Ruby 3 の型解析に向けた計画
Ruby 3 の型解析に向けた計画
 
A Type-level Ruby Interpreter for Testing and Understanding
A Type-level Ruby Interpreter for Testing and UnderstandingA Type-level Ruby Interpreter for Testing and Understanding
A Type-level Ruby Interpreter for Testing and Understanding
 
本番環境で使える実行コード記録機能
本番環境で使える実行コード記録機能本番環境で使える実行コード記録機能
本番環境で使える実行コード記録機能
 
Transcendental Programming in Ruby
Transcendental Programming in RubyTranscendental Programming in Ruby
Transcendental Programming in Ruby
 
Cookpad Hackarade #04: Create Your Own Interpreter
Cookpad Hackarade #04: Create Your Own InterpreterCookpad Hackarade #04: Create Your Own Interpreter
Cookpad Hackarade #04: Create Your Own Interpreter
 
Ruby 3のキーワード引数について考える
Ruby 3のキーワード引数について考えるRuby 3のキーワード引数について考える
Ruby 3のキーワード引数について考える
 
TRICK 2018 results
TRICK 2018 resultsTRICK 2018 results
TRICK 2018 results
 
Type Profiler: An Analysis to guess type signatures
Type Profiler: An Analysis to guess type signaturesType Profiler: An Analysis to guess type signatures
Type Profiler: An Analysis to guess type signatures
 

超絶技巧 Ruby プログラミング - Esoteric, Obfuscated Ruby Programming

  • 1. 超絶技巧 Ruby Programming Esoteric, Obfuscated Ruby Programming 遠藤侑介 Yusuke Endoh
  • 2. Who am I? • Yusuke Endoh 遠藤侑介 – twitter: @mametter – 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
  • 3. Esoteric Programming • 普通の人 normal programmer puts “Hello, world!” • Esoteric Programmer alias|send¥ ;$stdin=GC | "%p?"%def# FALSE.gets();(8 | 64).chr+232424. to_s(25)+", "+%w|w ! | *"orlc". next<<012|| (c).Yusuke end;"oh, 2009" | "stegano-X."[0,4].reverse d,be="whydoes","crypto";:make. | %.mains..tr'eams',be.delete(d) • 参考: ゴルファー cf. code-golfer (14B) #!../s/grb -eh http://d.hatena.ne.jp/kurimura/20090929/1254257912 3
  • 4. Esoteric Programming Language (esolang) • 読み書きしにくいように作られた言語 obfuscated, confusing and unreadable programming language – esoteric: 難解な、深遠な、秘伝的な、奥義に達した – ex) brainf**k +++++++++[>++++++++>++++++++++ +>+++++<<<]>.>++.+++++++..+++. >-.------------.<++++++++.---- ----.+++.------.--------.>+. • 共通の特徴:奇妙な制約 Hello world in brainf**k common feature: bizarre constraint – 使える文字 bizarre kind of character used – 使える命令 bizarre instruction set – 命令順序や文字配置 bizarre execution order and placement 4
  • 5. Theme: Enjoy esolang with Ruby! • 制約を課せば Ruby も esolang として楽しめる Ruby with constraint can be an esolang – 1. 使用文字制約に勝つ ( ○○文字だけで Ruby を書けるか?) beat “character constraints” (Can you write Ruby with __ character-only?) – 2. 文字配置制約に勝つ (アスキーアート Quine) beat “shape constraints” (ASCII-art Quine) • 見所 Highlights • ゲーデル数 Gödel numbering – むだに深淵な背景理論 • コルモゴロフ複雑性 Kolmogorov complexity esoteric theory • チューリング完全性 Turing completeness – 勝つためなら何でもする • Ruby の黒魔術 Ruby’s black magic • コードゴルフ code golf dirty hack • 文法や意味論の悪用 abuse of syntax/semantics 5
  • 6. 1. Hello world with __ Character- only 6
  • 7. Hello world with Number only require "1234567890" 316805813369061470447252554255354 816767578747985092956934801232229 450578663292118901228453190669621 8369564670777459615871118090530  任意のプログラムが書けます you can write not only “Hello, world!” but also any program 7
  • 8. Hello world with number only 実装 internal • ゲーデル数化 Encoding: Gödel numbering • Ruby の黒魔術 Ruby’s black magic • you can install: gem install 1234567890_ 8
  • 9. Hello world with number only ゲーデル数による符号化 Gödel numbering 9
  • 10. Hello world with number only 黒魔術 Ruby’s black magic • コードに書かれただけの数字の参照を引っぱり出す How to gain number 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 10
  • 11. Hello, world with underscore only require "_" ____ _ _____ ____ __ ____ ____ __ ___ ____ __ __ _ ______ _____ ___ _ _ ___ _____ ______ ____ _ _ ____ _ _ ____ _ ____ __ __ ___ _ ______ ___ ____ __ ______ ____ _ ____ ____ __ _ ____ _ _ ___ _____ _____ _ ______ ____ _ ______ _____ 11
  • 12. Hello world with underscore only 実装 internal • プログラムのゲーデル数化 (“number only” と同じ) also uses Gödel 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 _ 12
  • 13. Hello world with underscore only なぜ 6 進数?why base-6? 13
  • 14. class String def inspect concat begin dup ensure replace String nil concat concat concat concat size concat concat size concat concat size concat size concat begin size ensure replace String nil end end Hello world with purely Alphabet only concat begin dup ensure replace String nil concat concat concat concat concat concat size concat size concat begin size ensure replace String nil end end concat begin dup ensure replace String nil concat concat size concat concat concat concat size concat concat concat size concat begin size ensure replace String nil end end concat begin dup ensure replace String nil concat concat size concat concat concat size concat concat size class String concat concat concat begin concat concat dup ensure replace String concat concat size concat begin size ensure replace String nil end end concat nil size size concat concat concat concat size def inspect concat concat concat concat begin concat dup ensure replace String concat concat concat size concat begin size ensure replace String nil end end nil size size concat concat size concat begin dup ensure replace String nil concat concat concat concat concat size size size concat begin size ensure replace String nil end end concat begin dup ensure replace String nil concat concat size concat concat concat concat size concat concat concat concat concat concat concat concat concat concat size size size size size concat begin size ensure replace String nil end end concat concat size concat begin dup ensure replace String concat concat concat concat concat concat size nil concat begin size ensure replace String nil end end concat concat begin dup ensure replace String concat concat nil size concat concat size concat concat size concat concat concat begin concat concat dup ensure replace String concat concat concat size concat begin size ensure replace String nil end end concat nil size size concat concat size concat size concat concat concat concat begin concat concat dup ensure replace String size size size concat begin size ensure replace String nil end end nil concat concat size concat begin size ensure replace String nil end end concat concat concat concat concat concat concat concat size size size concat begin size ensure replace String nil end end concat begin dup ensure replace String nil concat concat size concat begin dup ensure replace String nil concat concat concat concat concat concat concat concat size size size concat begin size ensure replace String nil end end concat begin dup ensure replace String nil concat concat size concat concat concat concat concat concat size concat concat concat concat concat concat concat concat size size size concat begin size ensure replace String nil end end concat begin dup ensure replace String nil concat concat concat concat size concat size concat concat concat concat concat concat dup ensure replace String concat concat concat concat size concat begin size ensure replace String nil end end concat begin nil size size concat concat size concat begin size ensure replace String nil end end concat begin dup ensure replace String concat concat concat concat concat concat size size concat begin size ensure replace String nil end end concat nil concat begin size ensure replace String nil end end concat begin dup ensure replace String nil concat concat size • require がない concat concat size concat concat concat concat size concat concat size concat size concat begin size ensure replace String nil end end concat begin dup ensure replace String nil concat concat size concat concat size there is no “require” concat concat concat size concat concat concat size concat begin size ensure replace String nil end end concat begin dup ensure replace String nil concat concat size concat concat size concat concat concat size concat concat concat size concat size concat begin size ensure replace String nil end end concat begin dup ensure replace String nil concat concat size concat concat size concat concat concat concat concat size exit end 14 concat begin size ensure replace String nil end end eval self end copyright MMX Yusuke Endoh p String nil
  • 15. Hello world with purely alphabet only 実装 internal • 自分で読んでください no time to explain; please read 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 15
  • 16. 対「文字制約」まとめ summary of anti-character constraints • Ruby は使用文字制約に結構強い Ruby beats 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
  • 17. 2. Ruby for Quine in ASCII-art 17
  • 18. Quine とは What’s Quine? • 自分自身を出力するプログラム a program that outputs itself eval s="puts'eval s='+s.inspect" • 実装の基本 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 18
  • 19. 山手Quine Yamanote Quine • 実行すると隣の駅名になる This program transforms the next 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
  • 20. Yamanote Quine 実装 internal 1. 自分自身を再構成する Step 1. construct a string that 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 20
  • 21. Yamanote Quine アスキーアートでプログラムを書く How to write “shaped” Ruby program 1. 空白とバックスラッシュなしでプログラムを書く write your program with no space and backslash 2. eval %w と ).join で囲む enclose it (( 3. 自由に整形できる eval %w( you can shape it as you like pu ts • 注: %w() は文字列配列のリテラル “H NOTE: %w() is a literal for Array i” • %w(foo bar) = [“foo”, “bar”] ).join## 21
  • 22. Yamanote Quine 圧縮 compression • データサイズとデコーダサイズのトレードオフ trade off between compressed data size and its decoder size デコーダ小 shorter decoder データ小 shorter data データ大 longer data デコーダ大 longer decoder • 最適な圧縮方法はデータの規模によって変わる best decoder depends on data size data size (about) decoder ~ 10 bytes No compression • コルモゴロフ複雑性とか feel Kolmogorov complexity ~ 100 bytes String#to_i(36) – see Wikipedia ~ 500 bytes Base64 More Zlib + pack 22
  • 23. 15quzzle Quine でパネル移動後の盤面が出てくる This prints new board that space was moved to specified direction eval$s=%w[b=0 x40e1359a76cb d8f2;i=(m=0.. 15).find{|i|1 >b&m=15<<4*i} ;t=m|n=m<<4*o =("AdABrBlBAu A"=~/(.)#{ARG V*''}¥1/||04| |0)-4;(n<1||n >1<<64||[255< <12]&[t>>040| |___________2 |__________15 |___________8 |__________13 |0,t>>16,t]!= [])?t=0:i+=o; ;s="eval$s=%% w[b=0x%016x"% (b^=t.&b|m&b> >o*4)+$s.gsub (/(¥|_+¥d+)+/ ,'')[/;.*/]+" ]*''||0"<<92| |1;z=s=s.scan (/.{13}/);3.t imes{|j|s[(i| |__________11 |__________12 |___________6 |___________7 |0)/4*8+i+j*4 ,0]=m=(z=32.c hr)*13};c=b;4 .times{puts(( 0..3.times{pu ts((s.slice!( 0,4)*z).rstri p)}).map{j=c% 16;c/=16;;(0| |0)<(j)?"|"+j .to_s.rjust(1 2,"_"):m}*(z| |__________10 |___________9 |___________5 |___________3 |0),z)};b==0x fedcba9876543 21&&("%b"%"1t v7c1th0wylel7 3ba35knw3t".t o_i(36)).tr(" 01",".#").sca n(/.{25}/){pu ts$&}]*''||0¥ |___________1 |__________14 |___________4 23
  • 25. Quine Reversi 思考ルーチン組み込み、勝たないと Quine してくれない Quine with embedded AI, it does Quine only when you win 25
  • 26. Merry Quine-mas クリスマスソング演奏機能組み込み Quine Quine with wave composer (plays a song before printing itself) 26
  • 27. qng と qif 画像自身を出力する画像 images that draws a program that prints the image itself png gif 27
  • 28. Quine relay # ruby l=92.chr;eval s="s=s.dump[r=1..- 2].gsub(/("+l*4+"){4,}(?!¥")/){|t|'¥"+l*%d+¥"'%(t.size/2)};5.times{s=s.dump[r]};puts¥"# python¥¥nprint(¥¥¥"# perl¥¥¥¥nprint(¥¥¥¥¥¥¥"# lua"+l*4+"nprint("+l*7+"¥"(* ocaml *)"+l*8+"nprint_endline"+l*15+"¥"-- haskell"+l*16+"nimport Data.List;import Data.Bits;import Data.Char;main=putStrLn("+l*31+"¥"/* C */"+l*32+"n#include<stdio.h>"+l*32+"nint main(void){char*s[501]={"+l*31+"¥"++intercalate"+l*31+"¥","+l*31+"¥"(c(tail(init(show("+l*31+"¥ "/* Java */"+l*32+"npublic class QuineRelay{public static void main(String[]a){String[]s={"+l*31+"¥"++intercalate"+l*31+"¥","+l*31+"¥"(c("+l*31+"¥"brainfuck"+ l*64+"n++++++++[>++++<-]+++++++++>>++++++++++"+l*31+"¥"++(concat(snd(mapAccumL h 2("+l*31+"¥"110"+l*31+"¥"++g(length )++"+l*31+"¥"22111211100111112021111102011112120012"+l*31+" ¥"++concatMap("+l*32+"c->let d=ord c in if d<11then"+l*31+"¥"21002"+l*31+"¥"else"+l*31+"¥"111"+l*31+"¥"++g++"+l*31+"¥"22102"+l*31+"¥")s++" +l*31+"¥"21002111010120211222211211101000120211021120221102111000110120211202"+l*31+"¥"))))))++ "+l*31+"¥","+l*63+"¥""+l*64+"n"+l*63+"¥"};int i=0;for(;i<94;i++)System.out.print(s[i]);}}"+l*31+"¥")))))++"+l*31+"¥",0};int i=0;for(;s[i];i++)printf("+l*63+"¥"%s"+l*63+"¥",s[i]);puts("+l*63+"¥""+l*63+"¥");return 0;}"+l*31+"¥");c s=map("+l*32+"s- >"+l*31+"¥""+l*63+"¥""+l*31+"¥"++s++"+l*31+"¥""+l*63+"¥""+l*31+"¥")(unfoldr t s);t[]=Nothing;t s=Just(splitAt(if length s>w&&s!!w=='"+l*31+"¥"'then 501else w)s);w=500;f 0=Nothing;f x=Just((if x`mod`2>0then '0'else '1'),x`div`2);g x= reverse (unfoldr f x);h p c=let d=ord c- 48in(d,replicate(abs(p-d))(if d<p then '<'else '>')++"+l*31+"¥"."+l*31+"¥");s="+l*31+"¥"# ruby"+l*32+"n"+l*31+"¥"++"+l*31+"¥"l=92.chr;eval s=¥"+(z=l*31)+¥"¥¥¥"¥"+s+z+¥"¥¥¥""+l*31+"¥"++"+l*31+"¥""+l*32+"n"+l*31+"¥""+l*15+"¥""+l*7+"¥")" +l*4+"n¥¥¥¥¥¥¥")¥¥¥")¥"########### (c) Yusuke Endoh, 2009 ###########¥n" 28
  • 29. Quine relay • このプログラムは、このプログラム自身を出力する Unlambda プログラム、を出力する Whitespace プログラ ム、を出力する brainfuck プログラム、を出力する 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
  • 30. 対「文字配置制約」まとめ summary of anti-shape constraints • Ruby は文字配置制約+Quine に滅法強い Ruby beats shape constraints and Quine – あやしい言語機能に感謝 thanks to weird language features • %w, %q • BEGIN • eval – 文字列整形も強い also useful methods for string shaping • String#rjust, split, gsub!, slice!, rstrip • to_i / to_s / Integer#[] • unpack / pack / zlib 30
  • 31. 結論 conclusion • Why don’t you enjoy esolang with Ruby? – むだに深淵な背景理論 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
  • 32. 最後に aside • 来年 RubyKaigi 併設で IORCC やりたい I hope IORCC to be held in conjunction with the next RubyKaigi – International Obfuscated Ruby Code Contest __END__ 32
  • 33. 実行に 5 分かかる Quine Quine that takes five minutes 33