<?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: Eight queens revisited</title>
	<atom:link href="http://curiousprogrammer.wordpress.com/2007/01/01/eight-queens-revisited/feed/" rel="self" type="application/rss+xml" />
	<link>http://curiousprogrammer.wordpress.com/2007/01/01/eight-queens-revisited/</link>
	<description>Leveraging Perl and Emacs</description>
	<lastBuildDate>Tue, 07 May 2013 11:25:25 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: N-Queens Revisited: A Haskell Reply &#60; Ha4</title>
		<link>http://curiousprogrammer.wordpress.com/2007/01/01/eight-queens-revisited/#comment-7155</link>
		<dc:creator><![CDATA[N-Queens Revisited: A Haskell Reply &#60; Ha4]]></dc:creator>
		<pubDate>Sun, 14 Sep 2008 12:40:53 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/2007/01/01/eight-queens-revisited/#comment-7155</guid>
		<description><![CDATA[[...] Curious Programmer wrote C++ and OCaml solutions. According to the blog, “the fixed C++ completes 100 solutions in 9.5 [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Curious Programmer wrote C++ and OCaml solutions. According to the blog, “the fixed C++ completes 100 solutions in 9.5 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pietro abate</title>
		<link>http://curiousprogrammer.wordpress.com/2007/01/01/eight-queens-revisited/#comment-328</link>
		<dc:creator><![CDATA[pietro abate]]></dc:creator>
		<pubDate>Wed, 24 Jan 2007 20:51:10 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/2007/01/01/eight-queens-revisited/#comment-328</guid>
		<description><![CDATA[what&#039;s about this solution ?

&lt;code&gt;
let return x = [x]
let bind m f = List.flatten ( List.map f m )
let mzero = []
let mplus = List.append
let guard b = if b then return () else mzero

let rec select = function
&#124;[] -&gt; mzero
&#124;a::x -&gt; mplus (return (a,x)) (bind (select x) ( fun (b,x&#039;) -&gt; return
(b,a::x&#039;) ))

let notin q l = not(List.mem q l)

let range n =
let rec aux i l =
if i = 0 then l else i::(aux (i-1) l)
in List.rev ( aux n [] )

let rec place i rs d1 d2 = match i with
&#124;0 -&gt; return []
&#124;i -&gt;
bind (select rs) (fun (q,rs&#039;) -&gt; (* select one queen *)
let q1 = q - i in
let q2 = q + i in
bind (guard (notin q1 d1)) (fun r1 -&gt;
bind (guard (notin q2 d2)) (fun r2 -&gt;
bind (place (i-1) rs&#039; (q1::d1) (q2::d2)) (fun qs -&gt;
(return (q::qs))))))

let queen n = place n (range n) [] []
&lt;/code&gt;]]></description>
		<content:encoded><![CDATA[<p>what&#8217;s about this solution ?</p>
<p><code><br />
let return x = [x]<br />
let bind m f = List.flatten ( List.map f m )<br />
let mzero = []<br />
let mplus = List.append<br />
let guard b = if b then return () else mzero</p>
<p>let rec select = function<br />
|[] -&gt; mzero<br />
|a::x -&gt; mplus (return (a,x)) (bind (select x) ( fun (b,x') -&gt; return<br />
(b,a::x') ))</p>
<p>let notin q l = not(List.mem q l)</p>
<p>let range n =<br />
let rec aux i l =<br />
if i = 0 then l else i::(aux (i-1) l)<br />
in List.rev ( aux n [] )</p>
<p>let rec place i rs d1 d2 = match i with<br />
|0 -&gt; return []<br />
|i -&gt;<br />
bind (select rs) (fun (q,rs') -&gt; (* select one queen *)<br />
let q1 = q - i in<br />
let q2 = q + i in<br />
bind (guard (notin q1 d1)) (fun r1 -&gt;<br />
bind (guard (notin q2 d2)) (fun r2 -&gt;<br />
bind (place (i-1) rs' (q1::d1) (q2::d2)) (fun qs -&gt;<br />
(return (q::qs))))))</p>
<p>let queen n = place n (range n) [] []<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: IanO</title>
		<link>http://curiousprogrammer.wordpress.com/2007/01/01/eight-queens-revisited/#comment-212</link>
		<dc:creator><![CDATA[IanO]]></dc:creator>
		<pubDate>Wed, 03 Jan 2007 07:03:09 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/2007/01/01/eight-queens-revisited/#comment-212</guid>
		<description><![CDATA[Hi Harshad,

Unfortunately, wordpress has destroyed your code by removing the white-space (and possibly mangling punctuation such as &gt; and &lt;).  Even if it hadn&#039;t,  I believe the code is not similar to the original as it generates all solutions rather than back-tracking for a single solution so the benchmark would be invalid.

Ian]]></description>
		<content:encoded><![CDATA[<p>Hi Harshad,</p>
<p>Unfortunately, wordpress has destroyed your code by removing the white-space (and possibly mangling punctuation such as &gt; and &lt;).  Even if it hadn&#8217;t,  I believe the code is not similar to the original as it generates all solutions rather than back-tracking for a single solution so the benchmark would be invalid.</p>
<p>Ian</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harshad Joshi</title>
		<link>http://curiousprogrammer.wordpress.com/2007/01/01/eight-queens-revisited/#comment-199</link>
		<dc:creator><![CDATA[Harshad Joshi]]></dc:creator>
		<pubDate>Tue, 02 Jan 2007 11:21:43 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/2007/01/01/eight-queens-revisited/#comment-199</guid>
		<description><![CDATA[#!/bin/env python
&quot;&quot;&quot; General solution to the 8 queens puzzle.
&quot;&quot;&quot;

class queen:
   &quot;&quot;&quot; A queen on a chess board.
   &quot;&quot;&quot;
   def __init__(self, row, col):
       self.row, self.col = row, col
   def __str__(self):
       return &quot;(%d, %d)&quot; % (self.row, self.col)
   def safe_from(self, queens):
       &quot;&quot;&quot; Is this queen safe from the list of queens?
       &quot;&quot;&quot;
       for queen in queens:
           if self.attacked_by(queen):
               return False
       return True
   def attacked_by(self, queen):
       &quot;&quot;&quot; Is this queen attacked by the input queen?
       &quot;&quot;&quot;
       r, c = self.row, self.col
       qr, qc = queen.row, queen.col
       def same_row():
           return r == qr
       def same_column():
           return c == qc
       def same_diagonal():
           return r + c == qr + qc or r - c == qr - qc
       return same_row() or same_column() or same_diagonal()

def queens_puzzle(board_size):
   &quot;&quot;&quot; Generate solutions to the Queens puzzle for the input board size.
   &quot;&quot;&quot;
   def queen_columns(cols):
       if cols == 0:
           yield list()
       else:
           cols -= 1
           for queens in queen_columns(cols):
               for row in range(board_size):
                   new_queen = queen(row, cols)
                   if new_queen.safe_from(queens):
                       yield queens + [new_queen]
   for queens in queen_columns(board_size):
       yield queens

def outer_join(s, seq):
   return &quot;%s%s%s&quot; % (s, s.join(seq), s)

def print_solution(board_size, queens):
   line = outer_join(&quot;+&quot;, &quot;-&quot; * board_size)
   for row in range(board_size):
       print line
       print outer_join(&quot;&#124;&quot;,
                        [&quot; Q&quot;[q.row == row] for q in queens])
   print line
   print

try:
   print &quot;&quot;&quot;\
Queens puzzle solver.
Puts N chess queens on an N by N chessboard such that none of
them is able to capture any other.

At the prompt, enter the board size or Q to quit.
&quot;&quot;&quot;
   while True:
       board_size = int(raw_input(&quot;board size (Q to quit)? &quot;))
       if board_size  16:
               print (&quot;That&#039;s a tough one but I&#039;ll try my best. &quot;
                      &quot;Press CTRL-C to interrupt.&quot;)
           try:
               solutions = 0
               for solutions, queens in enumerate(queens_puzzle(board_size)):
                   print_solution(board_size, queens)
               if solutions: solutions += 1 # Users count from 1, not 0
               print &quot;There %s %d solution%s to the %d Queen%s puzzle.\n&quot; % (
                   solutions == 1 and &quot;is&quot; or &quot;are&quot;,
                   solutions, &quot;s&quot;[solutions==1:],
                   board_size,&quot;s&quot;[board_size==1:])
           except KeyboardInterrupt:
               print &quot;Execution interrupted.&quot;
except ValueError, v:
   print &quot;Bye for now!&quot;

Try the above version too..]]></description>
		<content:encoded><![CDATA[<p>#!/bin/env python<br />
&#8220;&#8221;" General solution to the 8 queens puzzle.<br />
&#8220;&#8221;"</p>
<p>class queen:<br />
   &#8220;&#8221;" A queen on a chess board.<br />
   &#8220;&#8221;"<br />
   def __init__(self, row, col):<br />
       self.row, self.col = row, col<br />
   def __str__(self):<br />
       return &#8220;(%d, %d)&#8221; % (self.row, self.col)<br />
   def safe_from(self, queens):<br />
       &#8220;&#8221;" Is this queen safe from the list of queens?<br />
       &#8220;&#8221;"<br />
       for queen in queens:<br />
           if self.attacked_by(queen):<br />
               return False<br />
       return True<br />
   def attacked_by(self, queen):<br />
       &#8220;&#8221;" Is this queen attacked by the input queen?<br />
       &#8220;&#8221;"<br />
       r, c = self.row, self.col<br />
       qr, qc = queen.row, queen.col<br />
       def same_row():<br />
           return r == qr<br />
       def same_column():<br />
           return c == qc<br />
       def same_diagonal():<br />
           return r + c == qr + qc or r &#8211; c == qr &#8211; qc<br />
       return same_row() or same_column() or same_diagonal()</p>
<p>def queens_puzzle(board_size):<br />
   &#8220;&#8221;" Generate solutions to the Queens puzzle for the input board size.<br />
   &#8220;&#8221;"<br />
   def queen_columns(cols):<br />
       if cols == 0:<br />
           yield list()<br />
       else:<br />
           cols -= 1<br />
           for queens in queen_columns(cols):<br />
               for row in range(board_size):<br />
                   new_queen = queen(row, cols)<br />
                   if new_queen.safe_from(queens):<br />
                       yield queens + [new_queen]<br />
   for queens in queen_columns(board_size):<br />
       yield queens</p>
<p>def outer_join(s, seq):<br />
   return &#8220;%s%s%s&#8221; % (s, s.join(seq), s)</p>
<p>def print_solution(board_size, queens):<br />
   line = outer_join(&#8220;+&#8221;, &#8220;-&#8221; * board_size)<br />
   for row in range(board_size):<br />
       print line<br />
       print outer_join(&#8220;|&#8221;,<br />
                        [" Q"[q.row == row] for q in queens])<br />
   print line<br />
   print</p>
<p>try:<br />
   print &#8220;&#8221;"\<br />
Queens puzzle solver.<br />
Puts N chess queens on an N by N chessboard such that none of<br />
them is able to capture any other.</p>
<p>At the prompt, enter the board size or Q to quit.<br />
&#8220;&#8221;"<br />
   while True:<br />
       board_size = int(raw_input(&#8220;board size (Q to quit)? &#8220;))<br />
       if board_size  16:<br />
               print (&#8220;That&#8217;s a tough one but I&#8217;ll try my best. &#8221;<br />
                      &#8220;Press CTRL-C to interrupt.&#8221;)<br />
           try:<br />
               solutions = 0<br />
               for solutions, queens in enumerate(queens_puzzle(board_size)):<br />
                   print_solution(board_size, queens)<br />
               if solutions: solutions += 1 # Users count from 1, not 0<br />
               print &#8220;There %s %d solution%s to the %d Queen%s puzzle.\n&#8221; % (<br />
                   solutions == 1 and &#8220;is&#8221; or &#8220;are&#8221;,<br />
                   solutions, &#8220;s&#8221;[solutions==1:],<br />
                   board_size,&#8221;s&#8221;[board_size==1:])<br />
           except KeyboardInterrupt:<br />
               print &#8220;Execution interrupted.&#8221;<br />
except ValueError, v:<br />
   print &#8220;Bye for now!&#8221;</p>
<p>Try the above version too..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: joe blogg</title>
		<link>http://curiousprogrammer.wordpress.com/2007/01/01/eight-queens-revisited/#comment-198</link>
		<dc:creator><![CDATA[joe blogg]]></dc:creator>
		<pubDate>Tue, 02 Jan 2007 11:19:18 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/2007/01/01/eight-queens-revisited/#comment-198</guid>
		<description><![CDATA[Huh?]]></description>
		<content:encoded><![CDATA[<p>Huh?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
