From: James Gray Date: 2008-03-08T00:47:13+09:00 Subject: Re: [SUMMARY] Hello, world? (#158) On Mar 7, 2008, at 9:00 AM, Matthew Moss wrote: > There are even a few solutions I still haven't figured out yet. I > need to break down the dense code from _why to get a handle on > what's going on. I assume we're talking about this: require 'rbconfig' bui = /^bui(.{2})$/ $stdout << "#{{}.class}"[0,1] << ("#{{}.methods}"[/c(\w{4})c/] && $1.reverse) << (([0]*2).inspect[2,2]) << Config::CONFIG.keys.grep(bui).first.gsub(bui, "#{Kernel.methods.grep(/^th/)[0][2,3].reverse}\\1") << ObjectSpace._id2ref(338) Yeah, that's crazy. Let's see if we can figure it out. require 'rbconfig' Require Ruby's configuration details. That gives us a bunch of fresh Strings to work with. bui = /^bui(.{2})$/ Define a regular expression that matches words like "build." $stdout << "#{{}.class}"[0,1] << From here on out, it's all output. This creates a Hash, and pulls the first character off of that class name. ("#{{}.methods}"[/c(\w{4})c/] && $1.reverse) << Now it starts to get tricky. This code pulls the methods for a Hash, joins them into a giant String, uses a Regexp to find "collec" from the collect() method, and reverses and prints the "olle" portion. That gets us the rest of "Hello." (([0]*2).inspect[2,2]) << This makes an Array, grabs the code for it from Ruby's inspect(), and indexes into that String to pull out the comma and space. Config::CONFIG.keys.grep(bui).first.gsub(bui, "#{Kernel.methods.grep(/^th/)[0][2,3].reverse}\\1") << This uses the Regexp built a while back to match the "build" key out of Ruby's configuration Hash. It then replaces the letters "bui." To get the replacement, the code hunts for the throw() method on Kernel, pulls the last three letters and reverses them. That gives us "wor" + "ld" or "world." ObjectSpace._id2ref(338) I have no idea how reliable this is, but in _why's build of Ruby, and my own, the object with the ID 338 is the Symbol :"!", the last character needed. Clever code as always from _why. > And I'm somewhat frightened to even contemplate the mind of Rubén > Medellín, whose solution is some bizarre, palindromic mirror image > of Ruby insanity. It was freaking awesome. I'll leave it to someone else too spoil that one… ;) James Edward Gray II