diff options
Diffstat (limited to 'jni/ruby/sample/trick2013')
-rw-r--r-- | jni/ruby/sample/trick2013/README.md | 13 | ||||
-rw-r--r-- | jni/ruby/sample/trick2013/kinaba/authors.markdown | 3 | ||||
-rw-r--r-- | jni/ruby/sample/trick2013/kinaba/entry.rb | 1 | ||||
-rw-r--r-- | jni/ruby/sample/trick2013/kinaba/remarks.markdown | 37 | ||||
-rw-r--r-- | jni/ruby/sample/trick2013/mame/authors.markdown | 3 | ||||
-rw-r--r-- | jni/ruby/sample/trick2013/mame/entry.rb | 97 | ||||
-rw-r--r-- | jni/ruby/sample/trick2013/mame/music-box.mp4 | bin | 0 -> 580724 bytes | |||
-rw-r--r-- | jni/ruby/sample/trick2013/mame/remarks.markdown | 47 | ||||
-rw-r--r-- | jni/ruby/sample/trick2013/shinh/authors.markdown | 2 | ||||
-rw-r--r-- | jni/ruby/sample/trick2013/shinh/entry.rb | 10 | ||||
-rw-r--r-- | jni/ruby/sample/trick2013/shinh/remarks.markdown | 4 | ||||
-rw-r--r-- | jni/ruby/sample/trick2013/yhara/authors.markdown | 3 | ||||
-rw-r--r-- | jni/ruby/sample/trick2013/yhara/entry.rb | 28 | ||||
-rw-r--r-- | jni/ruby/sample/trick2013/yhara/remarks.en.markdown | 23 | ||||
-rw-r--r-- | jni/ruby/sample/trick2013/yhara/remarks.markdown | 24 |
15 files changed, 295 insertions, 0 deletions
diff --git a/jni/ruby/sample/trick2013/README.md b/jni/ruby/sample/trick2013/README.md new file mode 100644 index 0000000..65f1d3b --- /dev/null +++ b/jni/ruby/sample/trick2013/README.md @@ -0,0 +1,13 @@ +This directory contains the award-winning entries of +the 1st Transcendental Ruby Imbroglio Contest for rubyKaigi (TRICK 2013). + +THESE ARE BAD EXAMPLES! You must NOT use them as a sample code. + +* kinaba/entry.rb: "Best pangram" - Gold award +* mame/entry.rb: "Most classic" - Bronze award +* shinh/entry.rb: "Most Readable" - Silver award +* yhara/entry.rb: "Worst abuse of constants" - Dishonorable mention + +For the contest outline and other winning entries, see: + +https://github.com/tric/trick2013 diff --git a/jni/ruby/sample/trick2013/kinaba/authors.markdown b/jni/ruby/sample/trick2013/kinaba/authors.markdown new file mode 100644 index 0000000..84c011e --- /dev/null +++ b/jni/ruby/sample/trick2013/kinaba/authors.markdown @@ -0,0 +1,3 @@ +* kinaba + * kiki@kmonos.net + * cctld: jp diff --git a/jni/ruby/sample/trick2013/kinaba/entry.rb b/jni/ruby/sample/trick2013/kinaba/entry.rb new file mode 100644 index 0000000..8a3f855 --- /dev/null +++ b/jni/ruby/sample/trick2013/kinaba/entry.rb @@ -0,0 +1 @@ +!@THEqQUICKbBROWNfFXjJMPSvVLAZYDGgkyz&[%r{\"}mosx,4>6]|?'while(putc 3_0-~$.+=9/2^5;)<18*7and:`# diff --git a/jni/ruby/sample/trick2013/kinaba/remarks.markdown b/jni/ruby/sample/trick2013/kinaba/remarks.markdown new file mode 100644 index 0000000..e35550e --- /dev/null +++ b/jni/ruby/sample/trick2013/kinaba/remarks.markdown @@ -0,0 +1,37 @@ +### Remarks + +Just run it with no argument: + + ruby entry.rb + +I confirmed the following implementations/platforms: + +* ruby 2.0.0p0 (2013-02-24) [i386-mswin32\_100] + +### Description + +The program prints each ASCII character from 0x20 ' ' to 0x7e '~' exactly once. + +The program contains each ASCII character from 0x20 ' ' to 0x7e '~' exactly once. + +### Internals + +The algorthim is the obvious loop "32.upto(126){|x| putc x}". + +It is not so hard to transform it to use each character *at most once*. Only the slight difficulty comes from the constraint that we cannot "declare and then use" variables, because then the code will contain the variable name twice. This restriction is worked around by the $. global variable, the best friend of Ruby golfers. + +The relatively interesting part is to use all the charcters *at least once*. Of course, this is easily accomplished by putting everything into a comment (i.e., #unsed...) or to a string literal (%(unused...), note that normal string literals are forbidden since they use quotation marks twice). Hey, but that's not fun at all! I tried to minimize the escapeway. + +* "@THEqQUICKbBROWNfFXjJMPSvVLAZYDGgkyz". Trash box of unused alphabet. I with I could have used "gkyz" somewhere else. + +* "%r{\"}mosx". Regex literal, with %-syntax. I don't even know what each m,o,s,x means... + +* "?'" Symbol literal. The quote characters (' " \`) are the first obstacle to this trial because they have to be used in pair usually. These are escaped as \" and ?' and :\`. + +* "4>6" "3\_0-~$.+=9/2^5" "18\*7". I had to consume many arithmetic operators +-\*/^~<>, but I only have ten literals 0 to 9 and $. as operands. Besides I have to express the print loop. This is an interesting puzzle. + +* "(putc ...;)<18*7". Trail semicolon doesn't change the value of the expression. + +### Limitation + +n/a. diff --git a/jni/ruby/sample/trick2013/mame/authors.markdown b/jni/ruby/sample/trick2013/mame/authors.markdown new file mode 100644 index 0000000..e99cd71 --- /dev/null +++ b/jni/ruby/sample/trick2013/mame/authors.markdown @@ -0,0 +1,3 @@ +* Yusuke Endoh + * mame@tsg.ne.jp + * cctld: jp diff --git a/jni/ruby/sample/trick2013/mame/entry.rb b/jni/ruby/sample/trick2013/mame/entry.rb new file mode 100644 index 0000000..8abfc2b --- /dev/null +++ b/jni/ruby/sample/trick2013/mame/entry.rb @@ -0,0 +1,97 @@ + 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=%: + + Jesu, Joy of Man's Desiring + Johann Sebastian Bach + + # + | # + | # + # # # # + | | | # + | | # # + # # # # + | | | # + | | # # + # # # # + | | | # + | | # # + # # # # + | | | # + | | # # + # # # # + | | | # + | | # # + # # # # + | | | # + | | # # + # # # # + | | | # + | | # + # # # # + | | | # + | #| # + # # | # + | | | # + | | # # + # # # # + | | # | + | | # # + # # # # + | | | # + | | # + # # # # + | | # | + | # # | + # # # # + | | | # + | | # # + # # # # + | | | # + | | # # + # # # # + | | | # + | | # # + # # # # + | | | # + | | # # + # # # # + | | | # + | | # # + # # # # + | | | # + | | # # + # # # # + | | | # + | # # + # # # + | | | # + | # | # + # # # # + | | | | + | | | | + | | | | + | | | | + | | | | + | | | | + | | | | + | | | | + | | | | + | | | | + | | | : diff --git a/jni/ruby/sample/trick2013/mame/music-box.mp4 b/jni/ruby/sample/trick2013/mame/music-box.mp4 Binary files differnew file mode 100644 index 0000000..6d1e87c --- /dev/null +++ b/jni/ruby/sample/trick2013/mame/music-box.mp4 diff --git a/jni/ruby/sample/trick2013/mame/remarks.markdown b/jni/ruby/sample/trick2013/mame/remarks.markdown new file mode 100644 index 0000000..8c1988c --- /dev/null +++ b/jni/ruby/sample/trick2013/mame/remarks.markdown @@ -0,0 +1,47 @@ +### Remarks + +Run the program under a platform that `/dev/dsp` is available. +For example, if you are using pulseaudio, use `padsp`: + + padsp ruby entry.rb + +Please see Limitation if you want to run this program on os x. + +I confirmed the following platforms. + +* ruby 2.0.0p0 (2013-02-24 revision 39474) [x86\_64-linux] +* ruby 1.9.3p194 (2012-04-20 revision 35410) [x86\_64-linux] +* ruby 1.9.3p327 (2012-11-10 revision 37606) [x86\_64-darwin10.8.0] + +For those who are lazy, I'm attaching a screencast. + +### Description + +This program is a music-box quine. +It prints itself with playing "Jesu, Joy of Man's Desiring". + +### Internal + +Like a real music box, this program consists of a mechanical part (code) and a piano roll. +In the piano roll, `#` represents a pin that hits a note, and `|` represents a slur. +The leftmost column corresponds 110Hz (low A). +Every column corresponds a semitone higher than the left one. + +This program uses [the frequency modulation synthesis](http://en.wikipedia.org/wiki/Frequency_modulation_synthesis) to play the sound like a music-box. +You can create a different-sounding tone by changing the parameter. +For example, the following will play the sound like a harpsichord. + + padsp ruby entry.rb 2.0 + +Note that this program does *not* use an idiom to remove whitespace, such as `.split.join`. All newlines and spaces do not violate any of the Ruby syntax rules. + +### Limitation + +On os x, `/dev/dsp` is not available. +You have to use sox by replacing the following part: + + open("/dev/dsp","wb") + +with: + + IO.popen("./pl","wb")
\ No newline at end of file diff --git a/jni/ruby/sample/trick2013/shinh/authors.markdown b/jni/ruby/sample/trick2013/shinh/authors.markdown new file mode 100644 index 0000000..7ea2298 --- /dev/null +++ b/jni/ruby/sample/trick2013/shinh/authors.markdown @@ -0,0 +1,2 @@ +Shinichiro Hamaji +Japan, .jp diff --git a/jni/ruby/sample/trick2013/shinh/entry.rb b/jni/ruby/sample/trick2013/shinh/entry.rb new file mode 100644 index 0000000..cd45173 --- /dev/null +++ b/jni/ruby/sample/trick2013/shinh/entry.rb @@ -0,0 +1,10 @@ +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 diff --git a/jni/ruby/sample/trick2013/shinh/remarks.markdown b/jni/ruby/sample/trick2013/shinh/remarks.markdown new file mode 100644 index 0000000..1cd190d --- /dev/null +++ b/jni/ruby/sample/trick2013/shinh/remarks.markdown @@ -0,0 +1,4 @@ +This program is a meaningless poem. +This does nothing for you. +Almost everything in this code is junk, +but you and program would confuse you a bit. diff --git a/jni/ruby/sample/trick2013/yhara/authors.markdown b/jni/ruby/sample/trick2013/yhara/authors.markdown new file mode 100644 index 0000000..c0adc2b --- /dev/null +++ b/jni/ruby/sample/trick2013/yhara/authors.markdown @@ -0,0 +1,3 @@ +* Yutaka Hara + * yutaka.hara.gmail.com + * cctld: jp diff --git a/jni/ruby/sample/trick2013/yhara/entry.rb b/jni/ruby/sample/trick2013/yhara/entry.rb new file mode 100644 index 0000000..a2deb54 --- /dev/null +++ b/jni/ruby/sample/trick2013/yhara/entry.rb @@ -0,0 +1,28 @@ +def _(&b)$><<->(x){x ? (String===x ?x.upcase: +(Class===x ? x : x.class).name[$a?0:($a=5)]): +" "}[ begin b[];rescue Exception;$!;end ] end + +_ { return } +_ { method(:p).unbind } +_ { eval "{ " } +_ { Thread.current.join } +_ { nil } +_ { select } +_ { ruby } +_ { self.class } +_ { Thread.current.group } +_ { nil.to_h } +_ { "\xFF".encode("big5") } +_ { raise } +_ { [0][1] } +_ { Regexp.compile "*" } +_ { RUBY_COPYRIGHT[32] } +_ { binding } +_ { :s.class.name[1] } +_ { warn } +_ { [a: :b][0] } +_ { methods } +_ { IO.class } +_ { {}.fetch(0) } +_ { open " " } +_ { 1000000.chr } diff --git a/jni/ruby/sample/trick2013/yhara/remarks.en.markdown b/jni/ruby/sample/trick2013/yhara/remarks.en.markdown new file mode 100644 index 0000000..bd821e8 --- /dev/null +++ b/jni/ruby/sample/trick2013/yhara/remarks.en.markdown @@ -0,0 +1,23 @@ +### Remarks + +Just run it with no argument: + + ruby entry.rb + +I confirmed the following implementations/platforms: + +* ruby 2.0.0p0 (2013-02-24 revision 39474) [x86\_64-darwin12.2.1] + +### Description + +It prints JUST ANOTHER RUBY HACKER¡£ + +### Internals + +This script uses characters in constants in Object class. It +intentionally raises some exceptions. The second 'U' comes from +RUBY\_COPYRIGHT, "Yukihiro Matsumoto". + +### Limitation + +This program does not work on JRuby because "return" does not raise an exception. diff --git a/jni/ruby/sample/trick2013/yhara/remarks.markdown b/jni/ruby/sample/trick2013/yhara/remarks.markdown new file mode 100644 index 0000000..99cb4b5 --- /dev/null +++ b/jni/ruby/sample/trick2013/yhara/remarks.markdown @@ -0,0 +1,24 @@ +### Remarks + +引数ãªã—ã§æ™®é€šã«å®Ÿè¡Œã—ã¦ãã ã•ã„。 + + ruby entry.rb + +以下ã®å®Ÿè£…・プラットフォームã§å‹•ä½œç¢ºèªã—ã¦ã„ã¾ã™ã€‚ + +* ruby 2.0.0p0 (2013-02-24 revision 39474) [x86\_64-darwin12.2.1] + +### Description + +JUST ANOTHER RUBY HACKERã¨è¡¨ç¤ºã—ã¾ã™ã€‚ + +### Internals + +Objectクラスã®å®šæ•°ã‹ã‚‰æ–‡å—を拾ã£ã¦ã„ã¾ã™ã€‚ +ãã®ãŸã‚ã«ã€æ„図的ã«ä¾‹å¤–ã‚’èµ·ã“ã—ã¦ã„ã¾ã™ã€‚ +「Uã€ãŒä¸€ã¤ã—ã‹è¦‹ã¤ã‹ã‚‰ãªã‹ã£ãŸã®ã§ã€ã‚‚ã†ä¸€å€‹ã¯RUBY\_COPYRIGHTã® +「Yukihiro Matsumotoã€ã‹ã‚‰å–ã£ã¦ã„ã¾ã™ã€‚ + +### Limitation + +JRubyã¯returnãŒã‚¨ãƒ©ãƒ¼ã«ãªã‚‰ãªãã¦ã€å‹•ãã¾ã›ã‚“ã§ã—ãŸã€‚ |