<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Permuted Index</title>
	<atom:link href="http://programmingpraxis.com/2009/12/22/permuted-index/feed/" rel="self" type="application/rss+xml" />
	<link>http://programmingpraxis.com/2009/12/22/permuted-index/</link>
	<description>A collection of etudes, updated weekly, for the education and enjoyment of the savvy programmer</description>
	<lastBuildDate>Sat, 11 Feb 2012 09:48:16 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Matías Giovannini</title>
		<link>http://programmingpraxis.com/2009/12/22/permuted-index/#comment-857</link>
		<dc:creator><![CDATA[Matías Giovannini]]></dc:creator>
		<pubDate>Wed, 23 Dec 2009 23:38:10 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1816#comment-857</guid>
		<description><![CDATA[I&#039;ve written my OCaml solution (heavily &quot;inspired&quot; by Remco&#039;s) &lt;a href=&quot;http://alaska-kamtchatka.blogspot.com/2009/12/gained-in-translation.html&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;.]]></description>
		<content:encoded><![CDATA[<p>I&#8217;ve written my OCaml solution (heavily &#8220;inspired&#8221; by Remco&#8217;s) <a href="http://alaska-kamtchatka.blogspot.com/2009/12/gained-in-translation.html" rel="nofollow">here</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Geo Marchin</title>
		<link>http://programmingpraxis.com/2009/12/22/permuted-index/#comment-856</link>
		<dc:creator><![CDATA[Geo Marchin]]></dc:creator>
		<pubDate>Wed, 23 Dec 2009 22:40:59 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1816#comment-856</guid>
		<description><![CDATA[Apologies for failing at code posting.
Here you go:

&lt;a href=&quot;http://codepad.org/nNEAA3xe&quot; rel=&quot;nofollow&quot;&gt;]]></description>
		<content:encoded><![CDATA[<p>Apologies for failing at code posting.<br />
Here you go:</p>
<p><a href="http://codepad.org/nNEAA3xe" rel="nofollow"></a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Geo Marchin</title>
		<link>http://programmingpraxis.com/2009/12/22/permuted-index/#comment-855</link>
		<dc:creator><![CDATA[Geo Marchin]]></dc:creator>
		<pubDate>Wed, 23 Dec 2009 22:11:45 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1816#comment-855</guid>
		<description><![CDATA[My python solution.

def rotate(phrase):
    &quot;&quot;&quot;
    Takes a given phrase and performs a keyword rotation on it, returning a
    list of (part 1, part 2) tuples.
    &quot;&quot;&quot;
    # I don&#039;t want to figure out the sorting of capital letters.
    phrase = phrase.lower()
    # split the phrase into words.
    split_phrase = phrase.split(&#039; &#039;)
    rotation_list = []
    # Perform the actual rotation and return the splits.
    for i in range(len(split_phrase)):
        non_words =\
        [&quot;a&quot;,&quot;an&quot;,&quot;and&quot;,&quot;by&quot;,&quot;for&quot;,&quot;if&quot;,&quot;in&quot;,&quot;is&quot;,&quot;of&quot;,&quot;on&quot;,&quot;the&quot;,&quot;to&quot;]
        # If the split is before a non word skip the split, unless it&#039;s the first
        # word in the phrase.
        if (split_phrase[i] in non_words) and (i is not 0):
            continue
        # Create the left and right portions of the split, and insert into the
        # return tuple list.
        left = &quot;&quot;
        right = &quot;&quot;
        for n in range(len(split_phrase[:i])):
            if n == 0:
                left = split_phrase[n]
            else:
                left = left + &#039; &#039; + split_phrase[n]
        for n in range(len(split_phrase[i:])):
            if n == 0:
                right = split_phrase[i+n]
            else:
                right = right + &#039; &#039; + split_phrase[i+n]
        rotation_list.append((left, right))
    return rotation_list

def sort(rotation_list):
    &quot;&quot;&quot;
    Given a rotation list, bubble sort by the right hand side because I&#039;m lazy.
    &quot;&quot;&quot;
    for i in range(len(rotation_list)):
        for n in range(len(rotation_list)-1):
            if (rotation_list[n][1] &gt; rotation_list[n+1][1]):
                rotation_list[n], rotation_list[n+1] = \
                rotation_list[n+1], rotation_list[n]

def unrotate(rotation_list):
    &quot;&quot;&quot;
    Neatly output the given rotation list to the user.
    &quot;&quot;&quot;
    # Find the length of the longest string in the rotation list.
    max_size = 0
    for i in range(len(rotation_list)):
        for j in range(2):
            if (len(rotation_list[i][j]) &gt; max_size):
                max_size = len(rotation_list[i][j])

    # Output the properly formatted index table.
    for i in range(len(rotation_list)):
        print &#039; &#039; * (max_size - len(rotation_list[i][0])) \
                + rotation_list[i][0] \
                + &quot;    &quot; \
                + rotation_list[i][1]]]></description>
		<content:encoded><![CDATA[<p>My python solution.</p>
<p>def rotate(phrase):<br />
    &#8220;&#8221;"<br />
    Takes a given phrase and performs a keyword rotation on it, returning a<br />
    list of (part 1, part 2) tuples.<br />
    &#8220;&#8221;"<br />
    # I don&#8217;t want to figure out the sorting of capital letters.<br />
    phrase = phrase.lower()<br />
    # split the phrase into words.<br />
    split_phrase = phrase.split(&#8216; &#8216;)<br />
    rotation_list = []<br />
    # Perform the actual rotation and return the splits.<br />
    for i in range(len(split_phrase)):<br />
        non_words =\<br />
        ["a","an","and","by","for","if","in","is","of","on","the","to"]<br />
        # If the split is before a non word skip the split, unless it&#8217;s the first<br />
        # word in the phrase.<br />
        if (split_phrase[i] in non_words) and (i is not 0):<br />
            continue<br />
        # Create the left and right portions of the split, and insert into the<br />
        # return tuple list.<br />
        left = &#8220;&#8221;<br />
        right = &#8220;&#8221;<br />
        for n in range(len(split_phrase[:i])):<br />
            if n == 0:<br />
                left = split_phrase[n]<br />
            else:<br />
                left = left + &#8216; &#8216; + split_phrase[n]<br />
        for n in range(len(split_phrase[i:])):<br />
            if n == 0:<br />
                right = split_phrase[i+n]<br />
            else:<br />
                right = right + &#8216; &#8216; + split_phrase[i+n]<br />
        rotation_list.append((left, right))<br />
    return rotation_list</p>
<p>def sort(rotation_list):<br />
    &#8220;&#8221;"<br />
    Given a rotation list, bubble sort by the right hand side because I&#8217;m lazy.<br />
    &#8220;&#8221;"<br />
    for i in range(len(rotation_list)):<br />
        for n in range(len(rotation_list)-1):<br />
            if (rotation_list[n][1] &gt; rotation_list[n+1][1]):<br />
                rotation_list[n], rotation_list[n+1] = \<br />
                rotation_list[n+1], rotation_list[n]</p>
<p>def unrotate(rotation_list):<br />
    &#8220;&#8221;"<br />
    Neatly output the given rotation list to the user.<br />
    &#8220;&#8221;"<br />
    # Find the length of the longest string in the rotation list.<br />
    max_size = 0<br />
    for i in range(len(rotation_list)):<br />
        for j in range(2):<br />
            if (len(rotation_list[i][j]) &gt; max_size):<br />
                max_size = len(rotation_list[i][j])</p>
<p>    # Output the properly formatted index table.<br />
    for i in range(len(rotation_list)):<br />
        print &#8216; &#8216; * (max_size &#8211; len(rotation_list[i][0])) \<br />
                + rotation_list[i][0] \<br />
                + &#8221;    &#8221; \<br />
                + rotation_list[i][1]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Remco Niemeijer</title>
		<link>http://programmingpraxis.com/2009/12/22/permuted-index/#comment-854</link>
		<dc:creator><![CDATA[Remco Niemeijer]]></dc:creator>
		<pubDate>Tue, 22 Dec 2009 12:31:00 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1816#comment-854</guid>
		<description><![CDATA[My Haskell solution (see http://bonsaicode.wordpress.com/2009/12/22/programming-praxis-permuted-index/ for a version with comments):

[sourcecode lang=&quot;css&quot;]
import Data.Char
import Data.List
import qualified Data.List.Key as K
import Text.Printf

stopList :: [String]
stopList = words &quot;a an and by for if in is of on the to&quot;

rot :: [String] -&gt; [(String, String)]
rot xs = [(unwords a, unwords b) &#124; (a, b) &lt;- init $
          zip (inits xs) (tails xs), notElem (head b) stopList]

prettyPrint :: [(String, String)] -&gt; IO ()
prettyPrint xs = mapM_ (\(a, b) -&gt; printf &quot;%*s   %-*s\n&quot; l1 a l2 b) xs
    where l1 = maximum $ map (length . fst) xs
          l2 = maximum $ map (length . snd) xs

permuteIndex :: String -&gt; IO ()
permuteIndex = prettyPrint . K.sort (\(_, x) -&gt; (map toLower x, x)) .
               concatMap (rot . words) . lines
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>My Haskell solution (see <a href="http://bonsaicode.wordpress.com/2009/12/22/programming-praxis-permuted-index/" rel="nofollow">http://bonsaicode.wordpress.com/2009/12/22/programming-praxis-permuted-index/</a> for a version with comments):</p>
<pre class="brush: css;">
import Data.Char
import Data.List
import qualified Data.List.Key as K
import Text.Printf

stopList :: [String]
stopList = words &quot;a an and by for if in is of on the to&quot;

rot :: [String] -&gt; [(String, String)]
rot xs = [(unwords a, unwords b) | (a, b) &lt;- init $
          zip (inits xs) (tails xs), notElem (head b) stopList]

prettyPrint :: [(String, String)] -&gt; IO ()
prettyPrint xs = mapM_ (\(a, b) -&gt; printf &quot;%*s   %-*s\n&quot; l1 a l2 b) xs
    where l1 = maximum $ map (length . fst) xs
          l2 = maximum $ map (length . snd) xs

permuteIndex :: String -&gt; IO ()
permuteIndex = prettyPrint . K.sort (\(_, x) -&gt; (map toLower x, x)) .
               concatMap (rot . words) . lines
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Programming Praxis &#8211; Permuted Index &#171; Bonsai Code</title>
		<link>http://programmingpraxis.com/2009/12/22/permuted-index/#comment-853</link>
		<dc:creator><![CDATA[Programming Praxis &#8211; Permuted Index &#171; Bonsai Code]]></dc:creator>
		<pubDate>Tue, 22 Dec 2009 12:30:44 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1816#comment-853</guid>
		<description><![CDATA[[...] Praxis &#8211; Permuted&#160;Index By Remco Niemeijer  In today&#8217;s Programming Praxis exercise we have to implement David Parnas&#8217; permuted index system. [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Praxis &#8211; Permuted&nbsp;Index By Remco Niemeijer  In today&#8217;s Programming Praxis exercise we have to implement David Parnas&#8217; permuted index system. [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

