Upgrade to Pro — share decks privately, control downloads, hide ads and more …

An Invitation to TRICK: How to write weird Ruby...

Yusuke Endoh
November 15, 2024
280

An Invitation to TRICK: How to write weird Ruby programs

Yusuke Endoh

November 15, 2024
Tweet

Transcript

  1. code.rb $ ruby code.rb No, you have to copy the

    whole text, from "You don't know" to the end" ';BEGIN{eval$q=%q(def don(e)=e;def You(g)=at_exit{puts"You don'#{g}';BEGIN{eval$q=%q(#$q)};$s=%!#$s!"})};$s=%! puts %(Nb, lbh unir gb pbcl gur jubyr grkg, sebz "Ybh qba'g xabj" gb gur raq").tr("a-z","n-za-m")
  2. The abstract You don't know truly weird Ruby yet, do

    you? TRICK is an irregularly held Ruby programming contest that celebrates the most creative and weird Ruby programs. Among the many submissions, about a dozen particularly exceptional entries are awarded. Curious about what kind of programs win? It is a code like this, this whole text itself. ';BEGIN{eval$q=%q(def don(e)=e;def You(g)=at_exit{puts"You don'#{g}';BEGIN{eval$q=%q(#$q)};$s=%!#$s!"})};$s=%! puts %(Nb, lbh unir gb pbcl gur jubyr grkg, sebz "Ybh qba'g xabj" gb gur raq").tr("a-z","n- za-m") In this talk, we will showcase the winning entries from past TRICK contest and our own weird Ruby code. We will explore various techniques for writing such programs. By the end of this talk, you'll be ready to submit your original Ruby creations to TRICK 2025! This is the abstract for this talk, and IS a Ruby code that prints the code itself
  3. Introduction and this talk • Yusuke Endoh (mame, @mametter) –

    A full-time Ruby committer at STORES, Inc. • Ruby's keyword arguments • Single-line def (as April Fool joke) • TypeProf – A weird Ruby programmer • This talk will – Introduce some weird Ruby programs – Briefly explain the tips to write weird Ruby programs
  4. cfp-quine.rb You don't know truly weird Ruby yet, do you?

    TRICK is an irregularly held Ruby programming contest that celebrates the most creative and weird Ruby programs. Among the many submissions, about a dozen particularly exceptional entries are awarded. Curious about what kind of programs win? It is a code like this, this whole text itself. ';BEGIN{eval$q=%q(def don(e)=e;def You(g)= at_exit{puts"You don'#{g}';BEGIN{eval$q=%q(#$q)};$s=%!#$s!"})};$s=%! puts %(Nb, lbh unir gb pbcl gur jubyr grkg, sebz "Ybh qba'g xabj" gb gur raq").tr("a-z","n- za-m") In this talk, we will showcase the winning entries from past TRICK contest and our own weird Ruby code. We will explore various techniques for writing such programs. By the end of this talk, you'll be ready to submit your original Ruby creations to TRICK 2025!
  5. cfp-quine.rb You don't know truly weird Ruby yet, do you?

    x x TRICK is an irregularly held Ruby programming contest that celebrates the most creative and weird Ruby programs. Among the many submissions, about a dozen particularly exceptional x entries are awarded. x x Curious about what kind of programs win? It is a code like this, this whole text itself. x x ';BEGIN{eval$q=%q(def don(e)=e;def You(g)= at_exit{puts"You don'#{g}';BEGIN{eval$q=%q(#$q)};$s=%!#$s!"})};$s=%! x puts %(Nb, lbh unir gb pbcl gur jubyr grkg, sebz "Ybh qba'g xabj" gb gur raq").tr("a-z","n- za-m") x x In this talk, we will showcase the winning entries from past TRICK contest and our own x weird Ruby code. x We will explore various techniques for writing such programs. x By the end of this talk, you'll be ready to submit your original Ruby creations to TRICK x 2025! A String literal Method calls to "don" and "You": You(don("…")) Quine: printing self
  6. Tip: Quine (self-reproducing program) • This program outputs the program

    itself s=%q( puts "s=%q(#{ s }); eval(s)" ); eval(s) $ ruby quine.rb s=%q( puts "s=%q(#{ s }); eval(s)" ); eval(s)
  7. TRICK: A contest for weird Ruby programs mametter eto shinh

    yhara matz sunleonid flagitious TRICK 2022 Judges Transcendental Ruby Imbroglio Contest for RubyKaigi
  8. TRICK: A contest for weird Ruby programs • Four TRICKs

    held in the past – TRICK 2013 – TRICK 2015 – TRICK 2018 (FINAL) – TRICK 2022 (Returns) • Today, I will pick up only four or five winning entries – All winning entries are published in: No k! http://github.com/tric /
  9. TRICK 2022: "Most global" award by mame (me!) a=0132;eval$s=%q!eval(%q~d,h,Y ___---------___

    ,X=*$*.map(&:to_i),45;b=(a+d)% R=360;s=[v=[include(Math)]] _--- ---_ ;T=PI*2;n=x=0;f=->{(n/=2)%2 >0?1:f[]*2+(n/=2)%2};g=- _- v@v ,,,,,, -_ >{z=f[];z/2*(3-z%2*6)};" 8'8f'y;I;asr1mY?Sr$6r _- ,vv@@@@@@@^''@v,-_ {+Gi{03G3=ZbpUo3l'}Yw C<Sl;J'x4aQbMAAD}c_@ / ^^^^^^@@@@@@vvv@@@@\ hG],qDu/[eKyo/rD919e TPva4BX7FC%#AuzChg / ,v@@vvv,, ^@ ^@@@@@@@@@\ uS)EmfeV+.m:*k@q)Z =VxSFP>qxJfHIWd'R /v ,@@@@@@@@@@@v ^^^'''^@@@@\ MUS4&$r3D>GqL((/C ea&e'|PS@3aQ@-hL /@@ ,v@@@@@@@@@@@@@@v, '*v, '^@\ ja+/Lru>]96]d_4W 9o][*A;J&..;a?@ /@@@ @@@@@@@@@@@@@@@@@@@v,,,@@@@@ @@\ O'x.RmTPRK+Pol# U;o_wP`}6.g#?y |@@@@v, '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@| 0`.lHNxLXjI^#S 5F-XcldGh_BZDc |@@@@@^ '^^@@@@@@@@@@@@@@@@@'@@@@ '@@@@| JTLKD)#e*CUo$. {c&a46;+AaGW*M |@@@@' '^@@@@@@@@@@@@@ @@@@@v '@@| R5".bytes{n=n* 90+-_1%91};190 |@@^ @@@@@@@@@@@@@ ^^^''' '@| .times{x+=e=(g []+g[].i)*T/R; |^' @@@@@@@@@@@@@vv, @| e==0?s<<v=[]:v <<v[0]=x.rect} | @@@@@@@@@@@@@^' @ | ;$><<(1..(d==0 ?h*w=h*4:25*w= | ,@@@@@@@@@@@^' | 80)).map{|i|q= i/w*6+3;r=i%w;" \ v@@@@@@@@@@@ / \s'*^,:v@\nXa=# {"%04o"%b};eval$ \ @@@@@@@@@@@@ / s=%q\x21#$s\x21" [r>0?X&&r==(X+168 \ @@@@@@@@^' ,v* / )%R*w/R&&q/6==(90 -Y)*h/180?9:(0..2) \ ^^^^^^' ,^ / .all?{e=d==0?cos(q* T/w/3):(r*3i-120i-q+ \ / 73)/Complex.polar(72 ,2/4.9);q-=2;y,x=e.re -_, _- ct;e.abs<1&&n+=n-s.ma p{|s|z=sqrt(1-y*y);c=d== -_v,, _- 0?r*T/(1-w):b*T/R+acos(x );g=0;s.sum{(g-g=atan2(sin( --__v, __-- o=_1+c),z/tan(_2)+y*cos(o)) /T).round}}.min/9}?n%8:i+9:8]} ```---------``` *""~.gsub(/\x20.*\x20|\n/){})!
  10. TRICK 2022: mame.rb • It prints itself with a globe

    rotated 45 degrees – Eight execution will return the original code a=0132;eval$s=%q!eval(%q~d,h,Y ___---------___ ,X=*$*.map(&:to_i),45;b=(a+d)% R=360;s=[v=[include(Math)]] _--- ---_ ;T=PI*2;n=x=0;f=->{(n/=2)%2 >0?1:f[]*2+(n/=2)%2};g=- _- v@v ,,,,,, -_ >{z=f[];z/2*(3-z%2*6)};" 8'8f'y;I;asr1mY?Sr$6r _- ,vv@@@@@@@^''@v,-_ {+Gi{03G3=ZbpUo3l'}Yw C<Sl;J'x4aQbMAAD}c_@ / ^^^^^^@@@@@@vvv@@@@\ hG],qDu/[eKyo/rD919e TPva4BX7FC%#AuzChg / ,v@@vvv,, ^@ ^@@@@@@@@@\ uS)EmfeV+.m:*k@q)Z =VxSFP>qxJfHIWd'R /v ,@@@@@@@@@@@v ^^^'''^@@@@\ MUS4&$r3D>GqL((/C ea&e'|PS@3aQ@-hL /@@ ,v@@@@@@@@@@@@@@v, '*v, '^@\ ja+/Lru>]96]d_4W 9o][*A;J&..;a?@ /@@@ @@@@@@@@@@@@@@@@@@@v,,,@@@@@ @@\ O'x.RmTPRK+Pol# U;o_wP`}6.g#?y |@@@@v, '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@| 0`.lHNxLXjI^#S 5F-XcldGh_BZDc |@@@@@^ '^^@@@@@@@@@@@@@@@@@'@@@@ '@@@@| JTLKD)#e*CUo$. {c&a46;+AaGW*M |@@@@' '^@@@@@@@@@@@@@ @@@@@v '@@| R5".bytes{n=n* 90+-_1%91};190 |@@^ @@@@@@@@@@@@@ ^^^''' '@| .times{x+=e=(g []+g[].i)*T/R; |^' @@@@@@@@@@@@@vv, @| e==0?s<<v=[]:v <<v[0]=x.rect} | @@@@@@@@@@@@@^' @ | ;$><<(1..(d==0 ?h*w=h*4:25*w= | ,@@@@@@@@@@@^' | 80)).map{|i|q= i/w*6+3;r=i%w;" \ v@@@@@@@@@@@ / \s'*^,:v@\nXa=# {"%04o"%b};eval$ \ @@@@@@@@@@@@ / s=%q\x21#$s\x21" [r>0?X&&r==(X+168 \ @@@@@@@@^' ,v* / )%R*w/R&&q/6==(90 -Y)*h/180?9:(0..2) \ ^^^^^^' ,^ / .all?{e=d==0?cos(q* T/w/3):(r*3i-120i-q+ \ / 73)/Complex.polar(72 ,2/4.9);q-=2;y,x=e.re -_, _- ct;e.abs<1&&n+=n-s.ma p{|s|z=sqrt(1-y*y);c=d== -_v,, _- 0?r*T/(1-w):b*T/R+acos(x );g=0;s.sum{(g-g=atan2(sin( --__v, __-- o=_1+c),z/tan(_2)+y*cos(o)) /T).round}}.min/9}?n%8:i+9:8]} ```---------``` *""~.gsub(/\x20.*\x20|\n/){})! a=0207;eval$s=%q!eval(%q~d,h,Y ___---------___ ,X=*$*.map(&:to_i),45;b=(a+d)% R=360;s=[v=[include(Math)]] _---@^^@@, ^@@@@---_ ;T=PI*2;n=x=0;f=->{(n/=2)%2 >0?1:f[]*2+(n/=2)%2};g=- _-@@@''''' *^ ''^^^v-_ >{z=f[];z/2*(3-z%2*6)};" 8'8f'y;I;asr1mY?Sr$6r _-^''@^ -_ {+Gi{03G3=ZbpUo3l'}Yw C<Sl;J'x4aQbMAAD}c_@ /@^, \ hG],qDu/[eKyo/rD919e TPva4BX7FC%#AuzChg / '@ \ uS)EmfeV+.m:*k@q)Z =VxSFP>qxJfHIWd'R / ^@ ^@v\ MUS4&$r3D>GqL((/C ea&e'|PS@3aQ@-hL / ,,v@@@@\ ja+/Lru>]96]d_4W 9o][*A;J&..;a?@ / v@@@vv, ,:'''''@\ O'x.RmTPRK+Pol# U;o_wP`}6.g#?y | @@@@@@@@v ,v@@@@@@vv^ | 0`.lHNxLXjI^#S 5F-XcldGh_BZDc | @@@@@@@@@@, v@@@@@@@@@@@, | JTLKD)#e*CUo$. {c&a46;+AaGW*M | @@@@@@@@@@@ v@@@@@@@@@@@@@@@| R5".bytes{n=n* 90+-_1%91};190 | ^@@@@@@@@@@@v, @@@@@@@@@@@@@@@| .times{x+=e=(g []+g[].i)*T/R; | @@@@@@@@@@@@@@ '@@@@@@@@@@@@@@| e==0?s<<v=[]:v <<v[0]=x.rect} | @@@@@@@@@@@@@' ''^@@@@@@@@@@| ;$><<(1..(d==0 ?h*w=h*4:25*w= | ,@@@@@@@@@@@@^ @@@@@@@v| 80)).map{|i|q= i/w*6+3;r=i%w;" \ v@@@@@@@@^^'' @@@@@@^/ \s'*^,:v@\nXa=# {"%04o"%b};eval$ \@@@@@^' @@@@@@'/ s=%q\x21#$s\x21" [r>0?X&&r==(X+168 \^' v@@@@@ / )%R*w/R&&q/6==(90 -Y)*h/180?9:(0..2) \ v@@@@@/ .all?{e=d==0?cos(q* T/w/3):(r*3i-120i-q+ \ @@@@@/ 73)/Complex.polar(72 ,2/4.9);q-=2;y,x=e.re -_ @@@_- ct;e.abs<1&&n+=n-s.ma p{|s|z=sqrt(1-y*y);c=d== -_ _- 0?r*T/(1-w):b*T/R+acos(x );g=0;s.sum{(g-g=atan2(sin( --__ __-- o=_1+c),z/tan(_2)+y*cos(o)) /T).round}}.min/9}?n%8:i+9:8]} ```---------``` *""~.gsub(/\x20.*\x20|\n/){})! 45-degree rotation
  11. TRICK 2022: mame.rb • Features – The rotation angle can

    be specified: ruby mame.rb 30 – The map can be dumped • Techniques – ASCII-art code – Stateful quine – Some algorithm (Compression of polygon map data) – Some math (Spherical trigonometry)
  12. Tips: ASCII-art programming in Ruby • %w (string array notation)

    • with Array#join %w(foo bar) #=> ["foo", "bar"] %w(foo bar).join #=> "foobar"
  13. Tips: ASCII-art programming in Ruby (cont'd) • … with "eval"

    • Now able to format Ruby code as you like eval(%w( pu ts "H el lo ,w or ld ").join) #=> Hello,world eval %w(p u t s " h i ").join #=> hi
  14. Stateful Quine • Non-stateful Quine • Stateful Quine eval s=%q(puts

    " eval s=%q(#{s})") n=1;eval s=%q(puts "n=#{n+1};eval s=%q(#{s})") $ ruby stateful-quine.rb n=2;eval s=%q(puts "n=#{n+1};eval s=%q(#{s})") $ ruby stateful-quine.rb | ruby n=3;eval s=%q(puts "n=#{n+1};eval s=%q(#{s})") $ ruby stateful-quine.rb | ruby | ruby n=4;eval s=%q(puts "n=#{n+1};eval s=%q(#{s})")
  15. TRICK 2022: "Best fishbowl" award by tompng eval((s=%~c=(0..35 ).map{s[2*_1+1]}*'';class$Inte ger;def$quXinclude(Math

    ;spXo(a)=self* a.pow(87X=h=32.chr;g=PI/480;ls=(sp*31X,89)%89; def$abX+'eval((s=%'+(n=? .next)+s*88.chr+[nXs()=[a =self%X+'.split(',sp*25+'?'+88.chr+');(0..36).mapX89,89- a].miX{s[2*_1].split}',sp*31+".join.tr('$',$/)))"]*$/)Xn;end ;reqX.split$/;trap(:INT){puts;exit};q=->t,i{a,y=((t+i*99)Xuire 'matrX%960). ivmod(80);[(a*(7+i)+i*23)%79+(y+a)/(5+i%4)%2,39Xix';1 5.tiX-y/2]};p=->t,u{a=->b,c{(0..5).sum{(u%2-1)*E**(t*(b+c*_1)*gXmes{ |i,*X.i+ i*u+=5+sin(u*u))}};x,z=a[5,3]. 5,3].rect;x+=y.Xv|z= *?!Xi a[19,4];z+=w;r=(4+(x.abs+z.i).ab };t=(0..959).fX..? W,?Xind{|t|(0..29).all?{x,y=q[t,_1];(x 2||h=ls[y][x]X[,* ?]..X[/[^!-}]/]}};h=($**h+h).chr;eval( []} ->(x,yX?};a =(0X,a,b){x=x*36+39.5;y=19.5-y*18;b*=1 |i|((yX..1 34)X-b).ceil..y+b).map{|j|((x-i)/a+(y j)/ .times{X.ma p{zXx,z=p[t,_1];l=u```=0;while``````(l<1)``; u+```=0 ;d=x-y;X.in dex(Xl+=(d.abs+(z-w``)``.i).ab``s*1.``1 ;x``,z=y``,w;o[v``=``x.r d.imag/Xc[i+ 15*Xd.abs*l*sin(2*``l-t``*g*80``-_1) l*(``1-l)/``6,a``=l*( -l)**2*0.X_1] )};X7,a*2]&&o[v,z,``0.0``3,l**`` ``times``{|i``|(8+i).times{|Xw=* MatXj|o[sin(i)/2+````` ```sin( `/2.0`````````)*j/200,j*0.0Xrix [*(X5-1,0.02,0.1]``}} ``. q[t,``_1];m``[y][x]= };i=-X0.. 44).X1;$><<(['%%','[H .map{|j|(0..79).map{|k|x=(Xmap{ |i,X -39.5)/35.8;y=( i+=1;m[j][k]?h:c[i]):ls[j]X*b| v<<X[k];}*''}*$/<<0) 1)%9 te"`")#qv.jSaL{=;q(Q}4fXa.z ip(Xjs(:#tK`Jm))FKO /A9(2'%iorvf7 eEa0uV xv+Q@qUU](L@&Py .1v'X0.. ).suXydSEH{-GI|-5(,z G5evpq,[b50 D[ t {on,I?VStS`?G@LoqFCXm{|j ,k|Xj1.QnxKz!mH%o# )b2Seut,]! 48 lBieJGi 5jeNPD#b}H3X-(p =(iXaVz#8*+US,hgF 5#6]y-` 4hy HN hF75WjD!0IxJ$sX+k) .powX+UP"cNUE9- G< tHvV;Ib <-s U T ? vlE xylg=x#X(i+k ,88)XV9u$9lKb9 @C do7+-w >l { v9 { P l ga%]AK<e&'X+1)* (j||(X4ifK/6S+ k} @@*a} 6rS xn"Q[M 8 `|g>$#BrjXb<<p; 0))}XtbDp'Kc t2 Dat9C s C rL+ g,j]Tf B< eMI+zzkWX;b}] .lup.XtVP<ak IM E/+)B jwv uB (Twqed D* dyf_dT7Xsolve (v);13Xn:8 #_ RiSTO, [Fk m O]O#"+ a_ cT_.X5.time s{c[i+X e5 T`FBEC q*f 2 o@{a<eUG aW PX15*_1] =z[a[_1]X z_@`nll 7F1 2 [=^uS0z^ 6X||w.shif t]}};eval(Xfg K#R N bp-E_Xc)~.split( ?X);(0..36).map{s[2*_1].split} .join.tr('$',$/)))
  16. tompng.rb • 960-frame fishbowl animation – Each frame is an

    executable Ruby code (Quine) • Techniques – ASCII-art code – Stateful Quine – 2D graphics for fish and grass – Error correction
  17. tompng3.rb eval((s=%~c=(0..35 ).map{s[2*_1+1]}*'';class$Inte ger;def$quXinclude(Math ;spXo(a)=self* a.pow(87X=h=32.chr;g=PI/480;ls=(sp*31X,89)%89; def$abX+'eval((s=%'+(n=? .next)+s*88.chr+[nXs()=[a =self%X+'.split(',sp*25+'?'+88.chr+');(0..36).mapX89,89- a].miX{s[2*_1].split}',sp*31+".join.tr('$',$/)))"]*$/)Xn;end

    ;reqX.split$/;trap(:INT){puts;exit};q=->t,i{a,y=((t+i*99)Xuire 'matrX%960). ivmod(80);[(a*(7+i)+i*23)%79+(y+a)/(5+i%4)%2,39Xix';1 5.tiX-y/2]};p=->t,u{a=->b,c{(0..5).sum{(u%2-1)*E**(t*(b+c*_1)*gXmes{ |i,*X.i+ i*u+=5+sin(u*u))}};x,z=a[5,3]. 5,3].rect;x+=y.Xv|z= *?!Xi a[19,4];z+=w;r=(4+(x.abs+z.i).ab };t=(0..959).fX..? W,?Xind{|t|(0..29).all?{x,y=q[t,_1];(x 2||h=ls[y][x]X[,* ?]..X[/[^!-}]/]}};h=($**h+h).chr;eval( []} ->(x,yX?};a =(0X,a,b){x=x*36+39.5;y=19.5-y*18;b*=1 |i|((yX..1 34)X-b).ceil..y+b).map{|j|((x-i)/a+(y j)/ .times{X.ma p{zXx,z=p[t,_1];l=u```=0;while``````(l<1)``; u+```=0 ;d=x-y;X.in dex(Xl+=(d.abs+(z-w``)``.i).ab``s*1.``1 ;x``,z=y``,w;o[v``=``x.r d.imag/Xc[i+ 15*Xd.abs*l*sin(2*``l-t``*g*80``-_1) l*(``1-l)/``6,a``=l*( -l)**2*0.X_1] )};X7,a*2]&&o[v,z,``0.0``3,l**`` ``times``{|i``|(8+i).times{|Xw=* MatXj|o[sin(i)/2+````` ```sin( `/2.0`````````)*j/200,j*0.0Xrix [*(X5-1,0.02,0.1]``}} ``. q[t,``_1];m``[y][x]= };i=-X0.. 44).X1;$><<(['%%','[H .map{|j|(0..79).map{|k|x=(Xmap{ |i,X -39.5)/35.8;y=( i+=1;m[j][k]?h:c[i]):ls[j]X*b| v<<X[k];}*''}*$/<<0) 1)%9 te"`")#qv.jSaL{=;q(Q}4fXa.z ip(Xjs(:#tK`Jm))FKO /A9(2'%iorvf7 eEa0uV xv+Q@qUU](L@&Py .1v'X0.. ).suXydSEH{-GI|-5(,z G5evpq,[b50 D[ t {on,I?VStS`?G@LoqFCXm{|j ,k|Xj1.QnxKz!mH%o# )b2Seut,]! 48 lBieJGi 5jeNPD#b}H3X-(p =(iXaVz#8*+US,hgF 5#6]y-` 4hy HN hF75WjD!0IxJ$sX+k) .powX+UP"cNUE9- G< tHvV;Ib <-s U T ? vlE xylg=x#X(i+k ,88)XV9u$9lKb9 @C do7+-w >l { v9 { P l ga%]AK<e&'X+1)* (j||(X4ifK/6S+ k} @@*a} 6rS xn"Q[M 8 `|g>$#BrjXb<<p; 0))}XtbDp'Kc t2 Dat9C s C rL+ g,j]Tf B< eMI+zzkWX;b}] .lup.XtVP<ak IM E/+)B jwv uB (Twqed D* dyf_dT7Xsolve (v);13Xn:8 #_ RiSTO, [Fk m O]O#"+ a_ cT_.X5.time s{c[i+X e5 T`FBEC q*f 2 o@{a<eUG aW PX15*_1] =z[a[_1]X z_@`nll 7F1 2 [=^uS0z^ 6X||w.shif t]}};eval(Xfg K#R N bp-E_Xc)~.split( ?X);(0..36).map{s[2*_1].split} .join.tr('$',$/))) Quine Error correction (Corrupted) redundant data for error correction (Corrupted) 2D graphics code
  18. tompng3.rb eval((s=%~c=(0..35 ).map{s[2*_1+1]}*'';class$Inte ger;def$quXinclude(Math);spXo(a)=self* a.pow(87X=h=32.chr;g=PI/480;ls=(sp*31X,89)%89; def$abX+'eval((s=%'+(n=?}.next)+s*88.chr+[nXs()=[a =self%X+'.split(',sp*25+'?'+88.chr+');(0..36).mapX89,89- a].miX{s[2*_1].split}',sp*31+".join.tr('$',$/)))"]*$/)Xn;end ;reqX.split$/;trap(:INT){puts;exit};q=->t,i{a,y=((t+i*99)Xuire 'matrX%960).divmod(80);[(a*(7+i)+i*23)%79+(y+a)/(5+i%4)%2,39Xix';1

    5.tiX-y/2]};p=->t,u{a=->b,c{(0..5).sum{(u%2-1)*E**(t*(b+c*_1)*gXmes{ |i,*X.i+6i*u+=5+sin(u*u))}};x,z=a[5,3].rect;y,w=a[5,3].rect;x+=y.Xv|z= *?!Xi+a[19,4];z+=w;r=(4+(x.abs+z.i).abs)/1.5;[x/r,z/r]};t=(0..959).fX..? W,?Xind{|t|(0..29).all?{x,y=q[t,_1];(x+y*2i-40-40i).abs>32||h=ls[y][x]X[,* ?]..X[/[^!-}]/]}};h=($**h+h).chr;eval(%!loop{m=(0..39).map{[]};o=->(x,yX?};a =(0X,a,b){x=x*36+39.5;y=19.5-y*18;b*=18;((x-a*=36).ceil..x+a).map{|i|((yX..1 34)X-b).ceil..y+b).map{|j|((x-i)/a+(y-j)/b.i).abs<1&&m[j][i]=1}}};3.times{X.ma p{zXx,z=p[t,_1];l=u```=0;while``````(l<1)``;y,w``=p[t-u+```=0.2,_1];d=x-y;X.in dex(Xl+=(d.abs+(z-w``)``.i).ab``s*1.``15;x``,z=y``,w;o[v``=``x.real+d.imag/Xc[i+ 15*Xd.abs*l*sin(2*``l-t``*g*80``-_1)``/8,z``+l*(``1-l)/``6,a``=l*(1-l)**2*0.X_1] )};X7,a*2]&&o[v,z,``0.0``3,l**``4/`6``]end``};8.``times``{|i``|(8+i).times{|Xw=* MatXj|o[sin(i)/2+`````````sin(``-t*```g*20``+i+j``/2.0`````````)*j/200,j*0.0Xrix [*(X5-1,0.02,0.1]``}};30``.time`````s``{x,y``````=q[t,``_1];m``[y][x]=1};i=-X0.. 44).X1;$><<(['%%','[H','[J%;'<<13]*27.chr+(0..39).map{|j|(0..79).map{|k|x=(Xmap{ |i,Xk-39.5)/35.8;y=(j-19.5)/17.9;(1>r=x*x+y*y)?(i+=1;m[j][k]?h:c[i]):ls[j]X*b| v<<X[k];}*''}*$/<<0);t=(t+1)%960;sleep(0.05)}!.delete"`")#qv.jSaL{=;q(Q}4fXa.z ip(Xjs(:#tK`Jm))FKOwC#/A9(2'%iorvf7SeEa0uV=&$L9<B9BWxv+Q@qUU](L@&Py+.1v'X0.. ).suXydSEH{-GI|-5(,ztM*G5evpq,[b50alD[]gPtx[f_?);U^({on,I?VStS`?G@LoqFCXm{|j ,k|Xj1.QnxKz!mH%o#|Fkx)b2Seut,]!L^A482w4ndu'W<vIoB=lBieJGiL5jeNPD#b}H3X-(p =(iXaVz#8*+US,hgFR5epB5#6]y-`K)o@4hy/e?19ewhk5pOw!VHN^hF75WjD!0IxJ$sX+k) .powX+UP"cNUE9-ApG<P,tHvV;IbV(V&<-s!Wj}dob"0hGUp?TW?q4vlECxylg=x#X(i+k ,88)XV9u$9lKb9rD@C9ledo7+-w;c6>lx{+8+H1v9"l[{L.FP)l|Dga%]AK<e&'X+1)* (j||(X4ifK/6S+24k}A[:@@*a}t96rS)PB?16xn"Q[MA{x8inVz`|g>$#BrjXb<<p; 0))}XtbDp'Kc}.bt2<MDat9Cn?s{C>$rL+5g,j]Tf1^B<ImWIeMI+zzkWX;b}] .lup.XtVP<akI<IMdTE/+)BJAjwv4`uBNk(TwqedgWD*UU5dyf_dT7Xsolve (v);13Xn:8Nq#_i^RiSTO,%'[FkJ<msnO]O#"+aIa_%SCcT_.X5.time s{c[i+Xc}e5D{T`FBEC):q*fB_2Vo@{a<eUG:aW1q<PX15*_1] =z[a[_1]Xvz_@`nllFI7F1(]2-[=^uS0z^F(6X||w.shif t]}};eval(XfgwwK#RK:Njbp-E_Xc)~.split( ?X);(0..36).map{s[2*_1].split} .join.tr('$',$/))) Quine Error correction (Recovered) redundant data for error correction (Recovered) 2D graphics code
  19. Note • Both of the above two were Quine •

    But TRICK is not a contest for Quine
  20. TRICK 2013: "Best pangram" award by kinaba • This code

    consists of all printable ASCII characters (32..126) • This code outputs all printable ASCII characters !@THEqQUICKbBROWNfFXjJMPSvVLAZYDGgkyz&[%r{\"}mosx,4>6]|?'while(putc 3_0-~$.+=9/2^5;)<18*7and:`# $ ruby kinaba1.rb !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
  21. kinaba1.rb • Under a pangram – A local variable: You

    can define one, but you cannot read it – A number: Need to make by calculation – Unneeded symbols: Need to discard well \"}mosx,4>6]|?'while(putc 3_0-~$.+=9/2^5;)<18*7and:`# Use of a special variable $. 9/2^5 = 1 3_0 = 30 18*7 = 126
  22. TRICK 2018: "Most reserved" award by kinaba • This is

    a no-op program that consists only of all reserved words alias BEGIN for unless def class super true or return defined? next break while begin undef do end rescue then retry else undef module nil ensure case if yield __LINE__ self and redo elsif not __FILE__ alias END in end when __ENCODING__ end until false end
  23. TRICK 2022: "Most anti-gravity" award by mame 2022;"# .chars} {puts'TRICK+2022'

    \ { ; #';$><< b ?! };#{s=' ' # 0 ! s[0]? ( b=$<.read ;' } ub( ,''} ';a= ''<<32 b.lines {puts( ?.. *( b.size) .gsub(/./) { b.sub!( /^#$`\K(\S) /x,a)?$1:a } .rstrip)}): ( [ 12,1,12,11]. cycle { | i | t = ( s * 10<< 10)* 10+ %(\e[A)* 10 10. times{t[i* _1 ] = 'TRICK+2022'[ _1 ] };$><<t sleep 1}) }" Ticker of "TRICK+2022"
  24. mame2.rb 2022;"# .chars} {puts'TRICK+2022' \ { ; #';$><< b ?!

    };#{s=' ' # 0 ! s[0]? ( b=$<.read ;' } ub( ,''} ';a= ''<<32 b.lines {puts( ?.. *( b.size) .gsub(/./) { b.sub!( /^#$`\K(\S) /x,a)?$1:a } .rstrip)}): ( [ 12,1,12,11]. cycle { | i | t = ( s * 10<< 10)* 10+ %(\e[A)* 10 10. times{t[i* _1 ] = 'TRICK+2022'[ _1 ] };$><<t sleep 1}) }" 2022;"# .chars}{puts'TRICK+2022' \{; #';$><<b ?! };#{s=''#0 !s[0]?(b=$<.read;' }ub(,''} ';a=''<<32 b.lines{puts(?..*( b.size).gsub(/./){ b.sub!(/^#$`\K(\S) /x,a)?$1:a} .rstrip)}): ([12,1,12,11]. cycle{|i|t=(s* 10<< 10)* 10+%(\e[A)* 10 10.times{t[i* _1]='TRICK+2022'[ _1]};$><<t sleep1}) }" left gravity up.rb: "Upward gravity" program
  25. mame2.rb 2022;"# .chars} {puts'TRICK+2022' \ { ; #';$><< b ?!

    };#{s=' ' # 0 ! s[0]? ( b=$<.read ;' } ub( ,''} ';a= ''<<32 b.lines {puts( ?.. *( b.size) .gsub(/./) { b.sub!( /^#$`\K(\S) /x,a)?$1:a } .rstrip)}): ( [ 12,1,12,11]. cycle { | i | t = ( s * 10<< 10)* 10+ %(\e[A)* 10 10. times{t[i* _1 ] = 'TRICK+2022'[ _1 ] };$><<t sleep 1}) }" 2022;"# {puts'TRICK+2022'} .chars} \ #{b=$<.read;0;'( #';$><< b .gsub(''<<32,'') };#?!=' ' 12,{puts()?..\*: !;s{s]? ( i |ub(/./`\{(}S* }.a[0es [ = s/x/^#$$1Ka[}[ '.l=ne) | 1,,a)?ri:)2) b.siz!( ] 't.rst1]p* i bysib1( ] lT12,1[s.* ' b0cue1{ }%=\(eA)t c0<l_ eR(ie+s{2 10)<_ ;tCm<20 10+* eI>K}t 10. }$ < ) 1 p 1 1 " upward gravity left.rb: "Left gravity" program
  26. mame2.rb 2022;"# .chars} {puts'TRICK+2022' \ { ; #';$><< b ?!

    };#{s=' ' # 0 ! s[0]? ( b=$<.read ;' } ub( ,''} ';a= ''<<32 b.lines {puts( ?.. *( b.size) .gsub(/./) { b.sub!( /^#$`\K(\S) /x,a)?$1:a } .rstrip)}): ( [ 12,1,12,11]. cycle { | i | t = ( s * 10<< 10)* 10+ %(\e[A)* 10 10. times{t[i* _1 ] = 'TRICK+2022'[ _1 ] };$><<t sleep 1}) }" 2022;"# {puts'TRICK+2022'} .chars} \ #{b=$<.read;0;'( #';$><< b .gsub(''<<32,'') };#?!=' ' 12,{puts()?..\*: !;s{s]? ( i |ub(/./`\{(}S* }.a[0es [ = s/x/^#$$1Ka[}[ '.l=ne) | 1,,a)?ri:)2) b.siz!( ] 't.rst1]p* i bysib1( ] lT12,1[s.* ' b0cue1{ }%=\(eA)t c0<l_ eR(ie+s{2 10)<_ ;tCm<20 10+* eI>K}t 10. }$ < ) 1 p 1 1 " 2022;"#{puts'TRICK+2022'} .chars}\#{b=$<.read;0;'( #';$><<b.gsub(''<<32,'') };#?!=''12,{puts()?..\*: !;s{s]?(i|ub(/./`\{(}S* }.a[0es[=s/x/^#$$1Ka[}[ '.l=ne)|1,,a)?ri:)2) b.siz!(]'t.rst1]p*i bysib1(]lT12,1[s.*' b0cue1{}%=\(eA)t c0<l_eR(ie+s{2 10)<_;tCm<20 10+*eI>K}t 10.}$<) 1p1 1" Prints "TRICK+2022" up and then left
  27. mame2.rb 2022;"# .chars} {puts'TRICK+2022' \ { ; #';$><< b ?!

    };#{s=' ' # 0 ! s[0]? ( b=$<.read ;' } ub( ,''} ';a= ''<<32 b.lines {puts( ?.. *( b.size) .gsub(/./) { b.sub!( /^#$`\K(\S) /x,a)?$1:a } .rstrip)}): ( [ 12,1,12,11]. cycle { | i | t = ( s * 10<< 10)* 10+ %(\e[A)* 10 10. times{t[i* _1 ] = 'TRICK+2022'[ _1 ] };$><<t sleep 1}) }" Prints "TRICK+2022" vertically left and then up 2022;"# .chars}{puts'TRICK+2022' \{; #';$><<b ?! };#{s=''#0 !s[0]?(b=$<.read;' }ub(,''} ';a=''<<32 b.lines{puts(?..*( b.size).gsub(/./){ b.sub!(/^#$`\K(\S) /x,a)?$1:a} .rstrip)}): ([12,1,12,11]. cycle{|i|t=(s* 10<< 10)* 10+%(\e[A)* 10 10.times{t[i* _1]='TRICK+2022'[ _1]};$><<t sleep1}) }" 2022;"#{puts'TRICK+2022' .chars}b#0<.read;' \{;$><<'=$ts(?..*( #';{s='b32ub(/./){ ?!#0]?(}pu$`\K(\S) };[(,''<gs}1].2'[ !sb=''<{^#:(s* }uaines.:a1i*2 ';lize)/})=20 b.sub!(12,* b.sa)?$)|t[ b.,trip1A)+ /xs2,1,i{t .r1le{|[CK ([c<(\es<t cy<*imeI 10)%'TR< 10+t;$>) 10.=p1} 10]} 10]e _1e _1 sl }"
  28. mame2.rb • The TRICK for left gravity • The TRICK

    for upward gravity "\ #{code1} # {code2}" "\#{code1} #{code2}" left gravity "x x#{code1} xx{code2} " "x{code1} x#{code2} xx " upward gravity
  29. Are you getting interested? • Introduced weird Ruby programs and

    explained implementation tips – For other winning entries of TRICK, check: No k! http://github.com/tric /
  30. IMPORTANT NOTICE • We are accepting submissions for TRICK 2025!

    –Deadline: Feb. 28, 2025 – Announce: Apr. 16--18, 2025 @ RubyKaigi 2025 – We want your weird Ruby programs! http://github.com/tric/trick2025
  31. rubyconf-chicago-quine.rb eval$q=%q!z=%w~i:Er(>.YA$zlRYC(g])1yTn.DR:):kL*4$oKjR[vX6ZpI[$qvFXYf>'5ZC=ac;Bz'^A(zfLq&PwshzQ<nQH`?q=pq&6:o0OND[fu(?h=]g-oxA_ BoyUA<Z597|v#T1vC}Lu`-DOs=:4BD]uf4D1PqA`mI6kO$xkQZpv<D7QHN/pWF8sexo3(.?In9|$1.OU&nvtEL:Eq>m-c:](R&KZPz1y7WR(^e@7/8haoEl9&Ry;yG m^[:if(GV}BVEAHY60c7`>4x]Sh>S*Ibc88f$(-MHJd;>aC)T&/&{0IH(#J{i1=::a`cA.'Q3,/Cf$q4m60F2gD6|JNeXSECT2yNlTMM]hVPd{'ApbVng8;n|GTOnN yEWmYf-:]l`dQ$r+$`NV>A'cEj5bx1j.F|Q?&CFYW+e;NSR'/tc(?tSS}55nf6kn:b:Vo5%O6KCXy2CQYS<{YwsG$U{IcJT;`I$a&Zx|9iC6..G^20ra;ut=LFp^)P lOv4MZ/ #1]zM VnP_u rX4 4$hfs*

    ;G%yG >tO3K0.Bn nz'u &[lw us+mS r{Ol f&Y`0-' ^8u$J?F ^?Xe 6E`( Tf=Z1 Plm WS3K V]El CjGGe 3%cHWu0 y,IHw1^S Vj_nr i}P 2G L'zk }W1SC'@/rd)vRlv fcS%lUw +B/j= J,a AlqhI ib@ }Nv3R Mb5 '/8<5 '#jQDO TIM_[#MBox y8iTJ ;-Y W # 1J=N Sx,A|]da2>Fd^)7 +IF$}fu 0Cit cjWB gk-4u '`# MGj< Q1H[ B:(5R GJsnB X_U53OF<-sU #RoDL SiE x - ArRA M2ImaFuF<rJH>RL xk0&'lW FJ,,W dQ1Pq ?tw YRY0@U ; F++2Df ORl@,tcPBdv BN64m D%b m P 0%J4 -VAF3jGL u%za#kj cDtp <nEx <UDdN m?= i7`: p}US/}2 5|*)`f@5 G3jk%_|*{)3 #7W#w z_a D X )k)o nt|.t;[-hIfRb<d {`]<M=: M61w6 2ZR vV&:5 lM7 (/D:T dVxiw*9 5_CVw#Q%[} :s3L?CSP&c /WexU v;v M v 8uO` VRRcaw6R>}STK^U Mq>d<Ov NbwSx I)t 6G`fi xno </={ '7qX[(D B#bs^S+)ry= ==Q-L(L. <PLD[ o>x o1 E^Wc 9|,$a/rm,R2}|#z /Hode{j SA<|Q f;p' L;+# (xahkag5 `3K>YV-oURoyu 'Dkt 5'l0 fW`cY =_Ug w_bGU|>+9_9)V0. >BJ_*u&):C+?q7fB*R*,HkX?S,wGGmg/k,Jk4&_*h(XT=hcmFv$s5qk9zxtjAX@/;K^MVgFn$vtP*bPSeo'2?uN%kL_XD%Ga{BDjVLWW)|cMw:9^Vgr<6hE<5ffX-_ 7O^sJq#d`0xgT1e%:cuAoz0))T']sKhK&>'3^)HV3:c-F*yBQg{PKMeugAO-Vq?l|M?:0'$4n?+TR$DU*v-jk8$Q^-n2u;<n:|{tUhj+`z|/]ic17ww[[K%5x,$C{_ s>KDPl94AA6]d@+UTV&NYW^I$+g]tW:]vQP?Na5RU5owPqOu8$?98iOcH,j=*oAJH-jV1L<y{$UusH7cRsk*1%jL0Zv/r;Evc/fPIFG)>XBuH|Fc=*]U%sF&FmX/BX K+X(>A2h~*"";eval(%w~c=0;z.bytes{c=c *90+( _1-1 )%91-1};z =+"";(z<<c%250;c/=250)while(c>0);55.upto (249){z=z[2..].gsub(""<<_1){z[0,2]}};z=z.byt es. each_ slice(3).to _a;Z=32 .chr;E="\e[";W=[128]*S=846008;j=100;n=z.m ap{|v,t,l|l*=804;t>0?(n=t=(n)?n+t-1:t-1;t=55 *2* *((t- 4)/12.0);l. times{ |i|f=i*Math::PI*t/4020;W[j+i]+=v>0?[40-i/4 00.0,0].max*Math.sin(f/2):[10-i*8.0/l,0].ma x*M ath.s in(f+Math. sin(f ))}):(n=p;j+=l)};File.write("chicago.wav",[ "RIFF",S+36,"WAVEfmt"+Z,16,1,1,8040,8040, 1,8," data" ,S].pack ("A4VA 8VvvVVvvA4V")+W.pack("C*"));D=->i,n{E+"#{n}m #{(0..8).map{|y|a=3*2741[j=i%12];E+"#{y +31};#{ 1+x=y <5?i*2 1/12+74 2[j ]:i/12*21+j*3/5*3}H"+(y<5&&a<1?Z*2:"[#] "[x%3,y<5?3451[j]+1:a])}*""+E}m"};q=3 3.chr;$>< <"#\e [30m \n#{q=%(e val$q=%q#{q+$q+q};%:)}:\n__END__\n\e[ ?25l\e[H\e[J\e[1;30r";at_exit{puts(E +"r\e[43;1H \e[?2 5hc hicago.wav_is_sav ed".tr(?_,Z))};72.times{$><<D[_1,0];sle ep(0.05)};$><<E+'41;42HFred_Fisher:_ "Chi cago _-_That_T oddling_Town"'.tr(?_,Z);a=[];d=(0..30). map{[]};c=0;o=Time.now;q=q.gsub(Z){E+"#{42+$`.size/1890*2}m#{Z+E}m"}.lines;29.times{z<<[0,0,1]};356.downto(-28){|i|n=p;1while( (v,t,l),*z=z;t>0&&(a<<[v,n=(n)?n+t-1:t-1,l,?V];d[-1]<<[n,v*2+42]));l.times{b=[];s=[Z]*126;a.map{|v,t,l,h|l>0?(s[t/12*21+t%12*1 8/11+10+1930[t%12]]=E+"#{v*2+32}m#{h+E}m";b<<[v,t,l-1,?|]):d[-1].unshift([t,0])};a=b;$><<E+"H\e[1T#{(i>0?s*"":q.pop)+d.shift.m ap{|t,v|D[t+5,v]}*""}";d<<[];c+=1;1while(Time.now-o<c*0.1)}};exit;"__RubyConf_Chicago_Quine__(C)_Yusuke_Endoh_2024__"~*"")!;%: [# # #][# # # #][# # #][# # # #][# # #][# # # #][# # #][# # # #][# # #][# # # #][# # #][# # # #] [# # #][# # # #][# # #][# # # #][# # #][# # # #][# # #][# # # #][# # #][# # # #][# # #][# # # #] [# # #][# # # #][# # #][# # # #][# # #][# # # #][# # #][# # # #][# # #][# # # #][# # #][# # # #] [# # #][# # # #][# # #][# # # #][# # #][# # # #][# # #][# # # #][# # #][# # # #][# # #][# # # #] [# # #][# # # #][# # #][# # # #][# # #][# # # #][# # #][# # # #][# # #][# # # #][# # #][# # # #] [#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#] [#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#] [#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#] [#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#][#] Fred Fisher: "Chicago - That Toddling Town"