<?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: Multiple Dwellings</title>
	<atom:link href="http://programmingpraxis.com/2009/02/20/multiple-dwellings/feed/" rel="self" type="application/rss+xml" />
	<link>http://programmingpraxis.com/2009/02/20/multiple-dwellings/</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: kawas</title>
		<link>http://programmingpraxis.com/2009/02/20/multiple-dwellings/#comment-3563</link>
		<dc:creator><![CDATA[kawas]]></dc:creator>
		<pubDate>Sat, 10 Sep 2011 09:30:14 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.wordpress.com/?p=54#comment-3563</guid>
		<description><![CDATA[Clojure code using only a list comprehension for this particular problem.
nb: in my country floors start at zero

[sourcecode lang=&quot;css&quot;]
;; list comprehension with all constraints in the :when clause
(for [b (range 5) c (range 5) f (range 5) m (range 5) s (range 5)
      :let [sf (- s f) fc (- f c)]
      :when (and (= 5 (count (distinct [b c f m s])))
                 (not= b 4) 
                 (not= c 0)
                 (&lt; 0 f 4)
                 (&gt; m c)
                 (not= 1 (* sf sf))
                 (not= 1 (* fc fc)))]
  [:Baker b :Cooper c :Fletcher f :Miller m :Smith s])

;; result: ([:Baker 2 :Cooper 1 :Fletcher 3 :Miller 4 :Smith 0])
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>Clojure code using only a list comprehension for this particular problem.<br />
nb: in my country floors start at zero</p>
<pre class="brush: css;">
;; list comprehension with all constraints in the :when clause
(for [b (range 5) c (range 5) f (range 5) m (range 5) s (range 5)
      :let [sf (- s f) fc (- f c)]
      :when (and (= 5 (count (distinct [b c f m s])))
                 (not= b 4)
                 (not= c 0)
                 (&lt; 0 f 4)
                 (&gt; m c)
                 (not= 1 (* sf sf))
                 (not= 1 (* fc fc)))]
  [:Baker b :Cooper c :Fletcher f :Miller m :Smith s])

;; result: ([:Baker 2 :Cooper 1 :Fletcher 3 :Miller 4 :Smith 0])
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Pierce</title>
		<link>http://programmingpraxis.com/2009/02/20/multiple-dwellings/#comment-1451</link>
		<dc:creator><![CDATA[Eric Pierce]]></dc:creator>
		<pubDate>Fri, 23 Jul 2010 06:06:48 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.wordpress.com/?p=54#comment-1451</guid>
		<description><![CDATA[After some false starts, I came up with Haskell solution that isn&#039;t half bad. Here&#039;s mine:

[sourcecode lang=&quot;css&quot;]
import Data.List
import Data.Map (fromList, toList, (!))

people = [&quot;Baker&quot;, &quot;Cooper&quot;, &quot;Fletcher&quot;, &quot;Miller&quot;, &quot;Smith&quot;]
assignments = [ fromList (zip people floors) &#124; floors &lt;- permutations [0,1,2,3,4] ]

-- Return True if the given floor assignments obey the constraints
constrain assign =
    let b = assign ! &quot;Baker&quot;
        c = assign ! &quot;Cooper&quot;
        f = assign ! &quot;Fletcher&quot;
        m = assign ! &quot;Miller&quot;
        s = assign ! &quot;Smith&quot;
    in b /= 4                    -- Baker is not on top floor
    &amp;&amp; c /= 0                    -- Cooper is not on bottom floor
    &amp;&amp; f `notElem` [0, 4]        -- Fletcher is not on top or bottom floor
    &amp;&amp; m &gt; c                     -- Miller is above Cooper
    &amp;&amp; s `notElem` [f-1, f+1]    -- Smith is not adjacent to Fletcher
    &amp;&amp; f `notElem` [c-1, c+1]    -- Fletcher is not adjacent to Cooper

-- Return all floor assignments that fit the constraints
solutions = head $ filter constrain assignments

main = putStrLn $ show $ toList solutions
-- [(&quot;Baker&quot;,2),(&quot;Cooper&quot;,1),(&quot;Fletcher&quot;,3),(&quot;Miller&quot;,4),(&quot;Smith&quot;,0)]
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>After some false starts, I came up with Haskell solution that isn&#8217;t half bad. Here&#8217;s mine:</p>
<pre class="brush: css;">
import Data.List
import Data.Map (fromList, toList, (!))

people = [&quot;Baker&quot;, &quot;Cooper&quot;, &quot;Fletcher&quot;, &quot;Miller&quot;, &quot;Smith&quot;]
assignments = [ fromList (zip people floors) | floors &lt;- permutations [0,1,2,3,4] ]

-- Return True if the given floor assignments obey the constraints
constrain assign =
    let b = assign ! &quot;Baker&quot;
        c = assign ! &quot;Cooper&quot;
        f = assign ! &quot;Fletcher&quot;
        m = assign ! &quot;Miller&quot;
        s = assign ! &quot;Smith&quot;
    in b /= 4                    -- Baker is not on top floor
    &amp;&amp; c /= 0                    -- Cooper is not on bottom floor
    &amp;&amp; f `notElem` [0, 4]        -- Fletcher is not on top or bottom floor
    &amp;&amp; m &gt; c                     -- Miller is above Cooper
    &amp;&amp; s `notElem` [f-1, f+1]    -- Smith is not adjacent to Fletcher
    &amp;&amp; f `notElem` [c-1, c+1]    -- Fletcher is not adjacent to Cooper

-- Return all floor assignments that fit the constraints
solutions = head $ filter constrain assignments

main = putStrLn $ show $ toList solutions
-- [(&quot;Baker&quot;,2),(&quot;Cooper&quot;,1),(&quot;Fletcher&quot;,3),(&quot;Miller&quot;,4),(&quot;Smith&quot;,0)]
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: OraQA &#187; Blog Archive &#187; How to solve the Multiple Dwellings Puzzle in SQL</title>
		<link>http://programmingpraxis.com/2009/02/20/multiple-dwellings/#comment-1307</link>
		<dc:creator><![CDATA[OraQA &#187; Blog Archive &#187; How to solve the Multiple Dwellings Puzzle in SQL]]></dc:creator>
		<pubDate>Tue, 08 Jun 2010 15:45:39 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.wordpress.com/?p=54#comment-1307</guid>
		<description><![CDATA[[...] Multiple Dwellings Baker, Cooper, Fletcher, Miller and Smith live on different floors of an apartment house that contains only five floors. Baker does not live on the top floor. Cooper does not live on the bottom floor. Fletcher does not live on either the top or the bottom floor. Miller lives on a higher floor than does Cooper. Smith does not live on a floor adjacent to Fletcher’s. Fletcher does not live on a floor adjacent to Cooper’s. Where does everyone live? [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Multiple Dwellings Baker, Cooper, Fletcher, Miller and Smith live on different floors of an apartment house that contains only five floors. Baker does not live on the top floor. Cooper does not live on the bottom floor. Fletcher does not live on either the top or the bottom floor. Miller lives on a higher floor than does Cooper. Smith does not live on a floor adjacent to Fletcher’s. Fletcher does not live on a floor adjacent to Cooper’s. Where does everyone live? [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: FalconNL</title>
		<link>http://programmingpraxis.com/2009/02/20/multiple-dwellings/#comment-28</link>
		<dc:creator><![CDATA[FalconNL]]></dc:creator>
		<pubDate>Wed, 11 Mar 2009 00:05:31 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.wordpress.com/?p=54#comment-28</guid>
		<description><![CDATA[Haskell (assuming 0 = bottom floor):

[sourcecode lang=&#039;css&#039;]
import Data.Map (fromList, (!))
import Data.List

data Person = Baker &#124; Cooper &#124; Fletcher &#124; Miller &#124; Smith deriving (Enum, Eq, Ord, Show)

main = print . filter conditions . map (fromList . flip zip [0 :: Int ..]) $ permutations [Baker ..]

conditions xs &#124; xs ! Baker    == 4                     = False
              &#124; xs ! Cooper   == 0                     = False
              &#124; xs ! Fletcher == 0                     = False
              &#124; xs ! Fletcher == 4                     = False
              &#124; xs ! Miller &lt; xs ! Cooper              = False
              &#124; abs (xs ! Smith - xs ! Fletcher) == 1  = False
              &#124; abs (xs ! Cooper - xs ! Fletcher) == 1 = False
              &#124; otherwise                              = True
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>Haskell (assuming 0 = bottom floor):</p>
<pre class="brush: css;">
import Data.Map (fromList, (!))
import Data.List

data Person = Baker | Cooper | Fletcher | Miller | Smith deriving (Enum, Eq, Ord, Show)

main = print . filter conditions . map (fromList . flip zip [0 :: Int ..]) $ permutations [Baker ..]

conditions xs | xs ! Baker    == 4                     = False
              | xs ! Cooper   == 0                     = False
              | xs ! Fletcher == 0                     = False
              | xs ! Fletcher == 4                     = False
              | xs ! Miller &lt; xs ! Cooper              = False
              | abs (xs ! Smith - xs ! Fletcher) == 1  = False
              | abs (xs ! Cooper - xs ! Fletcher) == 1 = False
              | otherwise                              = True
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pied</title>
		<link>http://programmingpraxis.com/2009/02/20/multiple-dwellings/#comment-16</link>
		<dc:creator><![CDATA[Pied]]></dc:creator>
		<pubDate>Sun, 01 Mar 2009 06:57:12 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.wordpress.com/?p=54#comment-16</guid>
		<description><![CDATA[In an appartment house?

P!]]></description>
		<content:encoded><![CDATA[<p>In an appartment house?</p>
<p>P!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

