<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Prog-a-Month &#187; business</title>
	<atom:link href="http://www.progamonth.com/?feed=rss2&#038;cat=19" rel="self" type="application/rss+xml" />
	<link>http://www.progamonth.com</link>
	<description>The journeys of a programmer</description>
	<lastBuildDate>Sat, 22 May 2010 23:01:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Still Alive.</title>
		<link>http://www.progamonth.com/?p=277</link>
		<comments>http://www.progamonth.com/?p=277#comments</comments>
		<pubDate>Tue, 27 Apr 2010 04:35:33 +0000</pubDate>
		<dc:creator>Stefan Kendall</dc:creator>
				<category><![CDATA[Meta]]></category>
		<category><![CDATA[business]]></category>
		<category><![CDATA[future]]></category>
		<category><![CDATA[grails]]></category>

		<guid isPermaLink="false">http://www.progamonth.com/?p=277</guid>
		<description><![CDATA[I&#8217;m currently working on a few side projects while trying to learn and use/deploy applications on Grails. I&#8217;ve also purchased another domain for my conquests. Hopefully I&#8217;ll have more to say about my side projects in the next few months, but I&#8217;ll hopefully get a Grails post up in early May. Expect pretty screenshots.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently working on a few side projects while trying to learn and use/deploy applications on <a href="http://grails.org/">Grails</a>. I&#8217;ve also purchased another domain for my conquests. Hopefully I&#8217;ll have more to say about my side projects in the next few months, but I&#8217;ll hopefully get a Grails post up in early May. Expect pretty screenshots.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.progamonth.com/?feed=rss2&amp;p=277</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>100 ways to skin an interview question</title>
		<link>http://www.progamonth.com/?p=235</link>
		<comments>http://www.progamonth.com/?p=235#comments</comments>
		<pubDate>Wed, 24 Feb 2010 20:17:44 +0000</pubDate>
		<dc:creator>Stefan Kendall</dc:creator>
				<category><![CDATA[business]]></category>
		<category><![CDATA[interviews]]></category>

		<guid isPermaLink="false">http://www.progamonth.com/?p=235</guid>
		<description><![CDATA[In a recent interview, I was asked the following question: Write a program to determine the 10th Fibonacci number. Without further specification, this problem is worthless. Depending on the scope and nature of the program, the solution to this problem will vary wildly. For example, will this function get called in a tight inner loop? [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent interview, I was asked the following question:</p>
<blockquote><p>Write a program to determine the 10th Fibonacci number.</p></blockquote>
<p>Without further specification, this problem is worthless. Depending on the scope and nature of the program, the solution to this problem will vary wildly. For example, will this function get called in a tight inner loop? What are the memory constraints? What are the concerns with respect to reusability? I&#8217;ll make this more concrete below.</p>
<h2>Naive solution</h2>
<pre class = "code" name = "python">
def F(n):
   if n == 1 or n == 0:
      return 1
   return F(n-1) + F(n-2)
</pre>
<p>Why this is completely wrong: What happens when you pass a fractional value to F(n)? You break. What happens if you pass a negative value? You break. You could fix this by checking if n <= 1 in the base case, but then you still have unneeded redundancy. Without explicitly defining the interface by which you generate a series, you've broken your code completely. Expect bugs, and expect huge memory waste. These results could be <a href="http://en.wikipedia.org/wiki/Memoization">memoized</a>, but consider the initial problem statement. Was there any implication that anything other than F(10) would need to be computed? No. This gives us a rather smart-ass solution.</p>
<h2>Efficient Solution</h2>
<p>Consider the following:</p>
<pre class = "code" name = "cpp">
#define Fib10 89</pre>
<p>If you can&#8217;t trust the compiler, memory constraints are tight, or performance is an issue, precomputation is clearly the solution. You KNOW F(10) without any programming whatsoever. You can compute it by hand and yield the above result. A more scrupulous reader might notice that F(10)==89 isn&#8217;t easily verifiable without writing code. A better solution might look like this.</p>
<h2>Verifiable Efficient Solution</h2>
<pre class = "code" name = "cpp">
#define Fib10 (1+1+2+3+5+8+13+21+34+55)
</pre>
<p>It&#8217;s still sloppy, but it&#8217;s as efficient as the previous solution and easier to verify. This solution, however, has a fatal flaw: it only works for one value of N (although you could define more), and it&#8217;s not reusable at all. A compromise between efficiency and reusability might give you the following.</p>
<h2>The Compromise Solution</h2>
<pre class = "code" name = "python">
Fib = [1,1]
for i in range(2,100):
   Fib.append( Fib[i-1]+Fib[i-2] )
</pre>
<p>This has no edge cases, it&#8217;s rather easy to verify, and you can adjust the maximum required value as necessary. This requires a fixed max size, though, which means it&#8217;s sure to break at some point. At best, you&#8217;re stuck with documenting this limitation. Once again, we consider memoization, but we can remember to avoid the unnecessary recursion to keep the solution a bit more efficient.</p>
<p>So, then, what do you do? Create something reusable.</p>
<h2>The Reusable Solution</h2>
<p>The code is getting funkier, so I&#8217;ll leave this as an exercise to the reader for now. Essentially, we can encapsulate the compromise solution in a class. If a client requests a Fibonacci number greater than that which we&#8217;ve precomputed, we compute up to the given value and store the intermediate computations. This solution, however, ignores the fact that most would ignore when approaching this problem. </p>
<h2>The Math Solution</h2>
<p><strong>Namely, Fibonacci numbers can be generated in constant time</strong> with <a href="http://en.wikipedia.org/wiki/Fibonacci_number#Computation_by_rounding">Binet&#8217;s formula</a>.</p>
<p>For reasonable values of N, the rounding formula provides exact values.</p>
<h2>The Real Solution</h2>
<p>So what, then, is the right answer? It really depends on information left out of the problem statement. In the real world, you would probably just use a math library to get the values, knowing that someone has gone through the same thought process through which you&#8217;ve just gone. If this isn&#8217;t possible, then you have to consider one of the above methods.</p>
<p>One might argue that this reasoning ability is what an interviewer should be looking for, but that was not the emphasis of the question. Really, there are just better questions you can ask a person to figure out if they&#8217;re worth their salt, unless, of course, you&#8217;re really just pre-screening, at which point you&#8217;re just looking for the response &#8220;89.&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.progamonth.com/?feed=rss2&amp;p=235</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
