<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:www.refactormycode.com,2007:users433</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/433" rel="self"/>
  <title>dorkalev</title>
  <updated>Sat Jun 13 08:25:11 -0700 2009</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor162942</id>
    <published>2009-06-13T08:25:11-07:00</published>
    <title>[Ruby] On Erlang Riddle for Rubists</title>
    <content type="html">&lt;p&gt;man, you loose all the fun of this task that way - though I DO LIKE YOUR WAY OF THINKING! ;-)
&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>dorkalev</name>
      <email>dor@dorkalev.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/916-erlang-riddle-for-rubists/refactors/162942" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code916</id>
    <published>2009-06-13T06:59:40-07:00</published>
    <updated>2009-06-13T20:49:50-07:00</updated>
    <title>[Ruby] Erlang Riddle for Rubists</title>
    <content type="html">&lt;p&gt;Originally published at &lt;a href="http://www.dorkalev.com/2009/06/erlang-riddle-for-rubists.html" target="_blank"&gt;http://www.dorkalev.com/2009/06/erlang-riddle-for-rubists.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the book  Software for a Concurrent World, Joe Armstrong gives an example of a function that returns all permutations of a given string.&lt;/p&gt;

&lt;p&gt;perms([]) -&amp;gt; [[]];
&lt;br /&gt;perms(L) -&amp;gt; [[H|T] || H &amp;lt;- L, T &amp;lt;- perms(L--[H])].&lt;/p&gt;

&lt;p&gt;I have tried to rewrite it in Ruby, in a form that would mostly imitate what's done here.
&lt;br /&gt;That's my best try so far.&lt;/p&gt;

&lt;p&gt;I hate the flatten hack I did there to simulate Erlang's valuse return as one Array.
&lt;br /&gt;I dislike having to send prem all his recursive &amp;quot;past&amp;quot; (as &amp;quot;nx&amp;quot;).&lt;/p&gt;

&lt;p&gt;I think there must be a better way to do it. A better way that will deliver the Erlangian concepts.
&lt;br /&gt;Do you think you might have a better way to pronounce the Erlangian magic of this function in Rubish ? If so, please post it here (as a comment) I'd really love to see it!&lt;/p&gt;

&lt;p&gt;Whoever has a better solution (me need to like) will get full credits on my blog and endless honor (!)&lt;/p&gt;

&lt;pre&gt;def prem(s,nx = [])
  return nx.join if s.empty?
  s.collect { |b| prem(s-[b],nx+[b]) }.flatten
end

puts prem('dor'.split(//))

output:

dor
dro
odr
ord
rdo
rod&lt;/pre&gt;</content>
    <author>
      <name>dorkalev</name>
      <email>dor@dorkalev.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/916-erlang-riddle-for-rubists" rel="alternate"/>
  </entry>
</feed>

