SlideShare ist ein Scribd-Unternehmen logo
1 von 68
Downloaden Sie, um offline zu lesen
• A contest for “esoteric” Ruby programming
– i.e., a Ruby version of IOCCC
– TRICK 2015 is the second contest
Transcendental /ˌtransɛnˈdɛnt(ə)l/
“relating to a spiritual realm” *
「霊的領域に関する」
「世俗を超越した」「超絶技巧」
Imbroglio /ɪmˈbrəʊlɪəʊ/
“an extremely confused, complicated, or
embarrassing situation” *
「極めて混乱した、恥ずかしい事態」
* according to Oxford Dictionaries
!@THEqQUICKbBROWNfFXjJMPSvVLAZYDGgkyz&[%r{¥"}mosx,
4>6]|?'while(putc 3_0-~$.+=9/2^5;)<18*7and:`#
eval$C=%q(at_exit{
open("/dev/dsp","wb"){|g|h=[0]*80
$><<"¥s"*18+"eval$C=%q(#$C);S=%:"
(S<<m=58).lines{|l|s=[128]*n=20E2
t=0; h.map!{|v|d=?!==l[
t]?1 :(l[
t]== ?#)?
0*v= 6:03
(v<1 ?[]:
0..n -1).
each {|z|
s[z] +=2*
M.sin(($*[0] ||1)
.to_f*M.sin(y= 40*(z+m)*2**
(t/12E0)/463)+ y)*(v-z*d/n)};
t+=1;v-d};m+= n;g.flush<<(s.
pack"C*"); puts(l)}}};M=
Math);S=%:
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
“Best pangram” by @kinaba
This prints each printable ASCII character exactly once.
This contains each printable ASCII character exactly once.
“Most readable” by @shinh
Non-sense poem
“Most classic” by @mametter
Music-box quine
• Announces the winners of TRICK 2015
– And demonstrates each winning entries
• The winning entries will be published at:
No k!
http://github.com/tric /trick2015/
• 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 の仕様を
安定化する
• 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 2015
C
Perl
Ruby
1985
IOCCC 1984-present
UCC 2005-present
OPC 1996-2000
IORCC 2005
TRICK
2013, 2015
1. Your entry must be a complete Ruby program.
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.
3. You can submit multiple entries, and your team may
consist of any number of members.
4. The entirety of your entry must be submitted under
MIT License.
5. Your entry must bring the judges a surprise,
excitement, and/or laughter.
• MRI 2.2 is recommended.
– Other implementations like JRuby are also allowed.
• You can use a gem library.
– We expect such entries to be much more interesting.
– Abusing gem to get around the size limit is discouraged.
• The judges would prefer more stoic, more portable,
and/or more funny entries.
• You are encouraged to examine the previous
winners of TRICK and IOCCC.
• Do not include your identity in your program.
– The judges will keep all entries anonymous during
judgment.
Yusuke Endoh (@mametter)
Koichiro Eto (@eto)
Shinichiro Hamaji (@shinh)
Yutaka Hara (@yhara)
Yukihiro Matsumoto (@yukihiro_matz)
Sun Park (@sunleonid)
Hirofumi Watanabe (@eban)
eto
– Media Artist.
– Chairman at NicoNicoGakkai Beta.
shinh
– The admin of anarchy golf.
– IOCCC winner.
yhara – The author of Japanese esolang book.
matz – The creator of Ruby.
leonid – The 1st super Ruby golfer.
eban – The 2nd super Ruby golfer.
– The world’s No.1 IOCCC player.
– Advocate for Transcendental programming.mame
• A textbook of
Transcendental
Programming
– 超絶技巧プログラミングの
入門書
– ¥2,680 + tax
– Buy it in the branch shop!
• TRICK 2015 became an international contest?
– Thank you for all the submitters!
JP
US
BE
PL TW
JP
cf. TRICK 2013
(I’m using 3D pie charts here to obfuscate the precise number of submissions.)
• Evaluated each entry with score 1..10.
• Selected 12 entries.
– Top 5 awards:
best entries by average score.
– 7 Judges’ awards:
entries of each judge’s best score
• The judges are allowed to submit their works.
– Of course, the author does not evaluate his own entry.
– In TRICK 2013, the judges won 5 awards out of 10.
– Good News: The judges could win just one award in
this conest.
5th
4th
• From here, this talk has a lot of spoilers!
– Exit now if you want to enjoy analyzing the winners.
• The winning entries will be published at:
No k!
http://github.com/tric /trick2015/
『最も手品で賞』 eto award
eto award
eval(%w{require'zlib';eval(Zlib: :Inflate.inflate('eJzNVt9zm0gMf
t+/QsfRAVrCYFw7TnrcTWauD/fW5zBch 9jrQGIDweBQ//jfT9Kubey0TqYvvX1Y
tJJW+lba/exJ2PtUhqPhVTC8oHnwSS6 TmXkXvlsL8QQ hTOBP8OEvqJJ8YvcduIZSCPMLhCISA
BAFLs4GnAwjdt9g7bnK2HbG/8Tsuy+s v8L+YrxuF7EQ c2wcueAhsQN9Fz66MHBh6MJlzMZdV+
fYz7lXyaWsFlKIm31bIxihf+xioWgvC yMtBKhRtr5PE TUk1o/Y88qFKxb6WqBoykaAdlsGXp3
N5cKbJ+U6GozIsH1pGGLY3iDe4sGSPT 48mc+HuzkUJK AD0wLYB04DBYcENG4iP2bDpnXh2wai
Fj5AgCi+HTn1Xnc6yjLSaMkQ03x4Cgz 6GOB3QLyHAC7 oMD9Mocp+FuQbggxfAKWrY+Z4PQxDi
Fv88 qPv+TQcYa5 QY01CCytgT+Bf6 DleXXxd4NJ CDm
H1E0 63B/UFKW8P XntuIb15R7qtpQ JHt7Ps7vr6 bzm
dJb X0Juprmysn9s pk/Ghbc8v x7hfNHQLyxmnlg mVpUAbFtd 89ryv51GSVtF YY
S2W zVdh/chU2U1/ bMgjACifD 8pp8nwC74Ti/K6 MQCAI+240 LS4fqU2GqBkt N8
tKT yThdbzIXHja6 vuY0quKow Ri4nwzeTO b3dRrjvgftU8 GH
EHq 02AqZT1QOyTl ceHah5Uzm FLcEQaddl 1edhdEaW++hy HL
bMJ ytoB2f7Va3Od pT24EuThnjp9VHoWNHZUbw5hctLzvys5JpUVZZ XoOZ8+H4hnGR g0
vq JHUhCvo3pOn1tU Y1mTfX6G9O1YGVmhPck3pFSGtvXDR5bVut5e CtH8R8sd5jcSwO U
KD nBRf9ka6wxUG5g V/HaVKtN+MNWrAx 9hhCdGgtpMb7qOB exUiRY4efSdnUC 3
jk kOainhRN7U1nzS IlxWImZQm+5w9U X6dFBRlkOao8e6 5vAoLrMfYUiaxD A
3s 6AGRjfsj0ik9eL xLoORI4MXfp9Dv mLkvtKOoYyOgMd R7BJCBncL4C5Ii G
fg bJK0XpAB2MzgLd /85oJEyJUclfaa f
4r KMMf8FSZAAtBDuh T4KjGp9N1a8rbXv A
68bCc5rNJC7/gMCHzQZK+C2EJ52pKNEtifQ/rFhrSVmUOj/HYubQq1RZ+ztr97p9PBzwbbi1L6LXHz6
IbLNabP8D7Sdt6A=='.unpack('m')[0]))###^^^^--- FOLLOW THE BALL ###trick2015}*"")
• A main program is zlib-compressed and
Base64-encoded.
eto award
eval(%w{
require'zlib';
eval(
Zlib::Inflate.inflate(
'<main code in zlib in base64>'.
unpack('m')[0]
)
)
}*"")
『最もふぞろいで賞』 leonid award
leonid award
p (?¥A-p +
?¥B-p +
?¥C-p +
?¥D-p +
?¥E-p +
…snip…
?¥X-p +
?¥Y-p +
?¥Z-p).b
.tr 'A-Z', ('_')/~0
BEGIN{class Object ; def
-(o)self end;alias/ -end}
• is a one-character string literal
• Do you know escape sequences and ?
• @leonid’s comment
– “Not sure how I would comment on it, since the code by itself
is pretty straightforward on what it's supposed to do.”
leonid award
p "¥C-a" #=> "¥x01”
p "¥C-b" #=> "¥x02”
p "¥C-c" #=> "¥x03”
p "¥M-a" #=> "¥xE1”
p "¥M-b" #=> "¥xE2”
p "¥M-c" #=> "¥xE3”
¥M-X¥C-X
?X
p ?A #=> "A"
p ?¥n #=> "¥n"
『最高のドキュメント賞』 eban award
eban award
Description from Ky.
----------
What if $1 and under junk games take over the world. It would makes you crazy.
We must fight against the future and will soon launch a new fantastic action game named TRICK!!!
Demo
----------
2020-03-25
Criminal 1 :: There he is! Kill the traitor.
Agent 1 :: Cover the man until 006 and 007 rescue us.
Agent 2 :: Okay. Come here!
Criminal 2 :: You must die if you bother us.
How to Get Demo Started if not for path in ENV
-
The command shows ruby version like this:
1.1
next __LINE__
ruby -v
'ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]'
1.2
next __LINE__
ruby entry.rb
end
• A polyglot of Ruby and Markdown!
– Invalid code is skipped in various ways.
– Similar to the Silver award of the previous contest,
but this is more clever.
eban award
Description from Ky.
----------
What if $1 and under junk games take over the world. …
Criminal 1 :: There he is! Kill the traitor.
Agent 1 :: Cover the man until 006 and 007 rescue us.
1.1
next __LINE__
ruby -v
『良い時機で賞』 mame award
mame award
0.times{%w{
2422-02-10T21:45:38+09:00
2580-06-19T08:53:09+09:00
2233-01-20T02:06:42+09:00
2535-06-28T10:04:32+09:00
2771-09-09T13:46:24+09:00
2478-04-17T02:50:28+09:00
3016-03-29T14:48:18+09:00
2358-03-06T12:25:34+09:00
2170-05-15T06:46:08+09:00
2365-05-11T19:00:00+09:00
2147-02-15T16:32:03+09:00
2500-02-13T23:15:21+09:00
2833-09-11T08:23:32+09:00
2431-03-03T09:48:37+09:00
2888-05-08T19:48:05+09:00
2098-12-09T19:37:41+09:00
2184-06-23T03:23:35+09:00
2289-12-20T01:21:04+09:00
2420-12-18T11:41:48+09:00
2922-08-26T03:58:58+09:00
2958-10-25T17:14:29+09:00
2260-10-29T11:18:23+09:00
2538-10-08T16:59:30+09:00
2765-03-10T15:17:18+09:00
3048-12-18T20:46:47+09:00
2238-03-12T21:38:38+09:00
2341-10-04T21:21:57+09:00
2136-05-29T03:39:48+09:00
2967-11-11T13:35:58+09:00
2751-11-28T05:17:41+09:00
2463-06-05T08:36:01+09:00
2375-04-30T18:11:29+09:00
2069-06-26T10:44:16+09:00
2876-12-06T18:46:16+09:00
"Back to the future?"
}}
GC.start
require'time';s = []; ObjectSpace.each_object{|u|s<<u}
eval s.map{|a|(((t=Time.iso8601(a))>Time.now)? t.to_i:
$')rescue nil}.compact.sort.uniq.map{|t|(t&0xff).chr}.
join# Quoted from "Back to the Future Part III (1990)"
2136-05-29T03:39:48+09:00
2967-11-11T13:35:58+09:00
2751-11-28T05:17:41+09:00
2463-06-05T08:36:01+09:00
2375-04-30T18:11:29+09:00
2069-06-26T10:44:16+09:00
2876-12-06T18:46:16+09:00
"Back to the future?"
• A message is encoded as a time sequence
1. Sorts the time sequence
2. Converts each time to an integer as UNIX time
3. Prints the integers as ASCII characters
• This program is a nice demonstration that
Ruby doesn’t suffer from “the Year 2038 problem.”
mame award
『 賞』 matz award
matz award
'(#|'.b;module Scheme;T,R,I,C,K=Struct.new(:a,:d,:o){include Enumerable# |#)#|
def initialize x,y=(),o=0.!;super c(x),c(y),o;K.empty?&&(R.delete a;R.delete d
R<<self)end;def-@;T[:-,self]end;alias == equal?;def call i;Scheme.t self,i end
def to_a;[T[:*,self]]end;def c o;Array===o ?Scheme.l(o):o end;def each&b;b.(a)
d&&d.each(&b)end},[],e=Struct.new(:t,:u){def[]=k,v;t[k]=v end;def[]i;t.fetch(i
){u[i]}end},e[_h={}],[];def Object.const_missing i;i end;refine(Fixnum){def[]i
T[self,T[i],1];end};module A; def -@;T[:-,T[self]];end;def call *a;a.
empty?? T[self]:Scheme.t(self ,a[0])end;end;refine(Array){def call a
T[self,T===a&&a.o ? a:T[a],1] end}; refine(Symbol){include A;def *i
T[self,T[:*,T[i]]]end; def-i; Symbol===i ? :"#{self}-#{i}":T[self,
T[:-,T[i]]]end;};at_exit{R.drop(K[ 0]=$0==__FILE__ ?0: 2).each{|l|v l}}
refine(String){include A;}; refine( Object){def method_missing i,*s;a,=
s;s.empty?? i:T[i,T===a&&a.o ? a:T[ a]]end};class<<self;def t s,i;T[s,
Array===i ?T[i[0]]:T===i&&i.o ? i: T[i],1]end;def e f,n;f.map{|i|v i,
n}[-1]end;def r x,f,n;->*a{e x.d. d,I[f ? Hash[f.zip a]:{},n]};end
def l v;v.reverse.inject(()){|a, i|T[i,a]};end;def v x,n=C;case x
when T;case x.a when :LAMBDA;r x,x.d.a,n when :LET; e={}; x.d.
a.each{|i|e[i.a]=v i.d.a,n};e x.d.d,I[e,n];when :IF;v(v(x.d.
a,n)?x.d.d.a: (y=x.d.d.d)?y. a : (),n);when :COND; while x=x.d
break e x.a.d,n if:ELSE==x. a.a || v(x.a.a,n); end;when :DEFINE
Symbol===(u=x.d.a) ?(n[u]= v x.d.d. a,n):(n[u.a]=r x,u.d,n);when
:QUOTE;d=x.d.a;d==true ? :TRUE:(d== false)?:FALSE:d else
f,*r=x.map{|i|v i,n};f. call(*r) end when Symbol;n[x]else
x;end;end;end;%w(PAIR? o T===o NOT o 0.!.==o SET-CDR! p,o
p.d=o LIST *s l(s) CAR p p.a NUMBER? o Numeric===o SET-CAR!
p,o p.a=o ERROR *s fail(s*"¥s") READ * t="using(Scheme);"*1;begin;gets&&eval(¥
t<<($_!=$/?$_:x),TOPLEVEL_BINDING);rescue(Object);retry;end NULL? o o==() CONS
a,b T[a,b] APPLY f,*n,s f.(*(n+(s||[]).map.to_a)) EOF-OBJECT? o o==() LENGTH l
l.to_a.size SYMBOL? o Symbol===o EQ? a,b a.equal?b DISPLAY o puts(o) CDR p p.d
* *s s.inject:* - *s s.inject:- MAP p,l l(l.map(&p)) STRING? o o.is_a?(String)
MIN *s s.min).each_slice(3){|t|eval'_h[:"%s"]=->%s{%s}'%t}end;using Scheme# |#
(DEFINE (FACT N) . (
(IF (EQ? N . (1)) . (
1 [* N . ((FACT (- N . (1))))]))))
(DISPLAY (FACT 6))
(DEFINE (FACT N) . (
(IF (EQ? N . (1)) . (
1 [* N . ((FACT (- N . (1))))]))))
(DISPLAY (FACT 6))
• A polyglot of Ruby and Scheme
matz award
'(#|'.b;module Scheme;T,R,I,C,K=Struct.new(:a,:d,:o){include Enumerable# |#)#|
def initialize x,y=(),o=0.!;super c(x),c(y),o;K.empty?&&(R.delete a;R.delete d
R<<self)end;def-@;T[:-,self]end;alias == equal?;def call i;Scheme.t self,i end
def to_a;[T[:*,self]]end;def c o;Array===o ?Scheme.l(o):o end;def each&b;b.(a)
d&&d.each(&b)end},[],e=Struct.new(:t,:u){def[]=k,v;t[k]=v end;def[]i;t.fetch(i
){u[i]}end},e[_h={}],[];def Object.const_missing i;i end;refine(Fixnum){def[]i
T[self,T[i],1];end};module A; def -@;T[:-,T[self]];end;def call *a;a.
empty?? T[self]:Scheme.t(self ,a[0])end;end;refine(Array){def call a
T[self,T===a&&a.o ? a:T[a],1] end}; refine(Symbol){include A;def *i
T[self,T[:*,T[i]]]end; def-i; Symbol===i ? :"#{self}-#{i}":T[self,
T[:-,T[i]]]end;};at_exit{R.drop(K[ 0]=$0==__FILE__ ?0: 2).each{|l|v l}}
refine(String){include A;}; refine( Object){def method_missing i,*s;a,=
s;s.empty?? i:T[i,T===a&&a.o ? a:T[ a]]end};class<<self;def t s,i;T[s,
Array===i ?T[i[0]]:T===i&&i.o ? i: T[i],1]end;def e f,n;f.map{|i|v i,
n}[-1]end;def r x,f,n;->*a{e x.d. d,I[f ? Hash[f.zip a]:{},n]};end
def l v;v.reverse.inject(()){|a, i|T[i,a]};end;def v x,n=C;case x
when T;case x.a when :LAMBDA;r x,x.d.a,n when :LET; e={}; x.d.
a.each{|i|e[i.a]=v i.d.a,n};e x.d.d,I[e,n];when :IF;v(v(x.d.
a,n)?x.d.d.a: (y=x.d.d.d)?y. a : (),n);when :COND; while x=x.d
break e x.a.d,n if:ELSE==x. a.a || v(x.a.a,n); end;when :DEFINE
Symbol===(u=x.d.a) ?(n[u]= v x.d.d. a,n):(n[u.a]=r x,u.d,n);when
:QUOTE;d=x.d.a;d==true ? :TRUE:(d== false)?:FALSE:d else
f,*r=x.map{|i|v i,n};f. call(*r) end when Symbol;n[x]else
x;end;end;end;%w(PAIR? o T===o NOT o 0.!.==o SET-CDR! p,o
p.d=o LIST *s l(s) CAR p p.a NUMBER? o Numeric===o SET-CAR!
p,o p.a=o ERROR *s fail(s*"¥s") READ * t="using(Scheme);"*1;begin;gets&&eval(¥
t<<($_!=$/?$_:x),TOPLEVEL_BINDING);rescue(Object);retry;end NULL? o o==() CONS
a,b T[a,b] APPLY f,*n,s f.(*(n+(s||[]).map.to_a)) EOF-OBJECT? o o==() LENGTH l
l.to_a.size SYMBOL? o Symbol===o EQ? a,b a.equal?b DISPLAY o puts(o) CDR p p.d
* *s s.inject:* - *s s.inject:- MAP p,l l(l.map(&p)) STRING? o o.is_a?(String)
MIN *s s.min).each_slice(3){|t|eval'_h[:"%s"]=->%s{%s}'%t}end;using Scheme# |#
(DEFINE (FACT N) . (
(IF (EQ? N . (1)) . (
1 [* N . ((FACT (- N . (1))))]))))
(DISPLAY (FACT 6))
'(#|'.b;module Scheme;T,R,I,C,K=Struct.new(:a,:d,:o){include Enumerable# |#)#|
def initialize x,y=(),o=0.!;super c(x),c(y),o;K.empty?&&(R.delete a;R.delete d
R<<self)end;def-@;T[:-,self]end;alias == equal?;def call i;Scheme.t self,i end
def to_a;[T[:*,self]]end;def c o;Array===o ?Scheme.l(o):o end;def each&b;b.(a)
d&&d.each(&b)end},[],e=Struct.new(:t,:u){def[]=k,v;t[k]=v end;def[]i;t.fetch(i
){u[i]}end},e[_h={}],[];def Object.const_missing i;i end;refine(Fixnum){def[]i
T[self,T[i],1];end};module A; def -@;T[:-,T[self]];end;def call *a;a.
empty?? T[self]:Scheme.t(self ,a[0])end;end;refine(Array){def call a
T[self,T===a&&a.o ? a:T[a],1] end}; refine(Symbol){include A;def *i
T[self,T[:*,T[i]]]end; def-i; Symbol===i ? :"#{self}-#{i}":T[self,
T[:-,T[i]]]end;};at_exit{R.drop(K[ 0]=$0==__FILE__ ?0: 2).each{|l|v l}}
refine(String){include A;}; refine( Object){def method_missing i,*s;a,=
s;s.empty?? i:T[i,T===a&&a.o ? a:T[ a]]end};class<<self;def t s,i;T[s,
Array===i ?T[i[0]]:T===i&&i.o ? i: T[i],1]end;def e f,n;f.map{|i|v i,
n}[-1]end;def r x,f,n;->*a{e x.d. d,I[f ? Hash[f.zip a]:{},n]};end
def l v;v.reverse.inject(()){|a, i|T[i,a]};end;def v x,n=C;case x
when T;case x.a when :LAMBDA;r x,x.d.a,n when :LET; e={}; x.d.
a.each{|i|e[i.a]=v i.d.a,n};e x.d.d,I[e,n];when :IF;v(v(x.d.
a,n)?x.d.d.a: (y=x.d.d.d)?y. a : (),n);when :COND; while x=x.d
break e x.a.d,n if:ELSE==x. a.a || v(x.a.a,n); end;when :DEFINE
Symbol===(u=x.d.a) ?(n[u]= v x.d.d. a,n):(n[u.a]=r x,u.d,n);when
:QUOTE;d=x.d.a;d==true ? :TRUE:(d== false)?:FALSE:d else
f,*r=x.map{|i|v i,n};f. call(*r) end when Symbol;n[x]else
x;end;end;end;%w(PAIR? o T===o NOT o 0.!.==o SET-CDR! p,o
p.d=o LIST *s l(s) CAR p p.a NUMBER? o Numeric===o SET-CAR!
p,o p.a=o ERROR *s fail(s*"¥s") READ * t="using(Scheme);"*1;begin;gets&&eval(¥
t<<($_!=$/?$_:x),TOPLEVEL_BINDING);rescue(Object);retry;end NULL? o o==() CONS
a,b T[a,b] APPLY f,*n,s f.(*(n+(s||[]).map.to_a)) EOF-OBJECT? o o==() LENGTH l
l.to_a.size SYMBOL? o Symbol===o EQ? a,b a.equal?b DISPLAY o puts(o) CDR p p.d
* *s s.inject:* - *s s.inject:- MAP p,l l(l.map(&p)) STRING? o o.is_a?(String)
MIN *s s.min).each_slice(3){|t|eval'_h[:"%s"]=->%s{%s}'%t}end;using Scheme# |#
(DEFINE (FACT N) . (
(IF (EQ? N . (1)) . (
1 [* N . ((FACT (- N . (1))))]))))
(DISPLAY (FACT 6))
DSL interpreter
A comment
ignored
Scheme-like
Ruby DSL
Normal
Scheme code
As Ruby As Scheme
『最も壊れやすいで賞』 shinh award
shinh award
lines = Array.new
open(__FILE__) do |fl|
fl.each_line{|line|
lines.push(line)
}
m=15+15
n=62
$e = lines.
map do|ln|
sz = ln.size
;
(sz<5?sz+m:sz+n).
chr().swapcase
end.join
$e
eval "#$e"
end
• Another Ruby program is hidden in “line lengths”
– Even changing the indent breaks this program!
– BTW: We kind of knew the author was a committer
since it works only on ruby trunk.
shinh award
lines = Array.new
open(__FILE__) do |fl|
fl.each_line{|line|
lines.push(line)
18
23
22
21
puts"……"
p+62
u+62
t+62
s+62
『一番綺麗な模様で賞』 yhara award
yhara award
-> ( &_ ) { _ [ _ , ?e +
?v + ?a + ?l , q = ?e +
?v + ?a + ?l + ?( + ?d +
?[ + ?1 + ?9 + ?, + ?9 +
?9 + ?9 + ?] + ?* + ?" +
?" + ?) ] }[ &(s , *d = %I{
#{ ?s + ?e + ?n + ?d } -> (
&_ ) { _ [ _ , ?e + ?v
+ ?a + ?l , q = a= d[ 0,
19 ]; ;b =q .c ha rs .m ap {|
_| b& &a << ?+ ;a << ?? +_ ;b
|= 1} ;a += %q !] X} [X &( sX
,X *d X= X% I{ X# {X ?s X+ X? e
X +X ?n X+ X? dX }X !. sp li
t( ?X )+ d+ "} X) X[ X0 X] X]
". sp li t( ?X ); pu ts (a .m
ap (& :t o_ s) .p ac k( "A 6"
*a .s iz e) .u np ac k" A6 1"
*1 9) #T RI CK } ) [ 0 ] ]
• Problem: no room to write “eval”!
• Key idea to solve
– Abuse of symbol array literal
• Detailed solution
– This margin is too narrow to explain.
– Read Chapter 6 of mame’s book!
• shinh discovered the same technique
independently 
yhara award
p %I{ foo bar } #=> [:foo, :bar]
『最も汎用的なソルバで賞』
• One liner
_='s %sSATISFIABLE';puts eval$<.read.gs
ub(/.*p.*?(¥d+).*?$|¥d+/m){$1?%w[?-+'=-
'=~/#{'(-?)'* }-*=(?=]*$1:$&>?0?"¥¥#$&$
|":'$)(?='}+‘)/x?[_%p%i=0,[*$~].map{|x|
x>?-?:v:eval(x+?1)*i-=1}*" "]:_%:UN'
• SAT solver in 194 bytes!
Finds an assignment to satisfy a given Boolean formula*
• Implementation trick
– Converts a given formula to Regexp matching problem
s.t. the matching is possible iff the formula is satisfiable.
x and !y x=true, y=false
x and !x UNSATISFIABLE
input output
* must be in conjunctive normal form
『最も汎用的でないソルバで賞』
class String;def[]*a;$*<<a;b;end;end;
_=0;z="C=Fiber;s=$*;a=*0..8;l=C.new{e
xit},*a.product(a).select{|r,c|s[r][c
]==0}."[1,9,_, _,_,8, _,_,5]+"map{|r,
c|C.ne"[_,_,2, _,5,_, _,8,9]+"w{o=s[r
][c];l"[8,_,6, 7,4,_, _,_,_]+"oop{(1.
.9).map{|n|C.yield(s[r][c]=n)if a.non
e?{|k|"[_,_,_, _,_,4, _,9,2]+"s[r][k]
==n||s"[_,2,3, _,7,_, 8,1,_]+"[k][c]=
=n||s["[5,6,_, 8,_,_, _,_,_]+"r-r%3+k
%3][c-c%3+k/3]==n}};s[r][c]=o;C.yield
}}},C."[_,_,_, _,2,7, 9,_,3]+"new{loo
p{puts"[9,3,_, _,8,_, 1,_,_]+" s.map{
|r|r*'"[2,_,_, 5,_,_, _,4,8]+" '}<<''
;C.yield}};c=l[i=1];loop{c=l[i+=c.res
ume ? 1:-1]}";eval z.tr ?¥n,''
class String;def[]*a;$*<<a;b;end;end;
_=0;z="C=Fiber;s=$*;a=*0..8;l=C.new{e
xit},*a.product(a).select{|r,c|s[r][c
]==0}."[1,9,_, _,_,8, _,_,5]+"map{|r,
c|C.ne"[_,_,2, _,5,_, _,8,9]+"w{o=s[r
][c];l"[8,_,6, 7,4,_, _,_,_]+"oop{(1.
.9).map{|n|C.yield(s[r][c]=n)if a.non
e?{|k|"[_,_,_, _,_,4, _,9,2]+"s[r][k]
==n||s"[_,2,3, _,7,_, 8,1,_]+"[k][c]=
=n||s["[5,6,_, 8,_,_, _,_,_]+"r-r%3+k
%3][c-c%3+k/3]==n}};s[r][c]=o;C.yield
}}},C."[_,_,_, _,2,7, 9,_,3]+"new{loo
p{puts"[9,3,_, _,8,_, 1,_,_]+" s.map{
|r|r*'"[2,_,_, 5,_,_, _,4,8]+" '}<<''
;C.yield}};c=l[i=1];loop{c=l[i+=c.res
ume ? 1:-1]}";eval z.tr ?¥n,''
• All-solution Sudoku solver
• A magic for mixing data and code
• Nicely demonstrates a use case of Fiber
– Elegant and hard to understand, at the same time!
class String;def[]*a;$*<<a;b;end
code="pri"[1, 2, 3]+"nt 1"
code="print 1"
$*=[[1, 2, 3]]
String#b ≒ self
『倍増するアンフィスバエナ賞』
;; ;; ;; ;;
;; ;; ;; ;;
;;eval$s =%q[i=1#
eval(%q[ xxxxxxxx
xx xxxx xx xx xxxx xx
xx xxxx xx xx xxxx xx
xxxxxxxx xxxxxxxx
xxxxxxxx xxxxxxxx
xx xx xxxxxxxxxx xx xxxxxxxx
j, t, p=0,[?;]," ev al$s=%qx
[#$s]".split*"";i,j,t=i-j,i+j,(x
[b=?¥s]*j.abs+t).map{|s|r=t.shix
ft ||b;r.gsub!(?;){p.slice!0}if $x
f| |=p>p=p.center(i*i+j*j,?;);r ,x
s=[s,r]if(i*j<0);(b*i.abs+s).ljx
ust(r.size).gsub(b){r[$`.size]|x
|b}}unti l$ f;puts(t)# xx xx
xxxxxxxx xx xxxxxxxxxx xx xx
xxxxxxxx xxxxxxxx
xxxxxxxx xxxxxxxx
xx xxxx xx xx xxxx xx
xx xxxx xx xx xxxx xx
xxxxxxxx x].gsub¥
/x.*|¥s/ ,"")#];;
;; ;; ;; ;;
;; ;; ;; ;;
• The author’s remarks:
• Amphisbaena(アンフィスバエナ)
– “A mythical serpent
with a head at each end” *
> geminum caput amphisbaenae, hoc est et a cauda,
> tamquam parum esset uno ore fundi venenum.
> aliis squamas esse, aliis picturas, omnibus exitiale virus.
>
> — GAIUS PLINIUS SECUNDUS, Naturalis Historia 8.85.1
* according to Oxford Dictionaries
• Cute string construction
• @shinh’s comment:
– “The code seems concise.”
• @yhara’s favorite piece of code
if $f ||= p > p = p.center(i*i+j*j,";")
;; ;;
;;
;;
;;
;;
;;
;;
;;
;;;;
;;;;
;;
;;
;; ;;
;; ;;
;;;;;;;;
;;;;;;;;
;; ;;
;; ;;
;; ;;
;; ;;
;;;;;;;;
;;;;;;;;
;; ;;;; ;;
;; ;;;; ;;
;;;;;;;;
;;;;;;;;
;; ;;
;; ;;
『最も読めない で賞』
• One liner with a lot of percents
%%%while eval '_=%%r%%(.)..
.¥1=%%=~[%%%%,,,,,%%%s ?=]
*%%%%%%#"]*%%%%3x+1?%%'.% %
%",%*p(_||=eval($**%%%))
• Collatz sequence calculator
– if n is even, n = n / 2
– if n is odd, n = 3n+1
• Example: starting with n = 3
Collatz conjecture: Any n will eventually boil down to 1.
• How is the program great?
– It uses no integer arithmetic, no branch.
ALU:
Arithmetic Logic Unit
算術論理演算装置
103 5 16 8 4 2 1
• Example: How to branch if N is even or not
– Note: This is more simplified than the original code.
– Integer arithmetic is even more complicated.
[ ", ", ", ", ]; …even… #"]; …odd…
", ×N
[ ", ", ", ]; …even… #"]; …odd…
String Comment
String
『最高の円周率ポエムで賞』
big, temp = Array 100000000**0x04e2
srand big
alias $curTerm $initTerm
Numeric
Interrupt
big += big
printout _pi_ finish if $never
init ||= big
$counter ||= 02
…snip…
• Piphilology(円周率覚え歌)
– A sentence to memorize the first digits of π
– A famous example
• The program does the same by using Ruby tokens
– Note: lexical tokens ≠ space-separated units
Yes I have a number
3 1 4 1 6. ≈ π
big , temp = Array 100000000 ** 0x04e2
3 1 4 1 5. 9 2 6
• Abuse “alias” of global variables
– to access the same value from token of different length
• “ ” is a storage!
– It returns the previous seed.
– It can be used as a latch.
– An assignment always requires
one-length token “=”.
alias $curTerm $initTerm
srand 1
p srand 2 #=> 1
p srand 3 #=> 2
p srand 4 #=> 3
srand
• 77 tokens are essential.
• 165 tokens are just no-op fillers.
• The blowup ratio:
Enumerable
Fixnum
Bignum
Math
Complex
Comparable
TrueClass
Dir
Encoding
Data
An example of fillers
165+77
77
≈ 3.14
• The winners who are here, come to the stage.
– You have a right to earn applause
• 受賞者でご臨席の方は、前に集まってください
– 拍手喝采をどうぞ
• yhara award: “Most beautiful pattern”–Shinichiro Hamaji
• shinh award: “Most fragile” – NAKAMURA Usaku
• matz award: “Matz Lisp award” – Kazuki Tsujimoto
• mame award: “Most timely” – Koichi Sasada
• eban award: “Best document” – yoshi-taka
• eto award: “Most illusionistic” – Don Yang
• leonid award: “Most inconsistent” – Koichi Sasada
“Best piphilology”
– kinaba
“Most unreadable ALU”
– Keisuke Nakano
“Doubling amphisbaena award”
– monae
“Least general solver” – Benoit Daloze
“Most general solver” – Keisuke Nakano
4th
5th
• Dishonor: the title of “insane”
• Top five entries will be checked into the Ruby
official repository in “sample” directory
– Ruby 2.3.0 will have them (perhaps)
• The winning entries will be published soon at:
• Thank you for all participants!
• See you in the next TRICK 201X!
No k!
http://github.com/tric /trick2015/

Weitere ähnliche Inhalte

Was ist angesagt?

An Introduction to Go
An Introduction to GoAn Introduction to Go
An Introduction to Go
Cloudflare
 
Dtrace и немного магии
Dtrace и немного магииDtrace и немного магии
Dtrace и немного магии
Dan Kruchinin
 
Php Extensions for Dummies
Php Extensions for DummiesPhp Extensions for Dummies
Php Extensions for Dummies
Elizabeth Smith
 
Migrating To Ruby1.9
Migrating To Ruby1.9Migrating To Ruby1.9
Migrating To Ruby1.9
tomaspavelka
 

Was ist angesagt? (20)

An Introduction to Go
An Introduction to GoAn Introduction to Go
An Introduction to Go
 
Graph-Tool in Practice
Graph-Tool in PracticeGraph-Tool in Practice
Graph-Tool in Practice
 
JavaScript Survival Guide
JavaScript Survival GuideJavaScript Survival Guide
JavaScript Survival Guide
 
Mirah Talk for Boulder Ruby Group
Mirah Talk for Boulder Ruby GroupMirah Talk for Boulder Ruby Group
Mirah Talk for Boulder Ruby Group
 
Dtrace и немного магии
Dtrace и немного магииDtrace и немного магии
Dtrace и немного магии
 
Meetup di Gruppo Game Jam Roma - Giorgio Pomettini - Codemotion Rome 2018
Meetup di Gruppo Game Jam Roma - Giorgio Pomettini - Codemotion Rome 2018Meetup di Gruppo Game Jam Roma - Giorgio Pomettini - Codemotion Rome 2018
Meetup di Gruppo Game Jam Roma - Giorgio Pomettini - Codemotion Rome 2018
 
Rust & Gamedev
Rust & GamedevRust & Gamedev
Rust & Gamedev
 
Php Extensions for Dummies
Php Extensions for DummiesPhp Extensions for Dummies
Php Extensions for Dummies
 
JavaScript Patterns
JavaScript PatternsJavaScript Patterns
JavaScript Patterns
 
Elegant concurrency
Elegant concurrencyElegant concurrency
Elegant concurrency
 
Migrating To Ruby1.9
Migrating To Ruby1.9Migrating To Ruby1.9
Migrating To Ruby1.9
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?
 
Alfresco the clojure way
Alfresco the clojure wayAlfresco the clojure way
Alfresco the clojure way
 
Shibuyajs Digest
Shibuyajs DigestShibuyajs Digest
Shibuyajs Digest
 
Templating with your {{mustache}}js
Templating with your {{mustache}}jsTemplating with your {{mustache}}js
Templating with your {{mustache}}js
 
Effective ES6
Effective ES6Effective ES6
Effective ES6
 
Learning Python from Data
Learning Python from DataLearning Python from Data
Learning Python from Data
 
Cranking Floating Point Performance To 11 On The iPhone
Cranking Floating Point Performance To 11 On The iPhoneCranking Floating Point Performance To 11 On The iPhone
Cranking Floating Point Performance To 11 On The iPhone
 
P6 OO vs Moose (&Moo)
P6 OO vs Moose (&Moo)P6 OO vs Moose (&Moo)
P6 OO vs Moose (&Moo)
 
Introduction to Ruby, Rails, and Ruby on Rails
Introduction to Ruby, Rails, and Ruby on RailsIntroduction to Ruby, Rails, and Ruby on Rails
Introduction to Ruby, Rails, and Ruby on Rails
 

Andere mochten auch

Andere mochten auch (20)

Practical Testing of Ruby Core
Practical Testing of Ruby CorePractical Testing of Ruby Core
Practical Testing of Ruby Core
 
Ruby で高速なプログラムを書く
Ruby で高速なプログラムを書くRuby で高速なプログラムを書く
Ruby で高速なプログラムを書く
 
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
 
Ruby meets Go
Ruby meets GoRuby meets Go
Ruby meets Go
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGems
 
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015
 
Photos Rares1mb
Photos Rares1mbPhotos Rares1mb
Photos Rares1mb
 
Optcarrot: A Pure-Ruby NES Emulator
Optcarrot: A Pure-Ruby NES EmulatorOptcarrot: A Pure-Ruby NES Emulator
Optcarrot: A Pure-Ruby NES Emulator
 
Quine・難解プログラミングについて
Quine・難解プログラミングについてQuine・難解プログラミングについて
Quine・難解プログラミングについて
 
Do you trust that certificate?
Do you trust that certificate?Do you trust that certificate?
Do you trust that certificate?
 
Techmix2014 温故知新
Techmix2014 温故知新Techmix2014 温故知新
Techmix2014 温故知新
 
Metaprogramming in Haskell
Metaprogramming in HaskellMetaprogramming in Haskell
Metaprogramming in Haskell
 
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
 
RubyKaigi2015 making robots-with-mruby
RubyKaigi2015 making robots-with-mrubyRubyKaigi2015 making robots-with-mruby
RubyKaigi2015 making robots-with-mruby
 
The OMR GC talk - Ruby Kaigi 2015
The OMR GC talk - Ruby Kaigi 2015The OMR GC talk - Ruby Kaigi 2015
The OMR GC talk - Ruby Kaigi 2015
 
Data Analytics Service Company and Its Ruby Usage
Data Analytics Service Company and Its Ruby UsageData Analytics Service Company and Its Ruby Usage
Data Analytics Service Company and Its Ruby Usage
 
Experiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRubyExperiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRuby
 
Logging for Production Systems in The Container Era
Logging for Production Systems in The Container EraLogging for Production Systems in The Container Era
Logging for Production Systems in The Container Era
 
Fluentd at Bay Area Kubernetes Meetup
Fluentd at Bay Area Kubernetes MeetupFluentd at Bay Area Kubernetes Meetup
Fluentd at Bay Area Kubernetes Meetup
 
"fireap" - fast task runner on consul
"fireap" - fast task runner on consul"fireap" - fast task runner on consul
"fireap" - fast task runner on consul
 

Ähnlich wie TRICK2015 results

Discussions In your own words (75-150 words)Due Sunday, May .docx
Discussions     In your own words (75-150 words)Due Sunday, May .docxDiscussions     In your own words (75-150 words)Due Sunday, May .docx
Discussions In your own words (75-150 words)Due Sunday, May .docx
edgar6wallace88877
 

Ähnlich wie TRICK2015 results (20)

TRICK 2018 results
TRICK 2018 resultsTRICK 2018 results
TRICK 2018 results
 
Ludo game using c++ with documentation
Ludo game using c++ with documentation Ludo game using c++ with documentation
Ludo game using c++ with documentation
 
Fighting fraud: finding duplicates at scale (Highload+ 2019)
Fighting fraud: finding duplicates at scale (Highload+ 2019)Fighting fraud: finding duplicates at scale (Highload+ 2019)
Fighting fraud: finding duplicates at scale (Highload+ 2019)
 
47966368 super-student
47966368 super-student47966368 super-student
47966368 super-student
 
47966368 super-student
47966368 super-student47966368 super-student
47966368 super-student
 
Hitchhikers guide to OpenSim calongne
Hitchhikers guide to OpenSim calongneHitchhikers guide to OpenSim calongne
Hitchhikers guide to OpenSim calongne
 
Game prototyping workshop
Game prototyping workshopGame prototyping workshop
Game prototyping workshop
 
I.fest 2018 event description
I.fest 2018 event descriptionI.fest 2018 event description
I.fest 2018 event description
 
I.fest 2018 event description
I.fest 2018 event descriptionI.fest 2018 event description
I.fest 2018 event description
 
I own copyright, so I pwn you!
I own copyright, so I pwn you!I own copyright, so I pwn you!
I own copyright, so I pwn you!
 
Discussions In your own words (75-150 words)Due Sunday, May .docx
Discussions     In your own words (75-150 words)Due Sunday, May .docxDiscussions     In your own words (75-150 words)Due Sunday, May .docx
Discussions In your own words (75-150 words)Due Sunday, May .docx
 
Dragon Ruby 孩子的游戏编程.pdf
Dragon Ruby 孩子的游戏编程.pdfDragon Ruby 孩子的游戏编程.pdf
Dragon Ruby 孩子的游戏编程.pdf
 
Tumbleweed Express: A Tale of 54 Game Jams
Tumbleweed Express: A Tale of 54 Game JamsTumbleweed Express: A Tale of 54 Game Jams
Tumbleweed Express: A Tale of 54 Game Jams
 
A Post-Apocalyptic sun.misc.Unsafe World
A Post-Apocalyptic sun.misc.Unsafe WorldA Post-Apocalyptic sun.misc.Unsafe World
A Post-Apocalyptic sun.misc.Unsafe World
 
Modeling computer networks by colored Petri nets
Modeling computer networks by colored Petri netsModeling computer networks by colored Petri nets
Modeling computer networks by colored Petri nets
 
Stop Monkeys Fall
Stop Monkeys FallStop Monkeys Fall
Stop Monkeys Fall
 
Hunting The Shadows: In Depth Analysis of Escalated APT Attacks
Hunting The Shadows: In Depth Analysis of Escalated APT AttacksHunting The Shadows: In Depth Analysis of Escalated APT Attacks
Hunting The Shadows: In Depth Analysis of Escalated APT Attacks
 
When a robot is smart enough?
When a robot is smart enough?When a robot is smart enough?
When a robot is smart enough?
 
Python Workshop
Python WorkshopPython Workshop
Python Workshop
 
Into the Void (NoSQL matters 2012)
Into the Void (NoSQL matters 2012)Into the Void (NoSQL matters 2012)
Into the Void (NoSQL matters 2012)
 

Mehr von mametter

クックパッド春の超絶技巧パンまつり 超絶技巧プログラミング編 資料
クックパッド春の超絶技巧パンまつり 超絶技巧プログラミング編 資料クックパッド春の超絶技巧パンまつり 超絶技巧プログラミング編 資料
クックパッド春の超絶技巧パンまつり 超絶技巧プログラミング編 資料
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 TypeProf
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 3
mametter
 
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
mametter
 

Mehr von 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
 
TRICK 2022 Results
TRICK 2022 ResultsTRICK 2022 Results
TRICK 2022 Results
 
クックパッド春の超絶技巧パンまつり 超絶技巧プログラミング編 資料
クックパッド春の超絶技巧パンまつり 超絶技巧プログラミング編 資料クックパッド春の超絶技巧パンまつり 超絶技巧プログラミング編 資料
クックパッド春の超絶技巧パンまつり 超絶技巧プログラミング編 資料
 
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のキーワード引数について考える
 
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
 

Kürzlich hochgeladen

Chat 9316020077💋 Call Girls Agency In Goa By Goa Call Girls Agency 💋
Chat 9316020077💋 Call Girls  Agency In Goa  By Goa  Call Girls  Agency 💋Chat 9316020077💋 Call Girls  Agency In Goa  By Goa  Call Girls  Agency 💋
Chat 9316020077💋 Call Girls Agency In Goa By Goa Call Girls Agency 💋
russian goa call girl and escorts service
 
Russian ℂall gIRLS In Goa 9316020077 ℂall gIRLS Service In Goa
Russian ℂall gIRLS In Goa 9316020077  ℂall gIRLS Service  In GoaRussian ℂall gIRLS In Goa 9316020077  ℂall gIRLS Service  In Goa
Russian ℂall gIRLS In Goa 9316020077 ℂall gIRLS Service In Goa
russian goa call girl and escorts service
 
Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...
Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...
Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...
mriyagarg453
 
Call Girls Agency In Goa 💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...
Call Girls  Agency In Goa  💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...Call Girls  Agency In Goa  💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...
Call Girls Agency In Goa 💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...
russian goa call girl and escorts service
 

Kürzlich hochgeladen (20)

(TOP CLASS) Call Girls In Nungambakkam Phone 7427069034 Call Girls Model With...
(TOP CLASS) Call Girls In Nungambakkam Phone 7427069034 Call Girls Model With...(TOP CLASS) Call Girls In Nungambakkam Phone 7427069034 Call Girls Model With...
(TOP CLASS) Call Girls In Nungambakkam Phone 7427069034 Call Girls Model With...
 
Chat 9316020077💋 Call Girls Agency In Goa By Goa Call Girls Agency 💋
Chat 9316020077💋 Call Girls  Agency In Goa  By Goa  Call Girls  Agency 💋Chat 9316020077💋 Call Girls  Agency In Goa  By Goa  Call Girls  Agency 💋
Chat 9316020077💋 Call Girls Agency In Goa By Goa Call Girls Agency 💋
 
College Call Girls Pune 8617697112 Short 1500 Night 6000 Best call girls Service
College Call Girls Pune 8617697112 Short 1500 Night 6000 Best call girls ServiceCollege Call Girls Pune 8617697112 Short 1500 Night 6000 Best call girls Service
College Call Girls Pune 8617697112 Short 1500 Night 6000 Best call girls Service
 
Hotel And Home Service Available Kolkata Call Girls Diamond Harbour ✔ 6297143...
Hotel And Home Service Available Kolkata Call Girls Diamond Harbour ✔ 6297143...Hotel And Home Service Available Kolkata Call Girls Diamond Harbour ✔ 6297143...
Hotel And Home Service Available Kolkata Call Girls Diamond Harbour ✔ 6297143...
 
Russian ℂall gIRLS In Goa 9316020077 ℂall gIRLS Service In Goa
Russian ℂall gIRLS In Goa 9316020077  ℂall gIRLS Service  In GoaRussian ℂall gIRLS In Goa 9316020077  ℂall gIRLS Service  In Goa
Russian ℂall gIRLS In Goa 9316020077 ℂall gIRLS Service In Goa
 
Hotel And Home Service Available Kolkata Call Girls Sonagachi ✔ 6297143586 ✔C...
Hotel And Home Service Available Kolkata Call Girls Sonagachi ✔ 6297143586 ✔C...Hotel And Home Service Available Kolkata Call Girls Sonagachi ✔ 6297143586 ✔C...
Hotel And Home Service Available Kolkata Call Girls Sonagachi ✔ 6297143586 ✔C...
 
Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...
Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...
Navsari Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girl...
 
VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...
 
Tikiapara Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex A...
Tikiapara Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex A...Tikiapara Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex A...
Tikiapara Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex A...
 
Call Girls Agency In Goa 💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...
Call Girls  Agency In Goa  💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...Call Girls  Agency In Goa  💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...
Call Girls Agency In Goa 💚 9316020077 💚 Call Girl Goa By Russian Call Girl ...
 
𓀤Call On 6297143586 𓀤 Ultadanga Call Girls In All Kolkata 24/7 Provide Call W...
𓀤Call On 6297143586 𓀤 Ultadanga Call Girls In All Kolkata 24/7 Provide Call W...𓀤Call On 6297143586 𓀤 Ultadanga Call Girls In All Kolkata 24/7 Provide Call W...
𓀤Call On 6297143586 𓀤 Ultadanga Call Girls In All Kolkata 24/7 Provide Call W...
 
Behala ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready ...
Behala ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready ...Behala ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready ...
Behala ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready ...
 
𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...
𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...
𓀤Call On 6297143586 𓀤 Park Street Call Girls In All Kolkata 24/7 Provide Call...
 
VIP Model Call Girls Vijayawada ( Pune ) Call ON 8005736733 Starting From 5K ...
VIP Model Call Girls Vijayawada ( Pune ) Call ON 8005736733 Starting From 5K ...VIP Model Call Girls Vijayawada ( Pune ) Call ON 8005736733 Starting From 5K ...
VIP Model Call Girls Vijayawada ( Pune ) Call ON 8005736733 Starting From 5K ...
 
Book Sex Workers Available Kolkata Call Girls Service Airport Kolkata ✔ 62971...
Book Sex Workers Available Kolkata Call Girls Service Airport Kolkata ✔ 62971...Book Sex Workers Available Kolkata Call Girls Service Airport Kolkata ✔ 62971...
Book Sex Workers Available Kolkata Call Girls Service Airport Kolkata ✔ 62971...
 
Independent Garulia Escorts ✔ 9332606886✔ Full Night With Room Online Booking...
Independent Garulia Escorts ✔ 9332606886✔ Full Night With Room Online Booking...Independent Garulia Escorts ✔ 9332606886✔ Full Night With Room Online Booking...
Independent Garulia Escorts ✔ 9332606886✔ Full Night With Room Online Booking...
 
Independent Hatiara Escorts ✔ 9332606886✔ Full Night With Room Online Booking...
Independent Hatiara Escorts ✔ 9332606886✔ Full Night With Room Online Booking...Independent Hatiara Escorts ✔ 9332606886✔ Full Night With Room Online Booking...
Independent Hatiara Escorts ✔ 9332606886✔ Full Night With Room Online Booking...
 
Bhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRL
Bhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRLBhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRL
Bhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRL
 
Hotel And Home Service Available Kolkata Call Girls Howrah ✔ 6297143586 ✔Call...
Hotel And Home Service Available Kolkata Call Girls Howrah ✔ 6297143586 ✔Call...Hotel And Home Service Available Kolkata Call Girls Howrah ✔ 6297143586 ✔Call...
Hotel And Home Service Available Kolkata Call Girls Howrah ✔ 6297143586 ✔Call...
 
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment BookingKanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
 

TRICK2015 results

  • 1.
  • 2. • A contest for “esoteric” Ruby programming – i.e., a Ruby version of IOCCC – TRICK 2015 is the second contest Transcendental /ˌtransɛnˈdɛnt(ə)l/ “relating to a spiritual realm” * 「霊的領域に関する」 「世俗を超越した」「超絶技巧」 Imbroglio /ɪmˈbrəʊlɪəʊ/ “an extremely confused, complicated, or embarrassing situation” * 「極めて混乱した、恥ずかしい事態」 * according to Oxford Dictionaries
  • 3. !@THEqQUICKbBROWNfFXjJMPSvVLAZYDGgkyz&[%r{¥"}mosx, 4>6]|?'while(putc 3_0-~$.+=9/2^5;)<18*7and:`# eval$C=%q(at_exit{ open("/dev/dsp","wb"){|g|h=[0]*80 $><<"¥s"*18+"eval$C=%q(#$C);S=%:" (S<<m=58).lines{|l|s=[128]*n=20E2 t=0; h.map!{|v|d=?!==l[ t]?1 :(l[ t]== ?#)? 0*v= 6:03 (v<1 ?[]: 0..n -1). each {|z| s[z] +=2* M.sin(($*[0] ||1) .to_f*M.sin(y= 40*(z+m)*2** (t/12E0)/463)+ y)*(v-z*d/n)}; t+=1;v-d};m+= n;g.flush<<(s. pack"C*"); puts(l)}}};M= Math);S=%: 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 “Best pangram” by @kinaba This prints each printable ASCII character exactly once. This contains each printable ASCII character exactly once. “Most readable” by @shinh Non-sense poem “Most classic” by @mametter Music-box quine
  • 4. • Announces the winners of TRICK 2015 – And demonstrates each winning entries • The winning entries will be published at: No k! http://github.com/tric /trick2015/
  • 5.
  • 6. • 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 の仕様を 安定化する
  • 7. • 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 2015 C Perl Ruby 1985 IOCCC 1984-present UCC 2005-present OPC 1996-2000 IORCC 2005 TRICK 2013, 2015
  • 8. 1. Your entry must be a complete Ruby program. 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. 3. You can submit multiple entries, and your team may consist of any number of members. 4. The entirety of your entry must be submitted under MIT License. 5. Your entry must bring the judges a surprise, excitement, and/or laughter.
  • 9. • MRI 2.2 is recommended. – Other implementations like JRuby are also allowed. • You can use a gem library. – We expect such entries to be much more interesting. – Abusing gem to get around the size limit is discouraged. • The judges would prefer more stoic, more portable, and/or more funny entries. • You are encouraged to examine the previous winners of TRICK and IOCCC. • Do not include your identity in your program. – The judges will keep all entries anonymous during judgment.
  • 10. Yusuke Endoh (@mametter) Koichiro Eto (@eto) Shinichiro Hamaji (@shinh) Yutaka Hara (@yhara) Yukihiro Matsumoto (@yukihiro_matz) Sun Park (@sunleonid) Hirofumi Watanabe (@eban)
  • 11. eto – Media Artist. – Chairman at NicoNicoGakkai Beta. shinh – The admin of anarchy golf. – IOCCC winner. yhara – The author of Japanese esolang book. matz – The creator of Ruby. leonid – The 1st super Ruby golfer. eban – The 2nd super Ruby golfer. – The world’s No.1 IOCCC player. – Advocate for Transcendental programming.mame
  • 12. • A textbook of Transcendental Programming – 超絶技巧プログラミングの 入門書 – ¥2,680 + tax – Buy it in the branch shop!
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19. • TRICK 2015 became an international contest? – Thank you for all the submitters! JP US BE PL TW JP cf. TRICK 2013 (I’m using 3D pie charts here to obfuscate the precise number of submissions.)
  • 20. • Evaluated each entry with score 1..10. • Selected 12 entries. – Top 5 awards: best entries by average score. – 7 Judges’ awards: entries of each judge’s best score • The judges are allowed to submit their works. – Of course, the author does not evaluate his own entry. – In TRICK 2013, the judges won 5 awards out of 10. – Good News: The judges could win just one award in this conest. 5th 4th
  • 21. • From here, this talk has a lot of spoilers! – Exit now if you want to enjoy analyzing the winners. • The winning entries will be published at: No k! http://github.com/tric /trick2015/
  • 22.
  • 24. eto award eval(%w{require'zlib';eval(Zlib: :Inflate.inflate('eJzNVt9zm0gMf t+/QsfRAVrCYFw7TnrcTWauD/fW5zBch 9jrQGIDweBQ//jfT9Kubey0TqYvvX1Y tJJW+lba/exJ2PtUhqPhVTC8oHnwSS6 TmXkXvlsL8QQ hTOBP8OEvqJJ8YvcduIZSCPMLhCISA BAFLs4GnAwjdt9g7bnK2HbG/8Tsuy+s v8L+YrxuF7EQ c2wcueAhsQN9Fz66MHBh6MJlzMZdV+ fYz7lXyaWsFlKIm31bIxihf+xioWgvC yMtBKhRtr5PE TUk1o/Y88qFKxb6WqBoykaAdlsGXp3 N5cKbJ+U6GozIsH1pGGLY3iDe4sGSPT 48mc+HuzkUJK AD0wLYB04DBYcENG4iP2bDpnXh2wai Fj5AgCi+HTn1Xnc6yjLSaMkQ03x4Cgz 6GOB3QLyHAC7 oMD9Mocp+FuQbggxfAKWrY+Z4PQxDi Fv88 qPv+TQcYa5 QY01CCytgT+Bf6 DleXXxd4NJ CDm H1E0 63B/UFKW8P XntuIb15R7qtpQ JHt7Ps7vr6 bzm dJb X0Juprmysn9s pk/Ghbc8v x7hfNHQLyxmnlg mVpUAbFtd 89ryv51GSVtF YY S2W zVdh/chU2U1/ bMgjACifD 8pp8nwC74Ti/K6 MQCAI+240 LS4fqU2GqBkt N8 tKT yThdbzIXHja6 vuY0quKow Ri4nwzeTO b3dRrjvgftU8 GH EHq 02AqZT1QOyTl ceHah5Uzm FLcEQaddl 1edhdEaW++hy HL bMJ ytoB2f7Va3Od pT24EuThnjp9VHoWNHZUbw5hctLzvys5JpUVZZ XoOZ8+H4hnGR g0 vq JHUhCvo3pOn1tU Y1mTfX6G9O1YGVmhPck3pFSGtvXDR5bVut5e CtH8R8sd5jcSwO U KD nBRf9ka6wxUG5g V/HaVKtN+MNWrAx 9hhCdGgtpMb7qOB exUiRY4efSdnUC 3 jk kOainhRN7U1nzS IlxWImZQm+5w9U X6dFBRlkOao8e6 5vAoLrMfYUiaxD A 3s 6AGRjfsj0ik9eL xLoORI4MXfp9Dv mLkvtKOoYyOgMd R7BJCBncL4C5Ii G fg bJK0XpAB2MzgLd /85oJEyJUclfaa f 4r KMMf8FSZAAtBDuh T4KjGp9N1a8rbXv A 68bCc5rNJC7/gMCHzQZK+C2EJ52pKNEtifQ/rFhrSVmUOj/HYubQq1RZ+ztr97p9PBzwbbi1L6LXHz6 IbLNabP8D7Sdt6A=='.unpack('m')[0]))###^^^^--- FOLLOW THE BALL ###trick2015}*"")
  • 25. • A main program is zlib-compressed and Base64-encoded. eto award eval(%w{ require'zlib'; eval( Zlib::Inflate.inflate( '<main code in zlib in base64>'. unpack('m')[0] ) ) }*"")
  • 27. leonid award p (?¥A-p + ?¥B-p + ?¥C-p + ?¥D-p + ?¥E-p + …snip… ?¥X-p + ?¥Y-p + ?¥Z-p).b .tr 'A-Z', ('_')/~0 BEGIN{class Object ; def -(o)self end;alias/ -end}
  • 28. • is a one-character string literal • Do you know escape sequences and ? • @leonid’s comment – “Not sure how I would comment on it, since the code by itself is pretty straightforward on what it's supposed to do.” leonid award p "¥C-a" #=> "¥x01” p "¥C-b" #=> "¥x02” p "¥C-c" #=> "¥x03” p "¥M-a" #=> "¥xE1” p "¥M-b" #=> "¥xE2” p "¥M-c" #=> "¥xE3” ¥M-X¥C-X ?X p ?A #=> "A" p ?¥n #=> "¥n"
  • 30. eban award Description from Ky. ---------- What if $1 and under junk games take over the world. It would makes you crazy. We must fight against the future and will soon launch a new fantastic action game named TRICK!!! Demo ---------- 2020-03-25 Criminal 1 :: There he is! Kill the traitor. Agent 1 :: Cover the man until 006 and 007 rescue us. Agent 2 :: Okay. Come here! Criminal 2 :: You must die if you bother us. How to Get Demo Started if not for path in ENV - The command shows ruby version like this: 1.1 next __LINE__ ruby -v 'ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]' 1.2 next __LINE__ ruby entry.rb end
  • 31. • A polyglot of Ruby and Markdown! – Invalid code is skipped in various ways. – Similar to the Silver award of the previous contest, but this is more clever. eban award Description from Ky. ---------- What if $1 and under junk games take over the world. … Criminal 1 :: There he is! Kill the traitor. Agent 1 :: Cover the man until 006 and 007 rescue us. 1.1 next __LINE__ ruby -v
  • 33. mame award 0.times{%w{ 2422-02-10T21:45:38+09:00 2580-06-19T08:53:09+09:00 2233-01-20T02:06:42+09:00 2535-06-28T10:04:32+09:00 2771-09-09T13:46:24+09:00 2478-04-17T02:50:28+09:00 3016-03-29T14:48:18+09:00 2358-03-06T12:25:34+09:00 2170-05-15T06:46:08+09:00 2365-05-11T19:00:00+09:00 2147-02-15T16:32:03+09:00 2500-02-13T23:15:21+09:00 2833-09-11T08:23:32+09:00 2431-03-03T09:48:37+09:00 2888-05-08T19:48:05+09:00 2098-12-09T19:37:41+09:00 2184-06-23T03:23:35+09:00 2289-12-20T01:21:04+09:00 2420-12-18T11:41:48+09:00 2922-08-26T03:58:58+09:00 2958-10-25T17:14:29+09:00 2260-10-29T11:18:23+09:00 2538-10-08T16:59:30+09:00 2765-03-10T15:17:18+09:00 3048-12-18T20:46:47+09:00 2238-03-12T21:38:38+09:00 2341-10-04T21:21:57+09:00 2136-05-29T03:39:48+09:00 2967-11-11T13:35:58+09:00 2751-11-28T05:17:41+09:00 2463-06-05T08:36:01+09:00 2375-04-30T18:11:29+09:00 2069-06-26T10:44:16+09:00 2876-12-06T18:46:16+09:00 "Back to the future?" }} GC.start require'time';s = []; ObjectSpace.each_object{|u|s<<u} eval s.map{|a|(((t=Time.iso8601(a))>Time.now)? t.to_i: $')rescue nil}.compact.sort.uniq.map{|t|(t&0xff).chr}. join# Quoted from "Back to the Future Part III (1990)" 2136-05-29T03:39:48+09:00 2967-11-11T13:35:58+09:00 2751-11-28T05:17:41+09:00 2463-06-05T08:36:01+09:00 2375-04-30T18:11:29+09:00 2069-06-26T10:44:16+09:00 2876-12-06T18:46:16+09:00 "Back to the future?"
  • 34. • A message is encoded as a time sequence 1. Sorts the time sequence 2. Converts each time to an integer as UNIX time 3. Prints the integers as ASCII characters • This program is a nice demonstration that Ruby doesn’t suffer from “the Year 2038 problem.” mame award
  • 36. matz award '(#|'.b;module Scheme;T,R,I,C,K=Struct.new(:a,:d,:o){include Enumerable# |#)#| def initialize x,y=(),o=0.!;super c(x),c(y),o;K.empty?&&(R.delete a;R.delete d R<<self)end;def-@;T[:-,self]end;alias == equal?;def call i;Scheme.t self,i end def to_a;[T[:*,self]]end;def c o;Array===o ?Scheme.l(o):o end;def each&b;b.(a) d&&d.each(&b)end},[],e=Struct.new(:t,:u){def[]=k,v;t[k]=v end;def[]i;t.fetch(i ){u[i]}end},e[_h={}],[];def Object.const_missing i;i end;refine(Fixnum){def[]i T[self,T[i],1];end};module A; def -@;T[:-,T[self]];end;def call *a;a. empty?? T[self]:Scheme.t(self ,a[0])end;end;refine(Array){def call a T[self,T===a&&a.o ? a:T[a],1] end}; refine(Symbol){include A;def *i T[self,T[:*,T[i]]]end; def-i; Symbol===i ? :"#{self}-#{i}":T[self, T[:-,T[i]]]end;};at_exit{R.drop(K[ 0]=$0==__FILE__ ?0: 2).each{|l|v l}} refine(String){include A;}; refine( Object){def method_missing i,*s;a,= s;s.empty?? i:T[i,T===a&&a.o ? a:T[ a]]end};class<<self;def t s,i;T[s, Array===i ?T[i[0]]:T===i&&i.o ? i: T[i],1]end;def e f,n;f.map{|i|v i, n}[-1]end;def r x,f,n;->*a{e x.d. d,I[f ? Hash[f.zip a]:{},n]};end def l v;v.reverse.inject(()){|a, i|T[i,a]};end;def v x,n=C;case x when T;case x.a when :LAMBDA;r x,x.d.a,n when :LET; e={}; x.d. a.each{|i|e[i.a]=v i.d.a,n};e x.d.d,I[e,n];when :IF;v(v(x.d. a,n)?x.d.d.a: (y=x.d.d.d)?y. a : (),n);when :COND; while x=x.d break e x.a.d,n if:ELSE==x. a.a || v(x.a.a,n); end;when :DEFINE Symbol===(u=x.d.a) ?(n[u]= v x.d.d. a,n):(n[u.a]=r x,u.d,n);when :QUOTE;d=x.d.a;d==true ? :TRUE:(d== false)?:FALSE:d else f,*r=x.map{|i|v i,n};f. call(*r) end when Symbol;n[x]else x;end;end;end;%w(PAIR? o T===o NOT o 0.!.==o SET-CDR! p,o p.d=o LIST *s l(s) CAR p p.a NUMBER? o Numeric===o SET-CAR! p,o p.a=o ERROR *s fail(s*"¥s") READ * t="using(Scheme);"*1;begin;gets&&eval(¥ t<<($_!=$/?$_:x),TOPLEVEL_BINDING);rescue(Object);retry;end NULL? o o==() CONS a,b T[a,b] APPLY f,*n,s f.(*(n+(s||[]).map.to_a)) EOF-OBJECT? o o==() LENGTH l l.to_a.size SYMBOL? o Symbol===o EQ? a,b a.equal?b DISPLAY o puts(o) CDR p p.d * *s s.inject:* - *s s.inject:- MAP p,l l(l.map(&p)) STRING? o o.is_a?(String) MIN *s s.min).each_slice(3){|t|eval'_h[:"%s"]=->%s{%s}'%t}end;using Scheme# |# (DEFINE (FACT N) . ( (IF (EQ? N . (1)) . ( 1 [* N . ((FACT (- N . (1))))])))) (DISPLAY (FACT 6)) (DEFINE (FACT N) . ( (IF (EQ? N . (1)) . ( 1 [* N . ((FACT (- N . (1))))])))) (DISPLAY (FACT 6))
  • 37. • A polyglot of Ruby and Scheme matz award '(#|'.b;module Scheme;T,R,I,C,K=Struct.new(:a,:d,:o){include Enumerable# |#)#| def initialize x,y=(),o=0.!;super c(x),c(y),o;K.empty?&&(R.delete a;R.delete d R<<self)end;def-@;T[:-,self]end;alias == equal?;def call i;Scheme.t self,i end def to_a;[T[:*,self]]end;def c o;Array===o ?Scheme.l(o):o end;def each&b;b.(a) d&&d.each(&b)end},[],e=Struct.new(:t,:u){def[]=k,v;t[k]=v end;def[]i;t.fetch(i ){u[i]}end},e[_h={}],[];def Object.const_missing i;i end;refine(Fixnum){def[]i T[self,T[i],1];end};module A; def -@;T[:-,T[self]];end;def call *a;a. empty?? T[self]:Scheme.t(self ,a[0])end;end;refine(Array){def call a T[self,T===a&&a.o ? a:T[a],1] end}; refine(Symbol){include A;def *i T[self,T[:*,T[i]]]end; def-i; Symbol===i ? :"#{self}-#{i}":T[self, T[:-,T[i]]]end;};at_exit{R.drop(K[ 0]=$0==__FILE__ ?0: 2).each{|l|v l}} refine(String){include A;}; refine( Object){def method_missing i,*s;a,= s;s.empty?? i:T[i,T===a&&a.o ? a:T[ a]]end};class<<self;def t s,i;T[s, Array===i ?T[i[0]]:T===i&&i.o ? i: T[i],1]end;def e f,n;f.map{|i|v i, n}[-1]end;def r x,f,n;->*a{e x.d. d,I[f ? Hash[f.zip a]:{},n]};end def l v;v.reverse.inject(()){|a, i|T[i,a]};end;def v x,n=C;case x when T;case x.a when :LAMBDA;r x,x.d.a,n when :LET; e={}; x.d. a.each{|i|e[i.a]=v i.d.a,n};e x.d.d,I[e,n];when :IF;v(v(x.d. a,n)?x.d.d.a: (y=x.d.d.d)?y. a : (),n);when :COND; while x=x.d break e x.a.d,n if:ELSE==x. a.a || v(x.a.a,n); end;when :DEFINE Symbol===(u=x.d.a) ?(n[u]= v x.d.d. a,n):(n[u.a]=r x,u.d,n);when :QUOTE;d=x.d.a;d==true ? :TRUE:(d== false)?:FALSE:d else f,*r=x.map{|i|v i,n};f. call(*r) end when Symbol;n[x]else x;end;end;end;%w(PAIR? o T===o NOT o 0.!.==o SET-CDR! p,o p.d=o LIST *s l(s) CAR p p.a NUMBER? o Numeric===o SET-CAR! p,o p.a=o ERROR *s fail(s*"¥s") READ * t="using(Scheme);"*1;begin;gets&&eval(¥ t<<($_!=$/?$_:x),TOPLEVEL_BINDING);rescue(Object);retry;end NULL? o o==() CONS a,b T[a,b] APPLY f,*n,s f.(*(n+(s||[]).map.to_a)) EOF-OBJECT? o o==() LENGTH l l.to_a.size SYMBOL? o Symbol===o EQ? a,b a.equal?b DISPLAY o puts(o) CDR p p.d * *s s.inject:* - *s s.inject:- MAP p,l l(l.map(&p)) STRING? o o.is_a?(String) MIN *s s.min).each_slice(3){|t|eval'_h[:"%s"]=->%s{%s}'%t}end;using Scheme# |# (DEFINE (FACT N) . ( (IF (EQ? N . (1)) . ( 1 [* N . ((FACT (- N . (1))))])))) (DISPLAY (FACT 6)) '(#|'.b;module Scheme;T,R,I,C,K=Struct.new(:a,:d,:o){include Enumerable# |#)#| def initialize x,y=(),o=0.!;super c(x),c(y),o;K.empty?&&(R.delete a;R.delete d R<<self)end;def-@;T[:-,self]end;alias == equal?;def call i;Scheme.t self,i end def to_a;[T[:*,self]]end;def c o;Array===o ?Scheme.l(o):o end;def each&b;b.(a) d&&d.each(&b)end},[],e=Struct.new(:t,:u){def[]=k,v;t[k]=v end;def[]i;t.fetch(i ){u[i]}end},e[_h={}],[];def Object.const_missing i;i end;refine(Fixnum){def[]i T[self,T[i],1];end};module A; def -@;T[:-,T[self]];end;def call *a;a. empty?? T[self]:Scheme.t(self ,a[0])end;end;refine(Array){def call a T[self,T===a&&a.o ? a:T[a],1] end}; refine(Symbol){include A;def *i T[self,T[:*,T[i]]]end; def-i; Symbol===i ? :"#{self}-#{i}":T[self, T[:-,T[i]]]end;};at_exit{R.drop(K[ 0]=$0==__FILE__ ?0: 2).each{|l|v l}} refine(String){include A;}; refine( Object){def method_missing i,*s;a,= s;s.empty?? i:T[i,T===a&&a.o ? a:T[ a]]end};class<<self;def t s,i;T[s, Array===i ?T[i[0]]:T===i&&i.o ? i: T[i],1]end;def e f,n;f.map{|i|v i, n}[-1]end;def r x,f,n;->*a{e x.d. d,I[f ? Hash[f.zip a]:{},n]};end def l v;v.reverse.inject(()){|a, i|T[i,a]};end;def v x,n=C;case x when T;case x.a when :LAMBDA;r x,x.d.a,n when :LET; e={}; x.d. a.each{|i|e[i.a]=v i.d.a,n};e x.d.d,I[e,n];when :IF;v(v(x.d. a,n)?x.d.d.a: (y=x.d.d.d)?y. a : (),n);when :COND; while x=x.d break e x.a.d,n if:ELSE==x. a.a || v(x.a.a,n); end;when :DEFINE Symbol===(u=x.d.a) ?(n[u]= v x.d.d. a,n):(n[u.a]=r x,u.d,n);when :QUOTE;d=x.d.a;d==true ? :TRUE:(d== false)?:FALSE:d else f,*r=x.map{|i|v i,n};f. call(*r) end when Symbol;n[x]else x;end;end;end;%w(PAIR? o T===o NOT o 0.!.==o SET-CDR! p,o p.d=o LIST *s l(s) CAR p p.a NUMBER? o Numeric===o SET-CAR! p,o p.a=o ERROR *s fail(s*"¥s") READ * t="using(Scheme);"*1;begin;gets&&eval(¥ t<<($_!=$/?$_:x),TOPLEVEL_BINDING);rescue(Object);retry;end NULL? o o==() CONS a,b T[a,b] APPLY f,*n,s f.(*(n+(s||[]).map.to_a)) EOF-OBJECT? o o==() LENGTH l l.to_a.size SYMBOL? o Symbol===o EQ? a,b a.equal?b DISPLAY o puts(o) CDR p p.d * *s s.inject:* - *s s.inject:- MAP p,l l(l.map(&p)) STRING? o o.is_a?(String) MIN *s s.min).each_slice(3){|t|eval'_h[:"%s"]=->%s{%s}'%t}end;using Scheme# |# (DEFINE (FACT N) . ( (IF (EQ? N . (1)) . ( 1 [* N . ((FACT (- N . (1))))])))) (DISPLAY (FACT 6)) DSL interpreter A comment ignored Scheme-like Ruby DSL Normal Scheme code As Ruby As Scheme
  • 39. shinh award lines = Array.new open(__FILE__) do |fl| fl.each_line{|line| lines.push(line) } m=15+15 n=62 $e = lines. map do|ln| sz = ln.size ; (sz<5?sz+m:sz+n). chr().swapcase end.join $e eval "#$e" end
  • 40. • Another Ruby program is hidden in “line lengths” – Even changing the indent breaks this program! – BTW: We kind of knew the author was a committer since it works only on ruby trunk. shinh award lines = Array.new open(__FILE__) do |fl| fl.each_line{|line| lines.push(line) 18 23 22 21 puts"……" p+62 u+62 t+62 s+62
  • 42. yhara award -> ( &_ ) { _ [ _ , ?e + ?v + ?a + ?l , q = ?e + ?v + ?a + ?l + ?( + ?d + ?[ + ?1 + ?9 + ?, + ?9 + ?9 + ?9 + ?] + ?* + ?" + ?" + ?) ] }[ &(s , *d = %I{ #{ ?s + ?e + ?n + ?d } -> ( &_ ) { _ [ _ , ?e + ?v + ?a + ?l , q = a= d[ 0, 19 ]; ;b =q .c ha rs .m ap {| _| b& &a << ?+ ;a << ?? +_ ;b |= 1} ;a += %q !] X} [X &( sX ,X *d X= X% I{ X# {X ?s X+ X? e X +X ?n X+ X? dX }X !. sp li t( ?X )+ d+ "} X) X[ X0 X] X] ". sp li t( ?X ); pu ts (a .m ap (& :t o_ s) .p ac k( "A 6" *a .s iz e) .u np ac k" A6 1" *1 9) #T RI CK } ) [ 0 ] ]
  • 43. • Problem: no room to write “eval”! • Key idea to solve – Abuse of symbol array literal • Detailed solution – This margin is too narrow to explain. – Read Chapter 6 of mame’s book! • shinh discovered the same technique independently  yhara award p %I{ foo bar } #=> [:foo, :bar]
  • 44.
  • 46. • One liner _='s %sSATISFIABLE';puts eval$<.read.gs ub(/.*p.*?(¥d+).*?$|¥d+/m){$1?%w[?-+'=- '=~/#{'(-?)'* }-*=(?=]*$1:$&>?0?"¥¥#$&$ |":'$)(?='}+‘)/x?[_%p%i=0,[*$~].map{|x| x>?-?:v:eval(x+?1)*i-=1}*" "]:_%:UN'
  • 47. • SAT solver in 194 bytes! Finds an assignment to satisfy a given Boolean formula* • Implementation trick – Converts a given formula to Regexp matching problem s.t. the matching is possible iff the formula is satisfiable. x and !y x=true, y=false x and !x UNSATISFIABLE input output * must be in conjunctive normal form
  • 49. class String;def[]*a;$*<<a;b;end;end; _=0;z="C=Fiber;s=$*;a=*0..8;l=C.new{e xit},*a.product(a).select{|r,c|s[r][c ]==0}."[1,9,_, _,_,8, _,_,5]+"map{|r, c|C.ne"[_,_,2, _,5,_, _,8,9]+"w{o=s[r ][c];l"[8,_,6, 7,4,_, _,_,_]+"oop{(1. .9).map{|n|C.yield(s[r][c]=n)if a.non e?{|k|"[_,_,_, _,_,4, _,9,2]+"s[r][k] ==n||s"[_,2,3, _,7,_, 8,1,_]+"[k][c]= =n||s["[5,6,_, 8,_,_, _,_,_]+"r-r%3+k %3][c-c%3+k/3]==n}};s[r][c]=o;C.yield }}},C."[_,_,_, _,2,7, 9,_,3]+"new{loo p{puts"[9,3,_, _,8,_, 1,_,_]+" s.map{ |r|r*'"[2,_,_, 5,_,_, _,4,8]+" '}<<'' ;C.yield}};c=l[i=1];loop{c=l[i+=c.res ume ? 1:-1]}";eval z.tr ?¥n,'' class String;def[]*a;$*<<a;b;end;end; _=0;z="C=Fiber;s=$*;a=*0..8;l=C.new{e xit},*a.product(a).select{|r,c|s[r][c ]==0}."[1,9,_, _,_,8, _,_,5]+"map{|r, c|C.ne"[_,_,2, _,5,_, _,8,9]+"w{o=s[r ][c];l"[8,_,6, 7,4,_, _,_,_]+"oop{(1. .9).map{|n|C.yield(s[r][c]=n)if a.non e?{|k|"[_,_,_, _,_,4, _,9,2]+"s[r][k] ==n||s"[_,2,3, _,7,_, 8,1,_]+"[k][c]= =n||s["[5,6,_, 8,_,_, _,_,_]+"r-r%3+k %3][c-c%3+k/3]==n}};s[r][c]=o;C.yield }}},C."[_,_,_, _,2,7, 9,_,3]+"new{loo p{puts"[9,3,_, _,8,_, 1,_,_]+" s.map{ |r|r*'"[2,_,_, 5,_,_, _,4,8]+" '}<<'' ;C.yield}};c=l[i=1];loop{c=l[i+=c.res ume ? 1:-1]}";eval z.tr ?¥n,''
  • 50. • All-solution Sudoku solver • A magic for mixing data and code • Nicely demonstrates a use case of Fiber – Elegant and hard to understand, at the same time! class String;def[]*a;$*<<a;b;end code="pri"[1, 2, 3]+"nt 1" code="print 1" $*=[[1, 2, 3]] String#b ≒ self
  • 52. ;; ;; ;; ;; ;; ;; ;; ;; ;;eval$s =%q[i=1# eval(%q[ xxxxxxxx xx xxxx xx xx xxxx xx xx xxxx xx xx xxxx xx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xx xx xxxxxxxxxx xx xxxxxxxx j, t, p=0,[?;]," ev al$s=%qx [#$s]".split*"";i,j,t=i-j,i+j,(x [b=?¥s]*j.abs+t).map{|s|r=t.shix ft ||b;r.gsub!(?;){p.slice!0}if $x f| |=p>p=p.center(i*i+j*j,?;);r ,x s=[s,r]if(i*j<0);(b*i.abs+s).ljx ust(r.size).gsub(b){r[$`.size]|x |b}}unti l$ f;puts(t)# xx xx xxxxxxxx xx xxxxxxxxxx xx xx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xx xxxx xx xx xxxx xx xx xxxx xx xx xxxx xx xxxxxxxx x].gsub¥ /x.*|¥s/ ,"")#];; ;; ;; ;; ;; ;; ;; ;; ;;
  • 53. • The author’s remarks: • Amphisbaena(アンフィスバエナ) – “A mythical serpent with a head at each end” * > geminum caput amphisbaenae, hoc est et a cauda, > tamquam parum esset uno ore fundi venenum. > aliis squamas esse, aliis picturas, omnibus exitiale virus. > > — GAIUS PLINIUS SECUNDUS, Naturalis Historia 8.85.1 * according to Oxford Dictionaries
  • 54. • Cute string construction • @shinh’s comment: – “The code seems concise.” • @yhara’s favorite piece of code if $f ||= p > p = p.center(i*i+j*j,";") ;; ;; ;; ;; ;; ;; ;; ;; ;; ;;;; ;;;; ;; ;; ;; ;; ;; ;; ;;;;;;;; ;;;;;;;; ;; ;; ;; ;; ;; ;; ;; ;; ;;;;;;;; ;;;;;;;; ;; ;;;; ;; ;; ;;;; ;; ;;;;;;;; ;;;;;;;; ;; ;; ;; ;;
  • 56. • One liner with a lot of percents %%%while eval '_=%%r%%(.).. .¥1=%%=~[%%%%,,,,,%%%s ?=] *%%%%%%#"]*%%%%3x+1?%%'.% % %",%*p(_||=eval($**%%%))
  • 57. • Collatz sequence calculator – if n is even, n = n / 2 – if n is odd, n = 3n+1 • Example: starting with n = 3 Collatz conjecture: Any n will eventually boil down to 1. • How is the program great? – It uses no integer arithmetic, no branch. ALU: Arithmetic Logic Unit 算術論理演算装置 103 5 16 8 4 2 1
  • 58. • Example: How to branch if N is even or not – Note: This is more simplified than the original code. – Integer arithmetic is even more complicated. [ ", ", ", ", ]; …even… #"]; …odd… ", ×N [ ", ", ", ]; …even… #"]; …odd… String Comment String
  • 60. big, temp = Array 100000000**0x04e2 srand big alias $curTerm $initTerm Numeric Interrupt big += big printout _pi_ finish if $never init ||= big $counter ||= 02 …snip…
  • 61. • Piphilology(円周率覚え歌) – A sentence to memorize the first digits of π – A famous example • The program does the same by using Ruby tokens – Note: lexical tokens ≠ space-separated units Yes I have a number 3 1 4 1 6. ≈ π big , temp = Array 100000000 ** 0x04e2 3 1 4 1 5. 9 2 6
  • 62. • Abuse “alias” of global variables – to access the same value from token of different length • “ ” is a storage! – It returns the previous seed. – It can be used as a latch. – An assignment always requires one-length token “=”. alias $curTerm $initTerm srand 1 p srand 2 #=> 1 p srand 3 #=> 2 p srand 4 #=> 3 srand
  • 63. • 77 tokens are essential. • 165 tokens are just no-op fillers. • The blowup ratio: Enumerable Fixnum Bignum Math Complex Comparable TrueClass Dir Encoding Data An example of fillers 165+77 77 ≈ 3.14
  • 64. • The winners who are here, come to the stage. – You have a right to earn applause • 受賞者でご臨席の方は、前に集まってください – 拍手喝采をどうぞ
  • 65. • yhara award: “Most beautiful pattern”–Shinichiro Hamaji • shinh award: “Most fragile” – NAKAMURA Usaku • matz award: “Matz Lisp award” – Kazuki Tsujimoto • mame award: “Most timely” – Koichi Sasada • eban award: “Best document” – yoshi-taka • eto award: “Most illusionistic” – Don Yang • leonid award: “Most inconsistent” – Koichi Sasada
  • 66. “Best piphilology” – kinaba “Most unreadable ALU” – Keisuke Nakano “Doubling amphisbaena award” – monae “Least general solver” – Benoit Daloze “Most general solver” – Keisuke Nakano 4th 5th
  • 67. • Dishonor: the title of “insane” • Top five entries will be checked into the Ruby official repository in “sample” directory – Ruby 2.3.0 will have them (perhaps)
  • 68. • The winning entries will be published soon at: • Thank you for all participants! • See you in the next TRICK 201X! No k! http://github.com/tric /trick2015/