<?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>Chris Cowdery &#187; Blog</title>
	<atom:link href="http://www.chriscowdery.com/posts/category/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://www.chriscowdery.com</link>
	<description>Coding, Design and all things Tech</description>
	<lastBuildDate>Sun, 27 Jun 2010 22:54:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Fun with Computer Vision</title>
		<link>http://www.chriscowdery.com/posts/179</link>
		<comments>http://www.chriscowdery.com/posts/179#comments</comments>
		<pubDate>Sun, 27 Jun 2010 22:35:06 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Computer Vision]]></category>

		<guid isPermaLink="false">http://www.chriscowdery.com/?p=179</guid>
		<description><![CDATA[One of my early projects in Computer Vision was a simple Optical Character Recognition (OCR) program. Although this is by no means anything new, it&#8217;s still fun to learn how it works, and I&#8217;m going to share with you a little demo of OCR that you can create yourself!
Your mission, should you choose to accept it: Detect [...]]]></description>
			<content:encoded><![CDATA[<p>One of my early projects in Computer Vision was a simple <a href="http://en.wikipedia.org/wiki/Optical_character_recognition" target="_blank">Optical Character Recognition</a> (OCR) program. Although this is by no means anything new, it&#8217;s still fun to learn how it works, and I&#8217;m going to share with you a little demo of OCR that you can create yourself!</p>
<p>Your mission, should you choose to accept it: <strong>Detect all the letter i&#8217;s on a document!</strong></p>
<p>Couple of things to note:</p>
<ul>
<li>Not all of the letter i&#8217;s will look the same (there will be some blotches of ink that make the letters look a little different)</li>
<li>You won&#8217;t have knowledge of what every single letter i looks like (or ever will look like) in the universe</li>
<li>You won&#8217;t have to recognize handwriting (that&#8217;s another party in and of itself)</li>
</ul>
<p>So let&#8217;s get started! We&#8217;ll be using the following document for our character detection:</p>
<p><a rel="attachment wp-att-180" href="http://www.chriscowdery.com/posts/179/textimage"><img class="aligncenter size-medium wp-image-180" title="TextImage" src="http://www.chriscowdery.com/wp-content/uploads/2010/06/TextImage-590x514.png" alt="" width="590" height="514" /></a></p>
<p>First, we can break the problem down into a bunch of subtasks, namely:</p>
<div id="_mcePaste">
<ol>
<li>Manipulating the data to make a solution easier for the program to visualize.</li>
<li>Cropping the image to the area of interest (getting rid of the image and handwriting above).</li>
<li>Finding and extracting ‘templates’, regions of the image which contain the ‘i’s we’re looking for.</li>
<li>Determining the locations of each row of text.</li>
<li>Correlating the template of the i character with each possible character.</li>
<li>Determining thresholds for each of the templates (the &#8216;bouncer&#8217; which determines if a character is really an i or not).</li>
<li>Displaying the results with the rectangles around each i.</li>
</ol>
</div>
<p>So let&#8217;s get started! I&#8217;ll be using <a href="http://www.mathworks.com/products/matlab/" target="_blank">MATLAB</a> and the <a href="http://www.mathworks.com/products/image/" target="_blank">Image Processing Toolbox</a> for my implementation in this post, but I&#8217;ll also attach a script which accomplishes the same results using Python.</p>
<h2>Manipulating the Data</h2>
<p>First things first, we need to read in our image. We&#8217;ll do that as follows:</p>
<blockquote><p>im = imread(&#8216;TextImage.tif&#8217;);<br />
im = im2double(im);</p></blockquote>
<p>This reads in the TextImage.tif image as a grayscale image,  and assigns each pixel to an intensity between 0 and 1 inclusive. However, we&#8217;re not quite done yet. By convention, data of interest is represented as white (all 1&#8217;s), and data which isn&#8217;t of interest being black (all 0&#8217;s) &#8211; so we&#8217;ll want to invert our image to show that the black text we just read in is of interest (e.g. white) we&#8217;ll do that as follows:</p>
<blockquote><p>im = imadjust(im, [0 1],[1 0]);</p></blockquote>
<div>This effectively says &#8220;Hey, what&#8217;s black is white, and what&#8217;s white is black!&#8221;. Pretty concise and nifty.</div>
<div>But wait! We&#8217;re not quite done yet. We need to do some <strong>thresholding</strong> of the data which we have so far. This process defines a &#8216;cut off&#8217; in that anything that is above (or equal to) the value we specify is scaled automatically to its maximum value, and anything below it is scaled automatically to its minimum value. In this case, our pixels will either go to 1 or 0 (as this is the range of our data). We&#8217;re doing this step to eliminate the paper grain, noise, and other image artifacts that aren&#8217;t of interest.</div>
<div>Thresholding values are usually determined after some experimentation and some number fiddling, but I found a good threshold for this document was <strong>0.05</strong>. We can apply it like so:</div>
<blockquote>
<div>THRESHOLD = 0.05;</div>
<div>im = im &gt; THRESHOLD;</div>
</blockquote>
<h2>Cropping the Image</h2>
<p>Although this is not an essential step, and the algorithm which we&#8217;ll be implementing soon will function fine without it, we&#8217;re going to restrict the area which we&#8217;ll be looking at. This helps for visualization in the end, and can be accomplished pretty quickly.</p>
<blockquote><p>im = im(400:end,:);</p></blockquote>
<p>This line of code cuts off everything above 400px, and leaves the rest of our image intact (end MATLAB knows means &#8220;go to the end of the image&#8221;, it&#8217;s not a variable we set earlier).</p>
<h2>Finding Templates</h2>
<p>The next goal we&#8217;ll have is to extract i&#8217;s from the image above that are of interest to us (computer vision junkies call these &#8216;templates&#8217;). I usually open up Adobe Photoshop and manually select areas which are of interest, and copy and paste the pixel coordinates. It&#8217;s important to note that we&#8217;re &#8216;cheating&#8217; on some level as we have a priori knowledge of what our document already looks like &#8211; a luxury which many commercial OCR software systems don&#8217;t often have <img src='http://www.chriscowdery.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Alas, I&#8217;ve taken some of the dirty work out for you, and found some i&#8217;s which are indicative of i&#8217;s across the entire document. Here&#8217;s my findings:</p>
<blockquote><p>templateOne = im(510:542, 532:551);<br />
templateOne = im2double(templateOne);</p>
<p>templateTwo = im(68:100, 390:409);<br />
templateTwo = im2double(templateTwo);</p>
<p>templateThree = im(266:298, 899:918);<br />
templateThree = im2double(templateThree);</p>
<p>templateFour = im(67:99, 144:163);<br />
templateFour = im2double(templateFour);</p>
<p>templateFive = im(168:200, 875:894);<br />
templateFive = im2double(templateFive);</p></blockquote>
<p>So we now have five templates (patches of the letter i in the image), each template is 19 pixels wide and 32 pixels tall. Now we&#8217;re going to combine all of them into an array for easy access later.</p>
<blockquote><p>templates(:,:,1) = templateOne;<br />
templates(:,:,2) = templateTwo;<br />
templates(:,:,3) = templateThree;<br />
templates(:,:,4) = templateFour;<br />
templates(:,:,5) = templateFive;</p></blockquote>
<p>This creates a three dimensional array. In the first two dimensions, we store the grayscale intensity (again from 0 to 1 inclusive) of the templates we found. Each index in the third dimension represents another template (The colon (:) operator in MATLAB is shorthand for &#8220;include everything&#8221;). So imagine a cardboard box stacked with a bunch of sheets of paper of the letter i on them, roughly speaking.</p>
<h2>Finding the rows of text</h2>
<p>Here&#8217;s some fun debauchery. We need to detect where each row of text  begins so that we know where we can match our templates to, and this can be accomplished fairly quickly.</p>
<p>First, what we need to do is rotate the image 90 degrees (put it on its side), and add up the pixel values in each <em>column. </em>Note that now that the image is rotated 90 degrees, what used to be <em>rows are now columns</em>. We&#8217;re rotating the image 90 degrees as it plays nicer with MATLAB&#8217;s sum function (only adds up columns). We&#8217;ll then be storing this in an array called spaces.</p>
<blockquote><p>spaces = sum(im&#8217;);</p></blockquote>
<p>Next, we need to determine (another) threshold, the intensity of what each row of text should be when summed up. If the sum of each row doesn&#8217;t match a threshold, there probably isn&#8217;t text there, so it&#8217;s not the beginning of a row. We can threshold the row sums by doing the following:</p>
<blockquote><p>ROW_SPACE_THRESHOLD = 10;<br />
spaces = spaces &gt; (ROW_SPACE_THRESHOLD);</p></blockquote>
<p>Now let&#8217;s detect <em>where</em> changes occur by taking the derivative of spaces. This highlights where values changed from 0 to 1 and vice versa. Begins stores where each row begins (derivative is 1), and ends stores where each row ends (derivative is -1).</p>
<blockquote><p>spaceDerivative = diff(spaces);<br />
begins = find(spaceDerivative == 1);<br />
ends = find(spaceDerivative == -1);</p></blockquote>
<h2>Correlating the template</h2>
<p>Before we sink our teeth into the meat of the OCR, we first need to define thresholds for each character template we found. Roughly speaking, this is the amount of &#8217;slack&#8217; we&#8217;ll give to each character we find. If it&#8217;s within this &#8217;slack&#8217; region, the program will think the character we found is an i, otherwise it won&#8217;t be. This is useful as we&#8217;ll never know what every single i looks like (and even if we did, that algorithm would be extremely inefficient), so this defines a level of tolerance in how much a character we are analyzing can deviate from our templates of the letter i to actually be considered the letter i. We&#8217;ll be definining these using integer constants determined by experimentation.</p>
<blockquote><p>MAX_FILTERED_I_VALUES = [ 145, 147, 147, 170, 150 ];</p></blockquote>
<p>Each index of the MAX_FILTERED_I_VALUES corresponds to the tolerance for each template (e.g. the first number corresponds to the first template, and so on). The meaning and purpose of these templates will be explored in greater detail very soon.</p>
<p>Now! This is where the fun starts. First we&#8217;re going to want to iterate through each row we found. We can do that like so:</p>
<blockquote><p>for i = 1 : (min([length(begins) length(ends)])),</p></blockquote>
<p>Next we&#8217;re going to want to extract each row, and then shortly thereafter each character from each row.  We can get the current row this way:</p>
<blockquote><p>currentRow = im(begins(i):ends(i),:);</p></blockquote>
<p>This says, &#8220;hey for this particular row number (index), we only care about pixels from whatever you found from the beginning to the end&#8221;. Now we need to find the spaces in between the characters:</p>
<blockquote><p>row_spaces = sum(currentRow);<br />
row_spaces = row_spaces &gt; 0.8;<br />
row_diff = diff(row_spaces);</p>
<p>charBegin = find(row_diff == 1);<br />
charEnd = find(row_diff == -1);</p></blockquote>
<p>This is a similar approach to what we did before, in that we&#8217;re taking this row of text we found, checking to see if it matches a threshold (which I found by experimentation for you) in each column to see if there&#8217;s actually text there, and then taking the derivative of that threshold to see where each character begins and ends.</p>
<p>Now let&#8217;s loop through each character we found:</p>
<blockquote><p>for j = 1 : min([length(charEnd) length(charBegin)]),</p></blockquote>
<p>Let&#8217;s get things set up for processing:</p>
<blockquote><p>currentChar = currentRow(:,charBegin(j):charEnd(j));<br />
currentChar = im2double(currentChar);</p>
<p>possibleMach = 0;</p></blockquote>
<p>In the above code, we&#8217;re segmenting the character from the image and converting its intensity to a double (why we&#8217;re doing this will be explained soon). We&#8217;re also creating a flag called possibleMatch to determine if we&#8217;ve actually found something that is likely to be an i.</p>
<p>Now for each character we found, iterate through the templates we extracted earlier to see if there&#8217;s a match. Enjoy your <a href="http://en.wikipedia.org/wiki/Big_O_notation" target="_blank">O(n^3) efficiency</a> <img src='http://www.chriscowdery.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> . We can iterate through each template this way (again, this is MATLAB shorthand for: every item in templates, take whatever&#8217;s in the third dimension &#8211; which is where we stored the index of our templates).</p>
<blockquote><p>for k = 1 : length(templates(1,1,:)),</p></blockquote>
<p>And we can correlate our above character with the template this way:</p>
<blockquote><p>filtered = abs(imfilter(currentChar,templates(:,:,k),&#8217;corr&#8217;));<br />
possibleMach = max(filtered(:)) &gt; MAX_FILTERED_I_VALUES(k);</p></blockquote>
<p>This is where the magic happens! Let&#8217;s break apart what we&#8217;re doing here:</p>
<p>In the first lone of code, we do something called a correlation (specified by the &#8216;corr&#8217; string to MATLAB). The correlation operation multiplies each pixel in the neighborhood by the corresponding pixel in the template. The output values (in a Cartesian x,y plane) are a sum of the results. The output value will be the highest at points where the template closely matches. If the value is determined to be a possible match by matching a constant threshold (MAX_FILTERED_I_VALUES), then we have a match.</p>
<p>In other words, the  correlation number returned from the imfilter function is (roughly speaking) a score of how closely the character we just found matches a possible template, and if the correlation value we found is greater than the threshold which we set earlier in MAX_FILTERED_I_VALUES, we&#8217;ve got a match!</p>
<h2>Displaying the Results</h2>
<p>The party is over, and now it&#8217;s time to clean up.  So if we&#8217;ve found a possible match, draw a red rectangle around it:</p>
<blockquote><p>if (possibleMach)</p>
<p>% Draw a red box around each character matching</p>
<p>finalRGB(begins(i):ends(i),charBegin(j),1) = 1.0;<br />
finalRGB(begins(i):ends(i),charBegin(j),2) = 0.0;<br />
finalRGB(begins(i):ends(i),charBegin(j),3) = 0.0;</p>
<p>finalRGB(begins(i):ends(i),charEnd(j),1) = 1.0;<br />
finalRGB(begins(i):ends(i),charEnd(j),2) = 0.0;<br />
finalRGB(begins(i):ends(i),charEnd(j),3) = 0.0;</p>
<p>finalRGB(begins(i),charBegin(j):charEnd(j),1) = 1.0;<br />
finalRGB(begins(i),charBegin(j):charEnd(j),2) = 0.0;<br />
finalRGB(begins(i),charBegin(j):charEnd(j),3) = 0.0;</p>
<p>finalRGB(ends(i),charBegin(j):charEnd(j),1) = 1.0;<br />
finalRGB(ends(i),charBegin(j):charEnd(j),2) = 0.0;<br />
finalRGB(ends(i),charBegin(j):charEnd(j),3) = 0.0;</p>
<p>break;<br />
end</p></blockquote>
<p>We draw a red rectangle by setting the red intensity (By MATLAB, 1st index in the third dimension of the image) to be 1 (all the way) and setting green and blue to be zero.</p>
<p><strong>We&#8217;re done! </strong>Our final product now looks like this:</p>
<p><a rel="attachment wp-att-181" href="http://www.chriscowdery.com/posts/179/screen-shot-2010-04-14-at-7-54-49-pm"><img class="aligncenter size-medium wp-image-181" title="Screen shot 2010-04-14 at 7.54.49 PM" src="http://www.chriscowdery.com/wp-content/uploads/2010/06/Screen-shot-2010-04-14-at-7.54.49-PM-590x316.png" alt="" width="590" height="316" /></a></p>
<p><strong>If you&#8217;d like to download the example source code, it can be found here:<br />
<a href="http://chriscowdery.com/download/blog/ocr-fun.zip">http://chriscowdery.com/download/blog/ocr-fun.zip</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.chriscowdery.com/posts/179/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>It&#8217;s About Time</title>
		<link>http://www.chriscowdery.com/posts/169</link>
		<comments>http://www.chriscowdery.com/posts/169#comments</comments>
		<pubDate>Sun, 27 Jun 2010 07:49:50 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.chriscowdery.com/?p=169</guid>
		<description><![CDATA[Hey! I&#8217;m not dead! In fact I&#8217;m very much alive, and I&#8217;m having a fantastic time down here in California at Apple.

I&#8217;ve been really busy getting into the swing of things, so I apologize for the dearth of updates. But! Without further ado&#8230; posts!
]]></description>
			<content:encoded><![CDATA[<p>Hey! I&#8217;m not dead! In fact I&#8217;m very much alive, and I&#8217;m having a fantastic time down here in California at Apple.</p>
<p><a rel="attachment wp-att-170" href="http://www.chriscowdery.com/posts/169/photo"><img class="aligncenter size-medium wp-image-170" title="Golden Gate Bridge" src="http://www.chriscowdery.com/wp-content/uploads/2010/06/photo-590x442.jpg" alt="" width="590" height="442" /></a></p>
<p>I&#8217;ve been really busy getting into the swing of things, so I apologize for the dearth of updates. But! Without further ado&#8230; posts!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chriscowdery.com/posts/169/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coding Kata &#8211; February 1st 2010 &#8211; Flippin&#8217; Lists</title>
		<link>http://www.chriscowdery.com/posts/151</link>
		<comments>http://www.chriscowdery.com/posts/151#comments</comments>
		<pubDate>Mon, 01 Feb 2010 06:00:40 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Kata]]></category>

		<guid isPermaLink="false">http://www.chriscowdery.com/?p=151</guid>
		<description><![CDATA[Goal: Flip tuples in a doubly linked list.
Example: Given A  B  C  D, have an algorithm produce B  A  D  C.
Constraints: All manipulations must be made to the original linked list, and minimize use of external data structures as much as possible.
Hmmm of the day: The ideal solution is [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Goal:</strong> Flip tuples in a doubly linked list.<br />
Example: Given A <-> B <-> C <-> D, have an algorithm produce B <-> A <-> D <-> C.</p>
<p><strong>Constraints:</strong> All manipulations must be made to the original linked list, and minimize use of external data structures as much as possible.</p>
<p><strong>Hmmm of the day:</strong> The ideal solution is fairly brief and elegant, so don&#8217;t try to over-think it unless you need to!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chriscowdery.com/posts/151/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Coding Kata – January 29 2010 – Playing Vegas</title>
		<link>http://www.chriscowdery.com/posts/149</link>
		<comments>http://www.chriscowdery.com/posts/149#comments</comments>
		<pubDate>Fri, 29 Jan 2010 17:18:36 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Kata]]></category>

		<guid isPermaLink="false">http://www.chriscowdery.com/?p=149</guid>
		<description><![CDATA[Goal: Design and implement an algorithm to detect certain hands in a game of Poker. You are given your parameters as 5 ints [0-13] representing each value of the card. The hands to check are:

Four of a kind (ex: 5,4,5,5,5)
Full house (ex: 5,4,4,5,5)
Three of a kind (ex: 5,4,5,5,1)
Two pair (ex: 8,4,4,5,5)
Pair (ex: 7,1,2,5,5)
High card (ex: [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Goal:</strong> Design and implement an algorithm to detect certain hands in a game of Poker. You are given your parameters as 5 ints [0-13] representing each value of the card. The hands to check are:</p>
<ul>
<li>Four of a kind (ex: 5,4,5,5,5)</li>
<li>Full house (ex: 5,4,4,5,5)</li>
<li>Three of a kind (ex: 5,4,5,5,1)</li>
<li>Two pair (ex: 8,4,4,5,5)</li>
<li>Pair (ex: 7,1,2,5,5)</li>
<li>High card (ex: 1,2,3,4,5)</li>
</ul>
<p><strong>Constraints:</strong></p>
<ul>
<li>Return the String value or enum code (to your specification) representing each case</li>
</ul>
<p><strong>Hmmm of the day:</strong> Are there any poker hands which could fall into more than one category?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chriscowdery.com/posts/149/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Coding Kata – January 28 2010 &#8211; Crazy List Copying</title>
		<link>http://www.chriscowdery.com/posts/135</link>
		<comments>http://www.chriscowdery.com/posts/135#comments</comments>
		<pubDate>Thu, 28 Jan 2010 05:53:16 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Kata]]></category>

		<guid isPermaLink="false">http://www.chriscowdery.com/?p=135</guid>
		<description><![CDATA[Goal: Create a duplicate copy of a linked list given the following facts about the linked list:

Each node in the list has a pointer to the next element in the list, or null if no element is present
Each node in the list has a data pointer which points to any arbitrary node in the list

Constraints:

You [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Goal:</strong> Create a duplicate copy of a linked list given the following facts about the linked list:</p>
<ul>
<li>Each node in the list has a pointer to the next element in the list, or null if no element is present</li>
<li>Each node in the list has a data pointer which points to <em>any</em> arbitrary node in the list</li>
</ul>
<p><strong>Constraints:</strong></p>
<ul>
<li>You are allowed to modify the list, so long as it is returned to its original state</li>
</ul>
<p><strong>Example: </strong><br />
<a href="http://www.chriscowdery.com/?attachment_id=139" rel="attachment wp-att-139"><img src="http://www.chriscowdery.com/wp-content/uploads/2010/01/crazylist1.png" alt="" title="crazylist" width="379" height="446" class="alignnone size-full wp-image-139" /></a></p>
<p><strong>Hmmm of the day:</strong> Can this be solved using pointer arithmetic, and if so, is it the most efficient solution?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chriscowdery.com/posts/135/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coding Kata &#8211; January 27 2010 &#8211; The Ski Lift</title>
		<link>http://www.chriscowdery.com/posts/133</link>
		<comments>http://www.chriscowdery.com/posts/133#comments</comments>
		<pubDate>Wed, 27 Jan 2010 06:23:13 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Kata]]></category>

		<guid isPermaLink="false">http://www.chriscowdery.com/?p=133</guid>
		<description><![CDATA[Goal: Create an algorithm to determine how close you are to the summit of a mountain (percentage) whilst on a chairlift. You know the following information:

What chair you are on
The chair coming in the opposite direction visible to your left at the current time

At what point do you have an accurate estimate of your progress? [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Goal:</strong> Create an algorithm to determine how close you are to the summit of a mountain (percentage) whilst on a <a href="http://en.wikipedia.org/wiki/Chairlift">chairlift</a>. You know the following information:</p>
<ul>
<li>What chair you are on</li>
<li>The chair coming in the opposite direction visible to your left at the current time</li>
</ul>
<p>At what point do you have an accurate estimate of your progress? When you are at that point, what is your percentage progress to the top?</p>
<p><strong>Constraints:</strong> You are not given the number of chairs on the chairlift.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chriscowdery.com/posts/133/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coding Kata – January 26 2010</title>
		<link>http://www.chriscowdery.com/posts/131</link>
		<comments>http://www.chriscowdery.com/posts/131#comments</comments>
		<pubDate>Tue, 26 Jan 2010 05:16:59 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Kata]]></category>

		<guid isPermaLink="false">http://www.chriscowdery.com/?p=131</guid>
		<description><![CDATA[Goal: Create code to rotate an N by N array 90 degrees clockwise.
Constraints: All manipulations must be made to the original array, but a single staging variable can be used.
Hmmm of the day: Can this be done for N by M arrays as well? If so, how? If not, why not?
]]></description>
			<content:encoded><![CDATA[<p><strong>Goal:</strong> Create code to rotate an N by N array 90 degrees clockwise.</p>
<p><strong>Constraints:</strong> All manipulations must be made to the original array, but a single staging variable can be used.</p>
<p><strong>Hmmm of the day:</strong> Can this be done for N by M arrays as well? If so, how? If not, why not?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chriscowdery.com/posts/131/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coding Kata &#8211; January 25 2010</title>
		<link>http://www.chriscowdery.com/posts/125</link>
		<comments>http://www.chriscowdery.com/posts/125#comments</comments>
		<pubDate>Mon, 25 Jan 2010 06:31:16 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Kata]]></category>

		<guid isPermaLink="false">http://www.chriscowdery.com/?p=125</guid>
		<description><![CDATA[Goal: Design a data structure and controller to model a Connect Four game.
Your controller must have two functions, putPiece and checkForWin (using any parameters you choose).
Constraints: Your checkForWin method should be relatively efficient (i.e. it can&#8217;t have O(n2) efficiency). Think you can do it in O(n)? How about O(1)?
Hmmm of the day: The most efficient [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Goal:</strong> Design a data structure and controller to model a <a href="http://en.wikipedia.org/wiki/Connect_Four">Connect Four</a> game.<br />
Your controller must have two functions, putPiece and checkForWin (using any parameters you choose).</p>
<p><strong>Constraints:</strong> Your checkForWin method should be relatively efficient (i.e. it can&#8217;t have O(n<sup>2</sup>) efficiency). Think you can do it in O(n)? How about O(1)?</p>
<p><strong>Hmmm of the day: </strong>The most efficient way to put a piece may seem a little &#8216;backwards&#8217; at first.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chriscowdery.com/posts/125/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Coding Kata</title>
		<link>http://www.chriscowdery.com/posts/119</link>
		<comments>http://www.chriscowdery.com/posts/119#comments</comments>
		<pubDate>Mon, 25 Jan 2010 06:24:16 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Kata]]></category>

		<guid isPermaLink="false">http://www.chriscowdery.com/?p=119</guid>
		<description><![CDATA[Ever write code that looks like this?

If you&#8217;re saying no, then you&#8217;re either a legend or you might have some delusions of grandeur &#8211; but in any case a little practice never hurt anybody. I&#8217;ve decided to keep my skills fresh, I&#8217;m going to try and create (and tackle) a new problem every day, and [...]]]></description>
			<content:encoded><![CDATA[<p>Ever write code that looks like this?</p>
<p><img src="http://www.chriscowdery.com/wp-content/uploads/2010/01/dari.jpg" alt="thatll_work" title="thatll_work" width="500" height="347" class="alignnone size-full wp-image-120" /></p>
<p>If you&#8217;re saying no, then you&#8217;re either a legend or you might have some delusions of grandeur &#8211; but in any case a little practice <em>never</em> hurt anybody. I&#8217;ve decided to keep my skills fresh, I&#8217;m going to try and create (and tackle) a new problem every day, and I&#8217;d like to share them with the rest of the world so that you might benefit as well. </p>
<p>This concept is by no means new, and I encourage you to check out <a href="http://codekata.pragprog.com">Dave Thomas&#8217; Coding Kata</a>, which is the earliest example of Coding Kata I can find. I really like the concept, but unfortunately the site is no longer maintained, so I&#8217;d like to pick up the torch and carry on from where Dave left off.</p>
<p>Some of them you may have come across some of before, but I&#8217;ll try to keep them as fresh as possible. I&#8217;ll also post the answer in the comments the next day for those who are interested. Karma points to whoever gets it first before that though <img src='http://www.chriscowdery.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.chriscowdery.com/posts/119/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Man in the middle design</title>
		<link>http://www.chriscowdery.com/posts/10</link>
		<comments>http://www.chriscowdery.com/posts/10#comments</comments>
		<pubDate>Tue, 03 Nov 2009 05:18:55 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Process]]></category>
		<category><![CDATA[Software Design]]></category>

		<guid isPermaLink="false">http://www.chriscowdery.com/?p=10</guid>
		<description><![CDATA[I used to always be a relentless top-down developer. I deduced that it simply was the best way to go &#8211; once you create the interface the client wants, you have a better understanding of the requirements and can get feedback right away which would help cut down potential changes in architecture mid-project. Bottom-up projects [...]]]></description>
			<content:encoded><![CDATA[<p>I used to always be a relentless top-down developer. I deduced that it simply was the best way to go &#8211; once you create the interface the client wants, you have a better understanding of the requirements and can get feedback <em>right away</em> which would help cut down potential changes in architecture mid-project. Bottom-up projects often suffered costly redesigns as the client would change their minds after seeing the product and in some cases I&#8217;d have to re-invent the wheel again.. and again. After being scarred too many times, I switched over to a top-down philosophy for my app development, and have been doing it for several years now.</p>
<p>The procedure was more or less the same for every project. I would create my user interface in Photoshop and slice it up (or if I&#8217;m feeling exceptionally keen, straight to the code), and then piece by piece I would snap little bits of interface together to form an overall gestalt. After many refinements and tweakings, I&#8217;d prepare a demo and portfolio for my client and showcase the new interface. If all went well, I&#8217;d begin design of my Controller and Model components from then on, giddy with satisfaction that the client liked the demo.</p>
<p>But that&#8217;s when the honeymoon period starts to end. Quickly.</p>
<p>The app now has all these lofty requirements and proposed features, and there&#8217;s a substantial chasm between the various elements. Solutions pop into your head on how to connect them, some more eloquent than others, but invariably the initial solution isn&#8217;t as clean-cut as you&#8217;d like it to be. Several pads of paper and pots of coffee later, a nice design emerges for your Controller and you swiftly bind all the GUI elements to their proposed functions. Life is good. But then there&#8217;s the Model&#8230;</p>
<p><img class="alignnone size-full wp-image-11" title="Travis-cavingunderpressure" src="http://www.chriscowdery.com/wp-content/uploads/2009/11/Travis-cavingunderpressure.jpg" alt="Travis-cavingunderpressure" width="500" height="375" /></p>
<p>After slewing through the Model, and getting that last unit test to pass, you finally have first release candidate to show to the client. You&#8217;re pleased with yourself, glad that you pulled it off and you&#8217;re happy with the results, and the client is too. The client then pulls you aside afterwards and was wondering what happened in the past few weeks. Despite the fact that you told them it was going to take a while to &#8216;do the plumbing&#8217; to connect everything, they expected something working earlier than this, after all &#8211; they saw an interface with everything they wanted to see on it! How hard could it possibly be?</p>
<p>Time after time I find that this approach suffers from the <a href="http://www.joelonsoftware.com/articles/fog0000000356.html">Iceberg Effect</a>, in addition to the dangerous waters you have to navigate through to avoid a Frankenstein app and other anti-patterns. I assumed it was the best way to go about doing things (for me) despite it&#8217;s shortcomings, and I continued on my merry little way&#8230; until this weekend.</p>
<p><strong>What if</strong> you didn&#8217;t start with the View, or even the Model &#8211; and just went <em>straight</em> to the Controller. This way you could start on an app which knew from the ground up the best ways to interact with the Model and also the best ways to interact with the View.</p>
<p>The most <em>essential</em> moment in the development of an application I believe is when you realize how the users intent can be fulfilled, and since this is predominately Controller logic anyway, you&#8217;ve basically got the app in the bag. Here are a few pros to this approach:</p>
<ul>
<li>You can construct a modular Controller around the <em>users actions</em> and not the <em>nitpicky needs of the app infrastructure</em></li>
<li>You still have an understanding of what functionality the user will be able to use in the View</li>
<li>You don&#8217;t need to make any compromises with the design of your model</li>
<li>You won&#8217;t be a victim to the Iceberg Effect</li>
<li>Can construct unit tests right away for Test Driven Development</li>
<li>Less likely to paint yourself into a corner since you know the app&#8217;s logic and constraints up-front</li>
<li>You and the client have reasonably high visibility on the project</li>
</ul>
<p>No methodology would be complete without it&#8217;s drawbacks though. Here&#8217;s a few which I think can come into play:</p>
<ul>
<li>Longer delay in getting the interface ready means that there could be a small back-and-forth between Controller and View handshaking if the client makes repeated changes</li>
<li>More time needed up-front to flush out the design</li>
</ul>
<p>So what do you think? Is this a steaming pile of balderdash, or do you think it&#8217;s a happy compromise in this day and age of app development? I will be trying it on my next project, and I&#8217;ll keep you posted with the results.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chriscowdery.com/posts/10/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
