<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>The Complexity Hammer</title><link>http://blogs.msdn.com/b/steverowe/archive/2010/03/16/if-complexity-is-the-hammer-not-all-problems-are-nails.aspx</link><description>I’ve been doing a lot of interviewing lately, especially of college students. There is one tendency I see a that really separates those that are good from those who still have more learning to do. This is the tendency of the good programmers to see elegant</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: The Complexity Hammer</title><link>http://blogs.msdn.com/b/steverowe/archive/2010/03/16/if-complexity-is-the-hammer-not-all-problems-are-nails.aspx#9990271</link><pubDate>Sun, 04 Apr 2010 13:46:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9990271</guid><dc:creator>hiryu</dc:creator><description>&lt;p&gt;I agree with jonathan opinion about this article Jonathan what you meant by memoization is it suppose to be memorization or something else?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9990271" width="1" height="1"&gt;</description></item><item><title>re: The Complexity Hammer</title><link>http://blogs.msdn.com/b/steverowe/archive/2010/03/16/if-complexity-is-the-hammer-not-all-problems-are-nails.aspx#9982730</link><pubDate>Mon, 22 Mar 2010 03:45:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9982730</guid><dc:creator>Jonathan</dc:creator><description>&lt;p&gt;To me, factors that would impact on how well someone goes on a task like this would be:&lt;/p&gt;
&lt;p&gt;* problem solving skills&lt;/p&gt;
&lt;p&gt;* level of nervousness&lt;/p&gt;
&lt;p&gt;The interviewee that has well developed problem solving skills may be helped secondarily by having the confidence to sit back and think about it, and conversely, a nervous interviewee probably won't have that confidence.&lt;/p&gt;
&lt;p&gt;I've noticed that &amp;quot;sitting back and thinking about it&amp;quot; can't be done (well) in front of the computer, or at least, not while using the computer, because it seems to bring the thought levels down to details and pixels, not concepts and possibilities.&lt;/p&gt;
&lt;p&gt;Also, I came across some brain fitness research (can't recall the link, sorry) which relates to how well they deal with the solution being wrong. &amp;nbsp;Basically, when someone is afraid (read &amp;quot;nervous&amp;quot;) or tired, and fails at something, they tend to retry the same or similar solutions - thus getting stuck in a rut. &amp;nbsp;This can be applied to life, and gives me some food for thought - I think it has been picked up by some self-help book authors too.&lt;/p&gt;
&lt;p&gt;But also, and slightly off on a tangent, relating more to my previous post, what may also affect the outcome is how well they know the language/tools, and thus how well they can match the problem (or sub-problems) to existing solutions. &amp;nbsp;For example, regarding optimization, because of the way it is written, the lisp solution above is amenable to memoization.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9982730" width="1" height="1"&gt;</description></item><item><title>re: The Complexity Hammer</title><link>http://blogs.msdn.com/b/steverowe/archive/2010/03/16/if-complexity-is-the-hammer-not-all-problems-are-nails.aspx#9982527</link><pubDate>Sun, 21 Mar 2010 11:41:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9982527</guid><dc:creator>Jonathan</dc:creator><description>&lt;p&gt;A bit OT, and it's probably unreadable, but it came to me as I read your post. &amp;nbsp;It loops a total of 557 times, but also uses recursion. &amp;nbsp;Perhaps it will stimulate discussion :).&lt;/p&gt;
&lt;p&gt;&amp;gt;(defun make-change (&amp;amp;optional (amount 100) (coins (list 25 10 5 1)))&lt;/p&gt;
&lt;p&gt;&amp;gt; &amp;nbsp;(when coins&lt;/p&gt;
&lt;p&gt;&amp;gt; &amp;nbsp; &amp;nbsp;(if (cdr coins)&lt;/p&gt;
&lt;p&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;(iter (for i from 0)&lt;/p&gt;
&lt;p&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(for remains downfrom amount by (car coins))&lt;/p&gt;
&lt;p&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(while (&amp;gt;= remains 0))&lt;/p&gt;
&lt;p&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(appending (mapcar (curry #'cons i)&lt;/p&gt;
&lt;p&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-change remains (cdr coins)))))&lt;/p&gt;
&lt;p&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;(if (zerop (mod amount (car coins)))&lt;/p&gt;
&lt;p&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(list (list (/ amount (car coins))))))))&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9982527" width="1" height="1"&gt;</description></item><item><title>re: The Complexity Hammer</title><link>http://blogs.msdn.com/b/steverowe/archive/2010/03/16/if-complexity-is-the-hammer-not-all-problems-are-nails.aspx#9981299</link><pubDate>Thu, 18 Mar 2010 17:55:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9981299</guid><dc:creator>SteveRowe</dc:creator><description>&lt;p&gt;@Chad/Rick. &amp;nbsp;Good catch. &amp;nbsp;I'll change it.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9981299" width="1" height="1"&gt;</description></item><item><title>re: The Complexity Hammer</title><link>http://blogs.msdn.com/b/steverowe/archive/2010/03/16/if-complexity-is-the-hammer-not-all-problems-are-nails.aspx#9980594</link><pubDate>Wed, 17 Mar 2010 18:14:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9980594</guid><dc:creator>Chad</dc:creator><description>&lt;p&gt;@Rick, the equality test in BetterMakeChange() should be with 100:&lt;/p&gt;
&lt;p&gt;if (100 == (quarters*25 + dimes*10 + nickles*5 + pennies)) print…;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9980594" width="1" height="1"&gt;</description></item><item><title>re: The Complexity Hammer</title><link>http://blogs.msdn.com/b/steverowe/archive/2010/03/16/if-complexity-is-the-hammer-not-all-problems-are-nails.aspx#9980425</link><pubDate>Wed, 17 Mar 2010 14:33:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9980425</guid><dc:creator>Rick</dc:creator><description>&lt;p&gt;In BetterMakeChange(), the if check only evaluates to true on the first pass through, when the change for a dollar is 0 quarters, 0 dimes, 0 nickels, and 0 pennies.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9980425" width="1" height="1"&gt;</description></item><item><title>re: The Complexity Hammer</title><link>http://blogs.msdn.com/b/steverowe/archive/2010/03/16/if-complexity-is-the-hammer-not-all-problems-are-nails.aspx#9979905</link><pubDate>Tue, 16 Mar 2010 21:59:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9979905</guid><dc:creator>SteveRowe</dc:creator><description>&lt;p&gt;As I said at the bottom of the post, this is meant to demonstrate a way of solving problems that is often indicative of a broader pattern. Don't get hung up on the specifics of the implementation. &amp;nbsp;The fact that there are hard coded constants is because it makes reading simple for this example. &amp;nbsp;The penny loop isn't optimized away either and it doesn't abort when the total is too high mid-loop. &amp;nbsp;This is to demonstrate a point, it's not how I would advocate writing such a program.&lt;/p&gt;
&lt;p&gt;@Mike, how do you enumerate all ways of making change without a loop? &amp;nbsp;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9979905" width="1" height="1"&gt;</description></item><item><title>re: The Complexity Hammer</title><link>http://blogs.msdn.com/b/steverowe/archive/2010/03/16/if-complexity-is-the-hammer-not-all-problems-are-nails.aspx#9979880</link><pubDate>Tue, 16 Mar 2010 21:27:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9979880</guid><dc:creator>Maurits [MSFT]</dc:creator><description>&lt;p&gt;Some free complexity analysis: the stateless example makes the &amp;quot;is the total accurate&amp;quot; comparison (4 + 1) * (10 + 1) * (20 + 1) * (100 + 1) = 116,655 times.&lt;/p&gt;
&lt;p&gt;By comparison, the stateful version makes the comparison 6,962 times (I calculated this by incrementing a global every time the comparison was executed. &amp;nbsp;I an not aware of s a way to calculate this elegantly.)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9979880" width="1" height="1"&gt;</description></item><item><title>re: The Complexity Hammer</title><link>http://blogs.msdn.com/b/steverowe/archive/2010/03/16/if-complexity-is-the-hammer-not-all-problems-are-nails.aspx#9979830</link><pubDate>Tue, 16 Mar 2010 20:26:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9979830</guid><dc:creator>Maurits [MSFT]</dc:creator><description>&lt;p&gt;&amp;gt; What if we wanted to make change for something other than $1.00?&lt;/p&gt;
&lt;p&gt;Well said... and what if you want to make change in a country that uses a 0.20 piece rather than a 0.25 piece? &amp;nbsp;And what if you want to allow half-dollars?&lt;/p&gt;
&lt;p&gt;Sometimes solving the general question is easier than solving the easier version:&lt;/p&gt;
&lt;p&gt;use strict;&lt;/p&gt;
&lt;p&gt;#&lt;/p&gt;
&lt;p&gt;# first argument is a prefix&lt;/p&gt;
&lt;p&gt;#&lt;/p&gt;
&lt;p&gt;# second argument is the amount of money to change&lt;/p&gt;
&lt;p&gt;#&lt;/p&gt;
&lt;p&gt;# the rest of the arguments are the eligible coins&lt;/p&gt;
&lt;p&gt;# these must be unique, &amp;gt; 0, integral, and in descending order&lt;/p&gt;
&lt;p&gt;#&lt;/p&gt;
&lt;p&gt;# no return; just prints out the available combinations&lt;/p&gt;
&lt;p&gt;sub change($$@);&lt;/p&gt;
&lt;p&gt;change(&amp;quot;\t&amp;quot;, 100, 25, 10, 5, 1);&lt;/p&gt;
&lt;p&gt;sub change($$@) {&lt;/p&gt;
&lt;p&gt;	my $prefix = shift;&lt;/p&gt;
&lt;p&gt;	my $total = shift;&lt;/p&gt;
&lt;p&gt;	my @coins = @_;&lt;/p&gt;
&lt;p&gt;	if (@coins == 0) {&lt;/p&gt;
&lt;p&gt;		# if the total came to 0 we have a solution&lt;/p&gt;
&lt;p&gt;		print $prefix, &amp;quot;\n&amp;quot; unless $total;&lt;/p&gt;
&lt;p&gt;		return;&lt;/p&gt;
&lt;p&gt;	}&lt;/p&gt;
&lt;p&gt;	my $coin = shift(@coins);&lt;/p&gt;
&lt;p&gt;	my $most = int($total / $coin);&lt;/p&gt;
&lt;p&gt;	for my $count (0 .. $most) {&lt;/p&gt;
&lt;p&gt;		change(&lt;/p&gt;
&lt;p&gt;			$prefix . ($count ? &amp;quot; $count * $coin&amp;quot; : &amp;quot;&amp;quot;),&lt;/p&gt;
&lt;p&gt;			$total - $count * $coin,&lt;/p&gt;
&lt;p&gt;			@coins&lt;/p&gt;
&lt;p&gt;		);&lt;/p&gt;
&lt;p&gt;	}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9979830" width="1" height="1"&gt;</description></item><item><title>re: The Complexity Hammer</title><link>http://blogs.msdn.com/b/steverowe/archive/2010/03/16/if-complexity-is-the-hammer-not-all-problems-are-nails.aspx#9979766</link><pubDate>Tue, 16 Mar 2010 19:26:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9979766</guid><dc:creator>Chad</dc:creator><description>&lt;p&gt;Personally, I've had limited success applying rules of thumb like &amp;quot;step back and look for a more elegant solution.&amp;quot; It's about as effective as cajoling developers to &amp;quot;Be More Innovative&amp;quot; or &amp;quot;Don't add bugs.&amp;quot; We know these things, but they don't tell us how to do these things.&lt;/p&gt;
&lt;p&gt;Adding better tools to ones toolbox pays better dividends: Gather data through repeatable experiments. Divide and Conquer. Identify a simpler version of the problem and solve it first.&lt;/p&gt;
&lt;p&gt;I'm surprised at the pooh-poohing of state. There are often times when keeping state around makes a problem much simpler to solve, especially for table-driven methods. In all my algorithmic training, I can't remember an instance where having four levels of deeply-nested for-loops was part of an elegant solution. Even if performance isn't an essential requirement for the code, the code seems awfully un-reusable. What if we wanted to make change for something other than $1.00? All those hard-coded (and uncommented) magic numbers would have to be re-calculated in some programmer's head.&lt;/p&gt;
&lt;p&gt;I do agree that watching great programmers solve problems is a joy.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9979766" width="1" height="1"&gt;</description></item></channel></rss>