An Invitation to TRICK: How to write weird Ruby programs

Summarized using AI

An Invitation to TRICK: How to write weird Ruby programs

Yusuke Endoh • November 15, 2024 • Chicago, IL • Talk

An Invitation to TRICK: How to Write Weird Ruby Programs

In this engaging talk presented by Yusuke Endoh at RubyConf 2024, the focus is on the art of writing unconventional Ruby programs. The talk introduces the TRICK contest, which celebrates creativity in programming by rewarding the most unique and bizarre Ruby code submissions.

Key Points Discussed:

  • Understanding Weird Ruby Programs: The presenter begins by defining what constitutes a weird Ruby program, using examples from past submissions. The abstract of the talk itself serves as a prime illustration of executing Ruby code that outputs its own source code, or a 'Quine'.
  • Structure and Techniques: Yusuke explains the structure of weird Ruby code, highlighting methods that allow the output of the program to mimic the code itself. He breaks down complex code snippets into understandable parts, explaining how to manipulate code for various outputs.
  • Winning Entries from TRICK: The presenter shares several award-winning examples from previous TRICK contests:
    • Rotating Quine: A program that, when run, rotates its output at angles, illustrating creative coding.
    • Animated Fish: A visually striking Ruby program generating an animation of swimming fish, which is executed frame by frame.
    • Pangram Sentence: A Ruby program that outputs a complete set of alphabet letters utilizing all printable characters in clever ways.
    • All-Ruby Keywords: A unique entry containing all Ruby keywords in a sequence that produces no syntax errors upon execution.
    • Anti-Gravity Program: A complex program that manipulates strings by shifting characters based on execution context, showcasing a unique approach to coding.
  • Techniques for Writing Weird Programs: Throughout the presentation, Yusuke emphasizes techniques such as self-replicating code and quirky implementations to inspire attendees. He encourages the audience to be adventurous with Ruby, pointing out the language's flexibility.
  • Call for Participation: Yusuke wraps up his presentation by inviting viewers to submit their original Ruby programs for TRICK 2025, providing motivation and reassurance that great ideas can sprout from experimentation.

Main Takeaways:

  • The TRICK contest provides a platform for innovative and unconventional programming concepts, emphasizing Ruby's versatility.
  • Deconstructing winning entries can inspire new ideas in coding while fostering a community of creativity among Ruby developers.
  • Potential participants are encouraged to derive inspiration from the showcased examples and to embrace the unusual in their programming endeavors.

In summary, this talk not only highlights the fun and eccentricity of programming with Ruby but also acts as a catalyst for budding developers to explore the boundaries of their coding skills and creativity.

An Invitation to TRICK: How to write weird Ruby programs
Yusuke Endoh • November 15, 2024 • Chicago, IL • Talk

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!

RubyConf 2024

