<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>Esoteric Ruby - Home</title>
  <id>tag:esotericruby.cilibrar.com,2006:mephisto/Home</id>
  <generator uri="http://mephisto.techno-weenie.net" version="666">Mephisto</generator>
  <link href="http://esotericruby.cilibrar.com/feed/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="http://esotericruby.cilibrar.com/" rel="alternate" type="text/html"/>
  <updated>2006-10-18T08:50:23Z</updated>
  <entry>
    <author>
      <name>cilibrar</name>
    </author>
    <id>tag:esotericruby.cilibrar.com,2006-10-18:/article/2006/10/18/an-extension-to-string-using-file-join</id>
    <published>2006-10-18T08:43:00Z</published>
    <updated>2006-10-18T08:43:00Z</updated>
    <category term="Ruby"/>
    <link href="http://esotericruby.cilibrar.com/2006/10/18/an-extension-to-string-using-file-join" rel="alternate" type="text/html"/>
    <title>An extension to String using File.join</title>
<content type="html">&lt;pre&gt;&lt;code&gt;# An idea for a convenient extension to String in Ruby
class String
  def /(nxtpart)
    File.join(self, nxtpart)
  end
end

dirname = '/usr/local/bin'
cmd = 'gcc'

puts dirname/cmd
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Here is the output:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;/usr/local/bin/gcc
&lt;/code&gt;&lt;/pre&gt;</content>  </entry>
  <entry>
    <author>
      <name>admin</name>
    </author>
    <id>tag:esotericruby.cilibrar.com,2006-10-04:/article/2006/10/4/anagrams-in-ruby</id>
    <published>2006-10-04T13:52:00Z</published>
    <updated>2006-10-04T13:52:00Z</updated>
    <link href="http://esotericruby.cilibrar.com/2006/10/4/anagrams-in-ruby" rel="alternate" type="text/html"/>
    <title>anagrams in ruby</title>
<content type="html">&lt;div bgcolor='#000000' text='#ffffff'&gt;

&lt;pre&gt;
&lt;font color='#00ffff'&gt;&lt;h2&gt;&lt;b&gt;Ruby&lt;/b&gt;&lt;/font&gt; &lt;font color='#00ffff'&gt;&lt;b&gt;Kata&lt;/b&gt;&lt;/font&gt; &lt;font color='#00ffff'&gt;&lt;b&gt;Six&lt;/b&gt;&lt;/font&gt;  --  &lt;font color='#00ffff'&gt;&lt;b&gt;Anagram&lt;/b&gt;&lt;/font&gt;&lt;/h2&gt;

&lt;font color='#00ffff'&gt;&lt;b&gt;# This was a fun one; another classic algorithm popular in class but always&lt;/b&gt;&lt;/font&gt;
&lt;font color='#00ffff'&gt;&lt;b&gt;# fun to recreate.  This reminds me also of the related Boggle type problem.&lt;/b&gt;&lt;/font&gt;
&lt;font color='#00ffff'&gt;&lt;b&gt;# Here's my answer for the anagram list.  Just feed the list of words to stdin.&lt;/b&gt;&lt;/font&gt;

&lt;font color='#00ffff'&gt;&lt;b&gt;#!/usr/bin/env ruby&lt;/b&gt;&lt;/font&gt;

&lt;font color='#8080ff'&gt;&lt;b&gt;def &lt;/b&gt;&lt;/font&gt;&lt;font color='#00ffff'&gt;&lt;b&gt;toHistogram&lt;/b&gt;
&lt;/font&gt;(str)
  res = [ ]
  str.each_byte { &lt;font color='#00ffff'&gt;&lt;b&gt;|i|&lt;/b&gt;&lt;/font&gt; res &amp;lt;&amp;lt; i }
  res.sort
&lt;font color='#8080ff'&gt;&lt;b&gt;end&lt;/b&gt;&lt;/font&gt;

result = &lt;font color='#00ffff'&gt;&lt;b&gt;STDIN&lt;/b&gt;&lt;/font&gt;.readlines.inject({}) &lt;font color='#ffff00'&gt;&lt;b&gt;do&lt;/b&gt;&lt;/font&gt; &lt;font color='#00ffff'&gt;&lt;b&gt;|n, w|&lt;/b&gt;&lt;/font&gt;
           w.chomp!
           h = toHistogram(w)
           n[h] ||= [ ]
           n[h].push(w)
           n
&lt;font color='#ffff00'&gt;&lt;b&gt;end&lt;/b&gt;&lt;/font&gt;

goodkeys = result.keys.sort_by { &lt;font color='#00ffff'&gt;&lt;b&gt;|i|&lt;/b&gt;&lt;/font&gt; -result[i].size }

goodkeys.each { &lt;font color='#00ffff'&gt;&lt;b&gt;|k|&lt;/b&gt;&lt;/font&gt;
  v = result[k]
  puts v.join(&lt;font color='#ff6060'&gt;&lt;b&gt;'&lt;/b&gt;&lt;/font&gt;&lt;font color='#ff40ff'&gt;&lt;b&gt; &lt;/b&gt;&lt;/font&gt;&lt;font color='#ff6060'&gt;&lt;b&gt;'&lt;/b&gt;&lt;/font&gt;) &lt;font color='#ffff00'&gt;&lt;b&gt;if&lt;/b&gt;&lt;/font&gt; v.size &amp;gt; &lt;font color='#ff40ff'&gt;&lt;b&gt;1&lt;/b&gt;&lt;/font&gt;
}
&lt;/pre&gt;
&lt;/div&gt;
</content>  </entry>
</feed>
