<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.3" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Puzzling</title>
	<link>http://marknelson.us/2007/04/01/puzzling/</link>
	<description>Programming, mostly.</description>
	<pubDate>Tue, 09 Mar 2010 22:27:30 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.3</generator>

	<item>
		<title>By: Coolkid</title>
		<link>http://marknelson.us/2007/04/01/puzzling/#comment-321977</link>
		<dc:creator>Coolkid</dc:creator>
		<pubDate>Thu, 28 Jan 2010 10:49:10 +0000</pubDate>
		<guid>http://marknelson.us/2007/04/01/puzzling/#comment-321977</guid>
		<description>Hi. If I use a set of element, each element has two int fields, represents for all string_m and string_n for state[i][j] (string_i and string_j), then all elements of state[i][j] is also in  state[m][n]. After we finish the pass for state[i][j] , we can mark that we solved state[m][n]. It can reduce many redundant computations. Sorry for my influent English, hope you understand my idea :)</description>
		<content:encoded><![CDATA[<p>Hi. If I use a set of element, each element has two int fields, represents for all string_m and string_n for state[i][j] (string_i and string_j), then all elements of state[i][j] is also in  state[m][n]. After we finish the pass for state[i][j] , we can mark that we solved state[m][n]. It can reduce many redundant computations. Sorry for my influent English, hope you understand my idea :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yet Another Word Puzzle</title>
		<link>http://marknelson.us/2007/04/01/puzzling/#comment-46620</link>
		<dc:creator>Yet Another Word Puzzle</dc:creator>
		<pubDate>Sun, 18 Nov 2007 20:59:08 +0000</pubDate>
		<guid>http://marknelson.us/2007/04/01/puzzling/#comment-46620</guid>
		<description>[...] I've confessed in the past, I'm a sucker for word puzzles. My recent post on a Will Shortz puzzle from NPR Morning Edition ended up provoking a surprising amount of comment, [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] I&#8217;ve confessed in the past, I&#8217;m a sucker for word puzzles. My recent post on a Will Shortz puzzle from NPR Morning Edition ended up provoking a surprising amount of comment, [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shahzad Bhatti &#187; Blog Archive &#187; Erlang translation of States Puzzle</title>
		<link>http://marknelson.us/2007/04/01/puzzling/#comment-42834</link>
		<dc:creator>Shahzad Bhatti &#187; Blog Archive &#187; Erlang translation of States Puzzle</dc:creator>
		<pubDate>Sat, 03 Nov 2007 02:48:28 +0000</pubDate>
		<guid>http://marknelson.us/2007/04/01/puzzling/#comment-42834</guid>
		<description>[...] from  A Simple Programming Puzzle Seen Through Three Different Lenses regarding states puzzle from Mark Nelson, which was originally posted NPR. Here is my translation of Anders Pearson&#8217;s [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] from  A Simple Programming Puzzle Seen Through Three Different Lenses regarding states puzzle from Mark Nelson, which was originally posted NPR. Here is my translation of Anders Pearson&#8217;s [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark</title>
		<link>http://marknelson.us/2007/04/01/puzzling/#comment-42635</link>
		<dc:creator>Mark</dc:creator>
		<pubDate>Thu, 01 Nov 2007 11:59:19 +0000</pubDate>
		<guid>http://marknelson.us/2007/04/01/puzzling/#comment-42635</guid>
		<description>I don't have any major issues with what Anders says, but I do have a couple of comments.

First, as to the start with a quad-nested loop. I frequently (especially when writing) start with the most elemental brute force implementation possible. There are a couple of really good reasons to do this.

A brute force solution is usually much easier to prove correct. It is often much easier to understand, especially for someone who is not an experiences programmer or developer. So it provides a really good starting point for a more optimized version of the algorithm. It's natural for a developer to jump directly into something more optimal, and it certainly makes sense to do that for regular work, but for an article I happen to like the slower approach.

Second, I'm not sold on the notion that a choice of a static or scripted language predisposes you to certain behaviors. I think it more likely that the facilities your language provides are what drives your choices.

As in this example. It's no secret that C/C++ (the language I use at work all day, and thus my language of choice) is lamentably weak on string handling. Further, associative arrays are a relatively new feature, and hashed associative arrays are still not part of the standard. (Unless TR1 has passed and I haven't received the news yet.)

So someone who writes Perl code all day is much more likely to have worked on problems analyzing text, using regular expressions, and using strings as keys into other data structures. It's not the scripting that does this, it would be  just as true in a statically typed language that had great string support.

The interesting thing is that an optimal solution to this problem ends up looking similar in all the languages we've seen here. Even the unfamiliar Haskell looks vaguely familiar.

I'd really enjoy seeing some cases with language X, Y, and Z where the optimal C++ solution was not so good, and the optimal X/Y/Z solution looked amazingly different. Last time I did any functional programming was maybe 1975? and that seems like one place where you might be able to Think Different.</description>
		<content:encoded><![CDATA[<p>I don&#8217;t have any major issues with what Anders says, but I do have a couple of comments.</p>
<p>First, as to the start with a quad-nested loop. I frequently (especially when writing) start with the most elemental brute force implementation possible. There are a couple of really good reasons to do this.</p>
<p>A brute force solution is usually much easier to prove correct. It is often much easier to understand, especially for someone who is not an experiences programmer or developer. So it provides a really good starting point for a more optimized version of the algorithm. It&#8217;s natural for a developer to jump directly into something more optimal, and it certainly makes sense to do that for regular work, but for an article I happen to like the slower approach.</p>
<p>Second, I&#8217;m not sold on the notion that a choice of a static or scripted language predisposes you to certain behaviors. I think it more likely that the facilities your language provides are what drives your choices.</p>
<p>As in this example. It&#8217;s no secret that C/C++ (the language I use at work all day, and thus my language of choice) is lamentably weak on string handling. Further, associative arrays are a relatively new feature, and hashed associative arrays are still not part of the standard. (Unless TR1 has passed and I haven&#8217;t received the news yet.)</p>
<p>So someone who writes Perl code all day is much more likely to have worked on problems analyzing text, using regular expressions, and using strings as keys into other data structures. It&#8217;s not the scripting that does this, it would be  just as true in a statically typed language that had great string support.</p>
<p>The interesting thing is that an optimal solution to this problem ends up looking similar in all the languages we&#8217;ve seen here. Even the unfamiliar Haskell looks vaguely familiar.</p>
<p>I&#8217;d really enjoy seeing some cases with language X, Y, and Z where the optimal C++ solution was not so good, and the optimal X/Y/Z solution looked amazingly different. Last time I did any functional programming was maybe 1975? and that seems like one place where you might be able to Think Different.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Asmo</title>
		<link>http://marknelson.us/2007/04/01/puzzling/#comment-42617</link>
		<dc:creator>Asmo</dc:creator>
		<pubDate>Thu, 01 Nov 2007 08:53:05 +0000</pubDate>
		<guid>http://marknelson.us/2007/04/01/puzzling/#comment-42617</guid>
		<description>Hi Mark!

Check out Anders Pearson's analysis about your approach to the problem and how he sees that relates to programming languages:

http://thraxil.org/users/anders/posts/2007/10/30/A-Simple-Programming-Puzzle-Seen-Through-Three-Different-Lenses/

An interesting read, as was this article.</description>
		<content:encoded><![CDATA[<p>Hi Mark!</p>
<p>Check out Anders Pearson&#8217;s analysis about your approach to the problem and how he sees that relates to programming languages:</p>
<p><a href="http://thraxil.org/users/anders/posts/2007/10/30/A-Simple-Programming-Puzzle-Seen-Through-Three-Different-Lenses/" rel="nofollow">http://thraxil.org/users/anders/posts/2007/10/30/A-Simple-Programming-Puzzle-Seen-Through-Three-Different-Lenses/</a></p>
<p>An interesting read, as was this article.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 50 States Programming Puzzle</title>
		<link>http://marknelson.us/2007/04/01/puzzling/#comment-42604</link>
		<dc:creator>50 States Programming Puzzle</dc:creator>
		<pubDate>Thu, 01 Nov 2007 06:43:23 +0000</pubDate>
		<guid>http://marknelson.us/2007/04/01/puzzling/#comment-42604</guid>
		<description>[...] found out about it from Mark Nelson who, in turn, heard it on NPR. It&#8217;s not a terribly difficult riddle if you take a moment to [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] found out about it from Mark Nelson who, in turn, heard it on NPR. It&#8217;s not a terribly difficult riddle if you take a moment to [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike W.</title>
		<link>http://marknelson.us/2007/04/01/puzzling/#comment-42596</link>
		<dc:creator>Mike W.</dc:creator>
		<pubDate>Thu, 01 Nov 2007 04:21:25 +0000</pubDate>
		<guid>http://marknelson.us/2007/04/01/puzzling/#comment-42596</guid>
		<description>I have a solution that while for the problem at hand might be overkill is never the less another approach to the problem.

In essence the solution consists of the following
Build a list of the unique 2 state pairs and combine the letters in the pair into string. store the list of the original strings in on table on a sql db and store a list of alphabettically sorted strings in another column in that same table. do a select(unsortedstring) where count(sortedstring &#62; 1) order by sortedstring. you will then get the answer to the problem</description>
		<content:encoded><![CDATA[<p>I have a solution that while for the problem at hand might be overkill is never the less another approach to the problem.</p>
<p>In essence the solution consists of the following<br />
Build a list of the unique 2 state pairs and combine the letters in the pair into string. store the list of the original strings in on table on a sql db and store a list of alphabettically sorted strings in another column in that same table. do a select(unsortedstring) where count(sortedstring &gt; 1) order by sortedstring. you will then get the answer to the problem</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark</title>
		<link>http://marknelson.us/2007/04/01/puzzling/#comment-34746</link>
		<dc:creator>Mark</dc:creator>
		<pubDate>Sun, 02 Sep 2007 12:38:56 +0000</pubDate>
		<guid>http://marknelson.us/2007/04/01/puzzling/#comment-34746</guid>
		<description>if only I understood the first thing about Haskell!</description>
		<content:encoded><![CDATA[<p>if only I understood the first thing about Haskell!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Moertel</title>
		<link>http://marknelson.us/2007/04/01/puzzling/#comment-34734</link>
		<dc:creator>Tom Moertel</dc:creator>
		<pubDate>Sun, 02 Sep 2007 03:36:29 +0000</pubDate>
		<guid>http://marknelson.us/2007/04/01/puzzling/#comment-34734</guid>
		<description>If you are interested in seeing a Haskell solution, I wrote one to demonstrate a handy little clustering function that I use all the time. I'll not tempt the Worpress comment module to mangle the code (indentation is important in Haskell) so here's the link instead: http://blog.moertel.com/articles/2007/09/01/clusterby-a-handy-little-function-for-the-toolbox

Cheers! --Tom</description>
		<content:encoded><![CDATA[<p>If you are interested in seeing a Haskell solution, I wrote one to demonstrate a handy little clustering function that I use all the time. I&#8217;ll not tempt the Worpress comment module to mangle the code (indentation is important in Haskell) so here&#8217;s the link instead: <a href="http://blog.moertel.com/articles/2007/09/01/clusterby-a-handy-little-function-for-the-toolbox" rel="nofollow">http://blog.moertel.com/articles/2007/09/01/clusterby-a-handy-little-function-for-the-toolbox</a></p>
<p>Cheers! &#8211;Tom</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Emmett Shear</title>
		<link>http://marknelson.us/2007/04/01/puzzling/#comment-34718</link>
		<dc:creator>Emmett Shear</dc:creator>
		<pubDate>Sat, 01 Sep 2007 20:41:06 +0000</pubDate>
		<guid>http://marknelson.us/2007/04/01/puzzling/#comment-34718</guid>
		<description>Heh, oops. I just actually read all the comments and noticed Vince took the same approach I did, with very similar looking code. I guess I'll post my solution anyway (Ruby, yay!) even though it doesn't add too much. This solution runs in much less than one second, and took me only a two minutes to code (including debugging). I prettied it up a little bit to post here though...

[code]
  combos = Hash.new
  states.each do &#124;state&#124;
    states.each do &#124;state2&#124;
      # each pair of states can be represented as a list of sorted characters for our purposes
      key = (state.downcase   state2.downcase).split("").sort.join("")
      combos[key] &#124;&#124;= []
      # checking for duplicates is strictly unnecessary, but makes printing at the end prettier
      combos[key]  1}
  
  puts "First pair"
  puts(pairs[0])
  puts "Second pair"
  puts(pairs[1])
[/code]</description>
		<content:encoded><![CDATA[<p>Heh, oops. I just actually read all the comments and noticed Vince took the same approach I did, with very similar looking code. I guess I'll post my solution anyway (Ruby, yay!) even though it doesn't add too much. This solution runs in much less than one second, and took me only a two minutes to code (including debugging). I prettied it up a little bit to post here though...</p>
<div class="igBar"><span id="lcode-1"><a href="#" onclick="javascript:showPlainTxt('code-1'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-1">
<div class="code">
<ol>
<li class="li1">
<div class="de1">combos = Hash.<span class="me1">new</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; states.<span class="me1">each</span> do |state|</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; states.<span class="me1">each</span> do |state2|</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; # each pair of states can be represented as a list of sorted characters for our purposes</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; key = <span class="br0">&#40;</span>state.<span class="me1">downcase</span>&nbsp; &nbsp;state2.<span class="me1">downcase</span><span class="br0">&#41;</span>.<span class="me1">split</span><span class="br0">&#40;</span><span class="st0">""</span><span class="br0">&#41;</span>.<span class="me1">sort</span>.<span class="me1">join</span><span class="br0">&#40;</span><span class="st0">""</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; combos<span class="br0">&#91;</span>key<span class="br0">&#93;</span> ||= <span class="br0">&#91;</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; # checking for duplicates is strictly unnecessary, but makes printing at the end prettier</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; combos<span class="br0">&#91;</span>key<span class="br0">&#93;</span>&nbsp; <span class="nu0">1</span><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; puts <span class="st0">"First pair"</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; puts<span class="br0">&#40;</span>pairs<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; puts <span class="st0">"Second pair"</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; puts<span class="br0">&#40;</span>pairs<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
	</item>
</channel>
</rss>