00:00:16.199 uh hello uh my name is Yus endo and in
00:00:20.039 this talk I will show you some Weir
00:00:23.560 programs so what is a weir we program uh
00:00:27.800 maybe you have already seen the first
00:00:30.439 example that I show you
00:00:32.480 today
00:00:38.040 and okay this is the schedule uh of the
00:00:41.920 satday
00:00:42.879 of and you are listening to this
00:00:47.920 talk uh the first we program is in its
00:00:54.480 abstract so you may be curious of this
00:00:58.920 part uh so let's copy and uh WR
00:01:09.159 it
00:01:12.479 oops
00:01:15.080 ABS the cryp this dis disappeared so I
00:01:19.280 need to
00:01:21.479 okay so save it as T
00:01:26.479 RB and then execute it
00:01:31.119 uh it PRS no you have to copy the whole
00:01:34.159 text from you don't know to the end so
00:01:38.079 let check the abstract again and so this
00:01:43.759 abstract starts here you don't know Ruby
00:01:48.560 we truly we Ruby so you need to copy
00:01:53.040 from here and to the end here
00:02:00.880 so let's
00:02:06.200 write save it t again and I maybe the
00:02:12.319 last space last line is not this and run
00:02:21.680 it do you
00:02:24.120 understand and this program I to put a
00:02:26.920 Tex can you see so this Tex is the same
00:02:30.800 as the source code itself this is source
00:02:33.480 code and this is the output oops so uh
00:02:39.040 let's confirm and the output is actually
00:02:43.920 uh s so
00:02:46.599 say save the output as uh name out and
00:02:52.640 compare between the original file TB and
00:02:57.519 the
00:02:58.480 AL okay
00:03:00.720 it says F and out ident so
00:03:05.720 confirmed so thank
00:03:11.080 you so the abstract description for this
00:03:15.120 talk is an executeable Ruby code that
00:03:17.920 output it the code itself it is uh isn't
00:03:21.400 it quite weird and
00:03:24.120 interesting okay
00:03:27.080 so turn to right
00:03:40.959 just a
00:03:42.159 minute
00:03:43.959 okay so keep this
00:03:48.080 and okay uh let me briefly introduce
00:03:50.920 myself here I'm
00:03:53.079 Uso I'm atime committer uh working at
00:03:56.799 stor Inc uh as well as uh
00:04:00.360 the previous
00:04:03.079 talk me
00:04:05.000 and you know and Stor is a Japanese
00:04:09.280 company uh providing software Service uh
00:04:12.959 to support small and medium siiz
00:04:15.919 stores okay so I thought my biggest
00:04:19.799 contribution to Ruby was the design and
00:04:22.440 implementation of keyword arguments I
00:04:24.680 think and I also propos a single R
00:04:28.320 method definition uh as an April Hood
00:04:31.880 joke and Matt picked this
00:04:37.639 sing uh in his day one keynote so this
00:04:41.560 picture might be more important than key
00:04:46.160 arguments okay so recently I'm
00:04:48.600 developing typ Pro and a tool for type
00:04:52.000 analysis of R Cod but uh today however I
00:04:56.880 will talk not as a committer but as a
00:05:00.560 weird
00:05:01.560 reprogrammer and therefore I will
00:05:04.280 introduce some weird but interesting
00:05:06.440 reprograms and run through the
00:05:09.199 techniques using in
00:05:11.360 them so first uh let's uh recap the
00:05:16.280 structure of the abstract Co for this
00:05:19.600 talk uh this Cod is highlighted so you
00:05:24.560 may see uh there are two big string lits
00:05:28.759 uh first one start with uh single quote
00:05:32.680 and uh end with uh single quote the
00:05:36.199 second one start pass b and end with B
00:05:40.680 so uh this program contains two big
00:05:43.560 string lit and here U and D so these are
00:05:49.919 uh method CES uh D and U so essentially
00:05:54.919 in other words uh this is the same as uh
00:05:58.240 you open parent don't open par close P
00:06:01.960 close p and the two methods are defined
00:06:07.400 here uh
00:06:09.560 here uh these definitions is uh in the
00:06:13.479 cap begin Brock cap begin Brocks uh so I
00:06:17.360 evaluate before the method Cod itself
00:06:20.319 and uh finally uh this program emits the
00:06:23.800 program
00:06:25.680 itself so C that uh output itself is
00:06:31.440 called
00:06:32.400 Quin uh it is named after a philosopher
00:06:36.360 uh famous philosopher named V woman
00:06:40.440 Quin from the previous Cod I extracted
00:06:43.319 only the essence of Quin part and this
00:06:46.639 is uh that one and this code when
00:06:50.199 executed uh prints uh itself so oops
00:06:55.639 this this and this are same and I don't
00:06:59.000 have time to go into its detail but I
00:07:02.080 will publish these slides so please take
00:07:04.560 a look uh later so okay now uh I will
00:07:10.800 show you the winning entries of uh trick
00:07:14.960 trick is a programming contest for we
00:07:17.599 programs uh held regularly at Ruby Ruby
00:07:22.479 conference in
00:07:23.599 Japan uh trick is looking for uh weird
00:07:28.039 repr programs and the seven uh member
00:07:30.840 panel of Judges include me and uh mat
00:07:35.000 and we evaluate and select good weird
00:07:38.599 and interesting programs uh to
00:07:42.120 award and trick has been helpful uh uh
00:07:46.720 four times so far today uh I will
00:07:49.639 introduce four or five of the winning
00:07:52.919 entries P wining entries as works are
00:07:56.199 available on GitHub so if you are
00:07:58.440 interested please take
00:08:01.199 later uh so the first winning entry I
00:08:05.400 will show you today is this
00:08:09.919 one this is uh this one the most grobal
00:08:14.440 a trick
00:08:16.240 2022 the O is
00:08:19.199 me in the Jes themselves can submit
00:08:23.039 their own work uh in uh in such case uh
00:08:27.280 they are evaluated based on the a the
00:08:29.639 score of the other judges than the
00:08:32.519 Au anyway let's
00:08:40.360 right where is my castle perhaps okay
00:08:48.320 so this is the source code
00:08:52.839 and is a straight figure okay and uh
00:08:57.600 this is the source code and run it
00:09:04.920 oops do you
00:09:07.959 understand the original source code
00:09:10.440 afria is here and the executed result
00:09:14.880 afria is here so uh it outputs itself
00:09:18.560 but a gr part rotated 45 uh
00:09:22.959 degrees the output is of course
00:09:25.959 executable again so you can pass uh it
00:09:30.399 to Ruby again like
00:09:33.720 this and
00:09:35.800 now it has rotated
00:09:39.040 90° maybe we are here
00:09:42.200 now so each and rotates uh 50° each so
00:09:48.720 by uh after 1 2 3 4 5 6 seven eight
00:09:55.240 rotation reputations and it will
00:09:58.440 completely
00:10:00.000 return to the original position check
00:10:03.040 it this is the original source code okay
00:10:05.839 completely
00:10:07.640 sh
00:10:10.560 okay yeah thank
00:10:17.480 you so this was a variant of Quin with M
00:10:23.279 to Grove uh that rotates when exec
00:10:26.560 it and it has uh it also has some Advan
00:10:30.720 features such as you can specify the
00:10:33.760 rotation difficult is 45 but you can
00:10:36.800 specify in one or two or anything and
00:10:41.720 also it has also dumping uh the internal
00:10:46.120 uh map but I omit them today if you are
00:10:49.519 interested please try it yourself later
00:10:54.040 and implementation techniques include
00:10:56.800 aat uh programming uh and C with steps
00:11:01.360 and also uh completion of mdate and some
00:11:05.480 Mass but today I will uh I briefly
00:11:09.160 explain the first two tips the first one
00:11:12.600 is as
00:11:14.200 programming uh it is uh easier than you
00:11:18.200 may think in Ruby to make Ruby code ASAT
00:11:22.399 the key is uh passent
00:11:25.959 WL so you know you may know
00:11:29.800 where's my castle okay uh this uh is
00:11:35.079 interpreted as this so two string array
00:11:39.360 and you can strip uh this white Space by
00:11:43.160 using array joint method so this returns
00:11:47.120 this string you know this is not
00:11:50.279 difficult so this is not so difficult I
00:11:52.480 think and now uh let's put your favorite
00:11:56.120 record into thisum and uh pass it to Eva
00:12:01.320 method
00:12:03.040 so this is uh condensed uh
00:12:07.760 removed uh the spaces
00:12:10.839 and pass to method and so each outputs
00:12:16.320 High uh by exploiting this you can
00:12:19.560 really format the rub code by inserting
00:12:22.519 white spaces uh like this and this
00:12:26.000 prints hell world when executed
00:12:30.120 and this another key tip is St hook wine
00:12:34.600 uh I don't have time uh to elaborate uh
00:12:38.279 on this but uh quen can have uh the uh
00:12:43.440 State uh with just a few
00:12:46.360 modifications the above is normal Co so
00:12:50.639 it prints itself directly this this
00:12:54.720 itself directory and you can make it
00:12:57.240 state by adding some code fragments this
00:13:00.800 and this and this uh code uh when
00:13:05.680 executed it outputs uh almost the same
00:13:09.440 result but it has
00:13:12.600 nal2 and repeatedly executed uh the part
00:13:16.440 is
00:13:17.399 incremented
00:13:19.680 so you can use this number for the stage
00:13:23.160 of the code such as rotating group or uh
00:13:27.320 something okay
00:13:30.079 next one this is the best of fishable a
00:13:34.160 at trick 20 2022 okay that's not
00:13:41.760 NE
00:13:52.759 okay okay so let's
00:14:00.360 oops T
00:14:08.240 to as you see three fish are swimming
00:14:11.519 three fish is swimming and the grass is
00:14:16.560 waving interestingly H each frame uh
00:14:20.600 oops each frame is exit uh executable so
00:14:25.720 I stopped it and copy it
00:14:31.720 and okay copyed and pass it to Ruby
00:14:37.560 interpr okay uh keep crossb
00:14:42.199 uh
00:14:44.399 executed the execution resumes from that
00:14:48.920 frame so you
00:14:52.160 can
00:14:57.759 okay okay so this is also a variant of
00:15:00.680 Quin that shows visable animation with
00:15:04.320 960
00:15:05.920 frames uh this is also based in on
00:15:09.199 implementation techniques like ASAT code
00:15:12.240 and state Quine but also uh it has uh
00:15:16.839 the 2D Graphics of fish and grass which
00:15:20.440 is very ey catching but it is what is
00:15:23.519 interesting I think is uh the use of era
00:15:27.519 collection technology
00:15:30.800 I mean so okay uh this illustrates what
00:15:35.319 part of the code has water
00:15:38.560 R the orange part this part is uh the 2D
00:15:44.440 Graphics C but cored by fish and grass
00:15:50.240 and the black part is is a redundant dat
00:15:54.680 for ER collection and the pink part pink
00:15:59.680 part it is a bit to see but this is pink
00:16:04.079 and uh for eror correction code uh this
00:16:08.000 uh code for qu uh at the beginning and
00:16:12.920 end and this code when executed first
00:16:17.319 extract pink part and and run it and
00:16:21.800 perform error correction to recover
00:16:23.759 orange part and black part like this
00:16:27.120 okay do you understand
00:16:30.000 so the orange part and black part are
00:16:33.040 corrupted by uh spes or fish and for
00:16:37.040 fish and grass and uh the error
00:16:40.759 corlection program recovers the code in
00:16:43.959 other words uh this program has a self
00:16:46.959 repairing feature uh now then it can
00:16:50.279 extract uh complete uh recover to uh Tod
00:16:54.360 Graphics uh code and uh it uh per
00:16:59.480 the VIS
00:17:01.279 animation
00:17:04.160 okay I have shown two winning entries of
00:17:07.640 T so far both are qu or its variant uh
00:17:13.000 this is just because I personally love
00:17:16.000 qu however trick is a contest not only
00:17:20.039 for qu programs next I will show uh some
00:17:25.280 nonin winning entries of t
00:17:30.000 uh this is the best pangram award of Tri
00:17:34.799 2013 uh this is the first
00:17:37.559 trick uh this is a ruby
00:17:40.640 pangram a pangram is a sentence using
00:17:44.160 that uses all the letters of the of the
00:17:48.559 alphabet uh this program is coded using
00:17:51.280 all printable uh characters one at a
00:17:54.799 time so this is a
00:17:57.280 rangr and
00:17:59.799 uh when executed it outputs all printer
00:18:03.440 key characters oops Yeah
00:18:09.039 so do you understand
00:18:12.159 okay and this program may look simpler
00:18:16.120 than the previous entries but uh the
00:18:19.240 Restriction using uh every data only
00:18:22.400 once is uh more interesting than you may
00:18:25.440 think so for example consider a local
00:18:29.240 variable uh the same variable name can
00:18:32.159 only be written once so you can Define
00:18:36.320 uh a variable but you cannot read
00:18:39.919 it so this code solves the issue by
00:18:43.600 using a special number variable uh that
00:18:47.760 dot uh this special variable contains a
00:18:51.679 line line number of the last line red
00:18:55.360 red and since this program is one line
00:18:59.000 and this variable is initialized to one
00:19:01.440 this is a good use of this variable also
00:19:05.280 you cannot even write integer freely uh
00:19:11.520 this code uses some calculation to
00:19:14.240 create uh needed ints like
00:19:17.760 this yeah okay
00:19:20.919 next this is the most reserved award at
00:19:24.360 trick 28 uh 208
00:19:29.280 and as you can see this is a this is
00:19:31.880 just a list of rubby keyw but it is
00:19:41.679 executable
00:19:46.360 stop this is qy just q but it is
00:19:51.840 executable so no is produced uh when it
00:19:55.400 is executed what is interesting is that
00:19:58.400 no syntax is
00:20:01.320 produced the fact that there are no
00:20:04.200 syntax SAS in this T is very amazing and
00:20:08.520 so it got a gold medal uh Tri
00:20:13.159 2018 and uh this is Alo very technical
00:20:17.559 and for example
00:20:20.679 uh it makes very clear cly use of
00:20:24.679 keywords uh such as uh this begin is not
00:20:28.880 C this is a method name of
00:20:32.559 areas for example and this is modifier
00:20:36.760 and this and so if you interested please
00:20:42.200 sa it
00:20:47.360 okay okay as the final F uh I like to
00:20:52.200 present trick
00:20:54.320 2022 uh most anti-gravity a okay let's
00:20:59.080 uh R
00:21:02.000 it
00:21:04.600 oops this is the code and it's
00:21:09.159 R
00:21:14.159 oops
00:21:17.679 okay and it wave a string to
00:21:21.760 2022 of course uh this is not
00:21:24.559 all uh let's try to remove uh all spaces
00:21:31.640 in from this
00:21:34.080 program
00:21:38.360 uh so the output looks crash to left I
00:21:45.240 so save this as app. RV up. RV up. RV
00:21:52.320 behaves differently from the original
00:21:54.039 source code it cres the input text app
00:21:57.679 as for example this is a sample T
00:22:03.799 and applying app. RB to this
00:22:08.720 Tex okay so every characters are moved
00:22:12.880 to Upward as possible
00:22:17.080 so next uh apply uh app RB to the
00:22:22.039 original source code moment Tob
00:22:28.840 the output look crat to the app save
00:22:32.080 this as left
00:22:37.400 RB and
00:22:40.240 uh you may uh already understand uh LIF
00:22:45.000 RB is also a te manipulation tool and it
00:22:49.400 moves all character to the
00:22:51.600 left
00:22:53.279 okay no no no no no no uh uh we have we
00:22:58.320 have
00:22:59.000 upv to crash up and left crash left yeah
00:23:04.000 here is where it is getting
00:23:07.600 interesting okay let's Clap the original
00:23:11.400 source code up and then
00:23:18.480 left this program we executed outputs
00:23:23.000 Tock
00:23:25.120 2022
00:23:27.039 and cross uh the original source code
00:23:33.240 oops and up to left to left and CR to
00:23:40.360 up this one is
00:23:45.039 executed PR T 2022 but do you
00:23:52.279 understand that's uh this program
00:23:55.039 includes five programs tick program and
00:23:58.240 a R left PR 2022 horizontally and
00:24:03.919 vertically okay so I think you need a
00:24:10.559 recap so this is the ti
00:24:13.880 program original original
00:24:16.840 program thank you
00:24:19.159 and if it is crashed to left it behaves
00:24:22.760 like this program uh behaves upward
00:24:26.360 crushing program and
00:24:29.159 if the original code is crashed to
00:24:30.919 Upward it behaves like a left crashing
00:24:33.880 program this is left crashing program
00:24:37.240 and if crash to up then right left uh it
00:24:42.279 print uh Tri
00:24:44.279 2022 and if CR to left and then up it
00:24:51.200 PR2
00:24:53.399 but
00:24:55.320 okay you understand okay uh I will only
00:24:59.679 introduce the key idea this is a gimmick
00:25:02.720 of detect left crash originally c one is
00:25:07.399 executed because it is in a string
00:25:10.120 interpolation however if it is crashed
00:25:12.440 to the left uh Cod one is now a part of
00:25:16.799 string because uh escaping back
00:25:20.120 character escapes the uh string
00:25:22.440 interpration and uh COD two is now
00:25:25.320 activated because uh
00:25:29.039 space is removed and it is now string
00:25:32.200 interation also detecting upward crash
00:25:35.720 is a similar once you understand the
00:25:39.120 idea I think it is easier than you must
00:25:41.600 think isn't it and it will take a little
00:25:45.440 more for to complete the program but the
00:25:48.039 important thing is the
00:25:50.559 idea okay
00:25:53.440 so uh I have introduced we programs and
00:25:57.840 all of the programs I I introduced today
00:26:01.640 as well as the other winning entries can
00:26:03.840 be found here uh this GitHub so please
00:26:06.919 take a look at
00:26:09.799 later and uh what I want to uh you to
00:26:15.279 remember from this talk is that uh we
00:26:18.679 are now accepting entries for
00:26:21.679 history thank
00:26:26.679 you the the is February 28th or next
00:26:31.039 year so there are three months more than
00:26:34.840 three months and you may think you can't
00:26:37.399 uh write such a program uh however Ruby
00:26:40.360 is very flexible and wonderful language
00:26:42.399 so if you try uh you you will be
00:26:45.200 surprised at uh what you can do so
00:26:48.679 please give it that try uh we are
00:26:50.880 waiting for your weird and interesting
00:26:53.480 entries
00:26:55.480 okay to conclude uh this present
00:26:58.760 I created a new Co for Rubik Chicago and
00:27:03.240 I I would like to end this look by
00:27:05.360 running this okay I have recorded the
00:27:09.240 video uh of the execution so I play
00:27:16.960 it this is the source code and this
00:27:21.480 partes a piano keyboard and then execute
00:27:26.159 it
00:27:48.720 Chicago
00:27:55.720 Chicago great thank you
00:28:00.360 this program plays a songo that town it
00:28:04.600 syes a sound by itself uh while
00:28:07.919 displaying the piano Ro and save the
00:28:11.120 file chicago. web file sound file uh
00:28:15.120 this video is made by combining uh the
00:28:19.000 screencast uh with uh the gener to
00:28:23.279 weire
00:28:24.919 so please enjoy
00:28:35.559 do you know this
00:28:36.799 song okay
00:28:52.320 great this song was composed uh in 19
00:28:58.559 s was so so copyright is
00:29:04.279 only it has no copyright
00:29:23.960 for wow
00:29:26.559 okay yes
00:29:29.159 thank
00:29:33.799 you yeah it is now original program okay
00:29:37.440 that's all thank you very much
Explore all talks recorded at RubyConf 2024
+64