The winning entry titled "Most competitive" leverages complex Ruby tricks to obfuscate a program that evaluates itself. It uses techniques like dynamically generating code strings, manipulating character encodings, and exploiting edge cases in Ruby's parsing and evaluation rules. The goal is to demonstrate both the robustness of Ruby interpreters in running such esoteric code, as well as uncover subtle aspects of Ruby's specification and implementation. The judges awarded it high honors for achieving the contest's goals of producing transcendental, imbroglio code.
2. What’s “TRICK”
• A contest for esoteric Ruby programming
Ruby で変態度を競い合うプログラミングの祭典
cf. International Obfuscated C Code Contest (IOCCC)
• This talk dishonors the winners of TRICK 2013
本発表では TRICK 2013 入賞者の不名誉を讃え
• And demonstrates the winning entries
さらに入賞作品のデモを紹介します
4. What “TRICK” means
Transcendental Ruby Imbroglio Contest for RubyKaigi
• Transcendental /ˌtransɛnˈdɛnt(ə)l/
– “relating to a spiritual realm”
「霊界に関する」
– but it is translated as “unworldly technical” in Japanese
なぜか日本語では「超絶技巧」と訳される
• ex. Transcendental Etudes (超絶技巧練習曲、Liszt)
• Imbroglio /ɪmˈbrəʊlɪəʊ/
– “an extremely confused, complicated, or embarrassing
situation”
極めて混乱した、複雑で、厄介な事態 adapted from
Oxford Dictionaries Online
Named by leonid
5. Goals of the TRICK
• Write the most Transcendental, Imbroglio Ruby program
現世利益のない、意味不明な Ruby プログラムを書く
• Illustrate some of the subtleties (and design issues) of
Ruby
Ruby のある種の神秘性 (と仕様バグ) を明らかにする
• Show the robustness and portability of Ruby interpreters
Ruby 処理系の意外な堅牢性と移植性を示す
• Stabilize the spec of Ruby by the presence of valuable but
unmaintainable code
メンテナンス不能だが価値あるコードを世に放つことで Ruby の仕様を
安定化する
6. Related Contests
• IOCCC: International Obfuscated C Code Contest
• UCC: Underhanded C Contest
• OPC: Obfuscated Perl Contest
• IORCC: International Obfuscated Ruby Code Contest
1990 1995 2000 2005 2010 2013
C
Perl
Ruby
1985
IOCCC 1984-2006 2011 2012
UCC 2005-2009 2013
OPC 1996-2000
IORCC 2005 2012?
TRICK
2013
7. TRICK Contest Rules (1)
1. Your entry must be a complete Ruby program.
あなたの作品は単体で動作する Ruby プログラムでなければならない。
2. The size of your program must be <= 4096 bytes in
length. The number of non-space characters must be <=
2048. The total size of your compressed submission
must be less than ten megabyte in size.
あなたのプログラムのサイズは 4096 バイト以下でなければならない。非
空白文字の数は 2048 以下でなければならない。あなたの投稿は zip
全体で 10 MB 未満でなければならない。
3. You can submit multiple entries, and your team may
consist of any number of members.
あなたは何作でも作品を投稿できる、また、あなたのチームは何人で
あっても良い。
8. TRICK Contest Rules (2)
4. The entirety of your entry must be submitted under
MIT License.
あなたの作品全体は MIT ライセンスで投稿されなければならない。
5. Your entry must bring the judges a surprise,
excitement, and/or laughter.
あなたの作品は審査員に驚き、感動、(and/or)笑いを与えなければなら
ない。
• Meta Rule: Rule Golf
– Too many restrictions may inhibit creativity
あれこれ制約して作品の可能性を絞らないように
9. Guidelines (1): Ruby version/impl.
• Matz Ruby Implementation (MRI) 1.9/2.0 is
recommended.
MRI 1.9/2.0 で動くことを推奨
• MRI 1.8 is highly discouraged because your entry
won't work in near future.
1.8 でしか動かないコードは強く非推奨
• You can use implementations other than MRI, such as
JRuby and Rubinius.
MRI 以外の実装もOK
10. Guidelines (2): Library
• You can require a gem library.
gem 使って OK
• But note that we will expect such entries to be much
more interesting than an entry that uses no library;
hence we will judge them strictly.
ただしその分面白い作品であることが期待され、審査基準は厳しくなる
• It is highly discouraged to abuse gem to get around
the size limit.
サイズ制限を回避するために gem を使うのは強く非推奨
11. Guidelines (3): Misc.
• The judges would prefer more stoic, more portable,
and/or more funny entries.
ストイックで、様々な環境で動き、笑いのある作品が評価されやすい
• You are encouraged to examine the winners of
previous IOCCC contests.
過去の IOCCC の勝者を研究することを推奨する
• To judge without bias, we will try to keep each entry
anonymous during judgment. Do not include
anything that reveal your identity (such as a signature,
copyright, URL, etc.) in your program.
偏見なく審査できるよう、審査の間はすべての作品を匿名として扱うので、
プログラムに作者がわかるような情報を含めないこと
12. Judges
Yusuke Endoh (@mametter)
Koichiro Eto (@eto)
Shinichiro Hamaji (@shinh)
Yutaka Hara (@yhara)
Yukihiro Matsumoto (@yukihiro_matz)
Sun Park a.k.a. leonid
Hirofumi Watanabe (@eban)
13. Judges
• mame
• eto
• shinh
• yhara
• matz
• leonid
• eban
– IOCCC winner
– Advocate for Transcendental programming.
– Media Artist.
– Chairman at NicoNicoGakkai Beta.
– The admin of anarchy golf.
– IOCCC winner.
– The author of Japanese esolang book.
– The creator of Ruby.
– The 1st super Ruby golfer in the anarchy golf.
– Ruby committer.
– The 2nd super Ruby golfer in the anarchy golf.
16. PR: Yutaka Hara (@yhara)
• 「Rubyで作る奇妙な
プログラミング言語」
Making Esoteric
Language with Ruby
• 2013年秋~冬
電子化(+復刻!?)予定
17. Judging process
• Each judge scores each entry on 10 point scale
各審査員は各作品を 10 点満点で評価
– Each entry gains the average
平均点がスコア
• A judge has no right to score his own entry
自分の作品は審査対象外
• Judges keep each entry anonymous during judgment
審査員は作者を知らずに審査する
19. Summary
• 10 winning entries
入賞作品数: 10
– including “Top Four” for particularly high dishonors
上位4作品は特に不名誉を受ける
• Winning entries will be pushed automatically
入賞作品は時間になったら push されます
http://github.com/tric /trick2013/
Dishonorable
mention
No k!
20. “Good way to make programs
wonderful”
Winner:
mame leonid yhara eban shinh eto matz
4 6 6 5 6 5 6
baban
5.43
14:45:00 ← push 予定時刻
21. “Good way to make programs
wonderful”
CONTEXT=->{
Alice.in.wonderland._
__
Alice.was.beginning_to.get.very._tired.of.
her.sitting.by.her.sister.on.the.bank,
and_.of.having.nothing.to.do,
once.or.twice.she.had.peeped.into.the.
book.her.sister.was.reading
...
22. “Good way to make programs
wonderful” – spoiler
• Main trick: method_missing
• Eye-catching feature: Character status
----------------------------------------
character status
----------------------------------------
Alice : tired line:5
Alice : hear line:14
Alice : feet line:19
Alice : pop_down line:21
WhiteRabbit : ran line:12
WhiteRabbit : say line:15
29. “Ruby by Ruby for Ruby award” –
spoiler
• Main trick: aliasing
• Extra tricks:
– A method name “ruby” and variable name “ruby” coexist
– Dynamic typing hell
alias RUBY inject; alias _Ruby join; end
class Fixnum; alias ruby chr; end
class Symbol; alias ruby to_s; end
class String; alias ruby chars; end
class Enumerator; alias ruby with_index; end
class Class; alias ruby new; end
alias ruby puts
30. “Worst house of garbage”
Winner:
mame leonid yhara eban shinh eto matz
7 7 8 3 2 8 9
Nakamura Narihiro
6.29
14:55:30 ← push 予定時刻
31. “Worst house of garbage”
GC.disable
Tape = ObjectSpace
Omitted because of normal appearance
見た目はつまんないので省略
Just a brainfuck interpreter, but…
ただの brainfuck インタプリタです、が
32. “Worst house of garbage” – spoiler
• Main trick: abuse of ObjectSpace.each_object
• By exploiting this infinite loop, a brainfuck interpreter
is constructed
この無限ループを利用して brainfuck 評価器を構成している
• Extra trick: history option
obj
yield!
object space
obj obj
new
obj
new
obj
yield! yield! yield! yield!
new
obj
33. “Best way to return true”
Winner:
mame leonid yhara eban shinh eto matz
6 6 7 5 10 9 2
NAKAMURA Usaku
6.43
14:59:00 ← push 予定時刻
34. “Best way to return true”
• The whole code
$ruby.is_a?(Object){|oriented| language}
35. “Best way to return true”— spoiler
• Just executable, no feature at all
実行可能なだけ、一切の機能なし
Is the most Transcendental, Imbroglio Ruby program
現世利益のない、意味不明な Ruby プログラムである
• Exploits the fact that a method does not check if it
accepts block argument or not
メソッドがブロック引数を受け付けるかどうかをチェックしないことを悪用
• Reveals a spec-level bug: missing is_an?
is_an? がないという仕様バグを浮き彫りに
Shows some of the subtleties (and design issues) of
Ruby
Ruby のある種の神秘性(と仕様バグ) を明らかにしている
36. “Best way to return true”— spoiler
• Works on almost all Ruby implementations
ほぼすべてのRuby実装で実行可能
shows the robustness and portability of Ruby
interpreters
Ruby 処理系の意外な堅牢性と移植性を示している
• This code returns true
$ruby.is_a?(Object){|oriented| language}
39. “Most competitive” – spoiler
• A “battle quine system” based on Elo rating
• Main trick: Elo rating
– A way of calculating the relative skill levels of players
• Used in chess, shogi, etc.
– Each program represents its own rate
• Sub tricks: cheat OCR, abuse of -i
$ ruby alice.rb bob.rb == alice.rb beats bob.rb
$ ruby bob.rb ailce.rb == bob.rb beats alice.rb
43. “Worst abuse of constants” –
spoiler
• Main Trick: pick up characters from constant names
_ { return } LocalJumpError
_ { method(:p).unbind } UnboundMethod
_ { eval “{ “ } SyntaxError
_ { Thread.current.join } ThreadError
• Extra tricks
– Another U is picked from RUBY_COPYRIGHT
– JRuby fails to run this program
46. “Most classic” – spoiler
• Main trick: music box with piano roll DSL
– # is a note, and | is a slur
• Extra tricks:
– “eval-split-join” idiom is not used
– Frequency modulation synthesis
FM 音源合成
• Judges’ comments
– boring
食傷気味
48. “Most readable”
begin with an easy program.
you should be able to write
a program unless for you,
program in ruby language is
too difficult. At the end
of your journey towards the
ultimate program; you must
be a part of a programming
language. You will end if
you != program
49. “Most readable” – spoiler
• Main trick:
– The whole structure is begin … end if false
– for statement is used for defining variables
begin
...
... unless
for you, program in ...
...
end
...
end if you != program
begin with an easy program.
you should be able to write
a program unless for you,
program in ruby language is
too difficult. At the end
of your journey towards the
ultimate program; you must
be a part of a programming
language. You will end if
you != program
51. “Best pangram”
• The program prints each ASCII character from
0x20 ' ' to 0x7e '~' exactly once.
• The program contains each ASCII character from
0x20 ' ' to 0x7e '~' exactly once.
!@THEqQUICKbBROWNfFXjJMPSvVLAZYDGgkyz&[%
r{¥"}mosx,4>6]|?'while(putc 3_0-~$.+=9/
2^5;)<18*7and:`#
52. “Best pangram” – spoiler
• Trick:
– 32.upto(126) {|x| putc x }
– But cannot “declare and then use” variables
• Features
– $. global variable, the best friend of Ruby golfers
– Trash box of unused alphabets: THE QUICK BROWN …
– Quote characters
– Century puzzle-ish
!@THEqQUICKbBROWNfFXjJMPSvVLAZYDGgkyz&[%
r{¥"}mosx,4>6]|?'while(putc 3_0-~$.+=9/
2^5;)<18*7and:`#
53. Judges’ comments
• For winners
業務連絡
– Please come to the stage during the last demo
最後の解説中に受賞者の方は前に集まってください
54. Winning entries
• "Good way to make programs wonderful“ – baban
• “Most characteristic” – yoshi-taka
• “Best way to return true” – unak
• “Worst house of garbage” – Nakamura Narihiro
• “Ruby by Ruby for Ruby award” – Yutaka Hara
• “Most competitive” – Yusuke Endoh
55. Dishonorable Top Four
“Best pangram” – kinaba
“Most Readable” – Shinichiro Hamaji
“Most classic”– Yusuke Endoh
“Worst abuse of constants” – Yutaka Hara
Dishonorable
mention
56. Prize?
• Dishonor: the title of “insane”
不名誉: 「変態」の称号
• Top three entries will be included in the Ruby official
repository as “sample” programs
上位3作品はRuby公式リポジトリにコミットされます
– The next Ruby tarball will be released with them
次期 Ruby パッケージにも含まれた状態でリリースされます
57. Conclusion
• TRICK rules and winning entries:
https://sites.google.com/site/trickcontest2013/
• Future work
– Next contest?
– Please please submit your entry
– Really looking forward to entries from foreign!