<?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/"
	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>Programming Praxis</title>
	<atom:link href="http://programmingpraxis.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://programmingpraxis.com</link>
	<description>A collection of etudes, updated weekly, for the education and enjoyment of the savvy programmer</description>
	<lastBuildDate>Sat, 28 Jan 2012 04:35:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='programmingpraxis.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Programming Praxis</title>
		<link>http://programmingpraxis.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://programmingpraxis.com/osd.xml" title="Programming Praxis" />
	<atom:link rel='hub' href='http://programmingpraxis.com/?pushpress=hub'/>
		<item>
		<title>Anagram Phrases</title>
		<link>http://programmingpraxis.com/2012/01/27/anagram-phrases/</link>
		<comments>http://programmingpraxis.com/2012/01/27/anagram-phrases/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 09:00:43 +0000</pubDate>
		<dc:creator>programmingpraxis</dc:creator>
				<category><![CDATA[Exercises]]></category>

		<guid isPermaLink="false">http://programmingpraxis.com/?p=5380</guid>
		<description><![CDATA[Words that are formed from the same set of letters are anagrams of each other. For instance, pots, post, stop, spot, opts, and tops are anagrams. We studied anagrams in a previous exercise. Anagrams can be extended from single words to phrases. For instance, &#8220;gin grammar prop six&#8221; and &#8220;maxim prong rasp rig&#8221; are anagrams [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programmingpraxis.com&amp;blog=6649073&amp;post=5380&amp;subd=programmingpraxis&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Words that are formed from the same set of letters are anagrams of each other. For instance, pots, post, stop, spot, opts, and tops are anagrams. We studied anagrams in a <a href="/2009/04/10/anagrams/">previous exercise</a>.</p>
<p>Anagrams can be extended from single words to phrases. For instance, &#8220;gin grammar prop six&#8221; and &#8220;maxim prong rasp rig&#8221; are anagrams for &#8220;programming praxis.&#8221;</p>
<p>Your task is to write a program to find all the anagram phrases for an input phrase that are present in a given dictionary; show only one permutation of each set of unique words. When you are finished, you are welcome to <a href="/2012/01/27/anagram-phrases/2/">read</a> or <a href="http://programmingpraxis.codepad.org/CBWq8vut">run</a> a suggested solution, or to post your own solution or discuss the exercise in the comments below.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/programmingpraxis.wordpress.com/5380/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/programmingpraxis.wordpress.com/5380/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/programmingpraxis.wordpress.com/5380/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/programmingpraxis.wordpress.com/5380/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/programmingpraxis.wordpress.com/5380/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/programmingpraxis.wordpress.com/5380/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/programmingpraxis.wordpress.com/5380/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/programmingpraxis.wordpress.com/5380/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/programmingpraxis.wordpress.com/5380/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/programmingpraxis.wordpress.com/5380/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/programmingpraxis.wordpress.com/5380/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/programmingpraxis.wordpress.com/5380/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/programmingpraxis.wordpress.com/5380/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/programmingpraxis.wordpress.com/5380/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programmingpraxis.com&amp;blog=6649073&amp;post=5380&amp;subd=programmingpraxis&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://programmingpraxis.com/2012/01/27/anagram-phrases/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">programmingpraxis</media:title>
		</media:content>
	</item>
		<item>
		<title>A Dozen Lines Of Code</title>
		<link>http://programmingpraxis.com/2012/01/24/a-dozen-lines-of-code/</link>
		<comments>http://programmingpraxis.com/2012/01/24/a-dozen-lines-of-code/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 09:00:56 +0000</pubDate>
		<dc:creator>programmingpraxis</dc:creator>
				<category><![CDATA[Exercises]]></category>

		<guid isPermaLink="false">http://programmingpraxis.com/?p=5341</guid>
		<description><![CDATA[Today&#8217;s task will require your imagination and creativity. A high-school programming teacher recently asked for examples of short programs with a high &#8220;cool&#8221; factor, the idea being to get his students interested in programming computers. I&#8217;m not sure the suggestions would work; today&#8217;s high-school students have been surrounded by computers their entire lives, and it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programmingpraxis.com&amp;blog=6649073&amp;post=5341&amp;subd=programmingpraxis&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s task will require your imagination and creativity.</p>
<p>A high-school programming teacher recently <a href="http://stackoverflow.com/questions/811074/what-is-the-coolest-thing-you-can-do-in-10-lines-of-simple-code-help-me-inspir">asked</a> for examples of short programs with a high &#8220;cool&#8221; factor, the idea being to get his students interested in programming computers. I&#8217;m not sure the suggestions would work; today&#8217;s high-school students have been surrounded by computers their entire lives, and it takes a lot to make them think a program is cool. Being from a different generation, I can remember when I thought it was cool that a program properly skipped over the perforation on a stack of green-bar paper &mdash; many programs didn&#8217;t!</p>
<p>Your task is to write a cool program in a dozen lines of code. You can define cool in any way that you wish. Try not to abuse the definition of &#8220;line of code,&#8221; at least not too badly; to be concrete, we will say that your solution must not exceed 12 lines, and each line must not exceed 80 characters including white space. When you are finished, you are welcome to <a href="/2012/01/24/a-dozen-lines-of-code/2/">read</a> or <a href="http://programmingpraxis.codepad.org/soelfszm">run</a> a suggested solution, or to post your own solution or discuss the exercise in the comments below.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/programmingpraxis.wordpress.com/5341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/programmingpraxis.wordpress.com/5341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/programmingpraxis.wordpress.com/5341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/programmingpraxis.wordpress.com/5341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/programmingpraxis.wordpress.com/5341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/programmingpraxis.wordpress.com/5341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/programmingpraxis.wordpress.com/5341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/programmingpraxis.wordpress.com/5341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/programmingpraxis.wordpress.com/5341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/programmingpraxis.wordpress.com/5341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/programmingpraxis.wordpress.com/5341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/programmingpraxis.wordpress.com/5341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/programmingpraxis.wordpress.com/5341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/programmingpraxis.wordpress.com/5341/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programmingpraxis.com&amp;blog=6649073&amp;post=5341&amp;subd=programmingpraxis&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://programmingpraxis.com/2012/01/24/a-dozen-lines-of-code/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">programmingpraxis</media:title>
		</media:content>
	</item>
		<item>
		<title>Knights On A Keypad</title>
		<link>http://programmingpraxis.com/2012/01/20/knights-on-a-keypad/</link>
		<comments>http://programmingpraxis.com/2012/01/20/knights-on-a-keypad/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 09:00:18 +0000</pubDate>
		<dc:creator>programmingpraxis</dc:creator>
				<category><![CDATA[Exercises]]></category>

		<guid isPermaLink="false">http://programmingpraxis.com/?p=5313</guid>
		<description><![CDATA[Today&#8217;s exercise is an interview question that appeared on Stack Overflow a few years ago: The numbers on a telephone keypad are arranged thus: 1 2 3 4 5 6 7 8 9 &#160;&#160;0 Starting from the digit 1, and choosing successive digits as a knight moves in chess, determine how many different paths can [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programmingpraxis.com&amp;blog=6649073&amp;post=5313&amp;subd=programmingpraxis&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s exercise is an interview question that <a href="http://stackoverflow.com/questions/2893470/generate-10-digit-number-using-a-phone-keypad">appeared</a> on Stack Overflow a few years ago:</p>
<blockquote><p>The numbers on a telephone keypad are arranged thus:</p>
<p><code>1 2 3<br />
4 5 6<br />
7 8 9<br />
&nbsp;&nbsp;0</code></p>
<p>Starting from the digit 1, and choosing successive digits as a knight moves in chess, determine how many different paths can be formed of length <em>n</em>. There is no need to make a list of the paths, only to count them.</p>
<p>A knight moves two steps either horizontally or vertically followed by one step in the perpendicular direction; thus, from the digit 1 on the keypad a knight can move to digits 6 or 8, and from the digit 4 on the keypad a knight can move to digits 3, 9 or 0. A path may visit the same digit more than once.</p></blockquote>
<p>Your task is to write a function that determines the number of paths of length <em>n</em> that a knight can trace on a keyboard starting from digit 1. When you are finished, you are welcome to <a href="/2012/01/20/knights-on-a-keypad/2/">read</a> or <a href="http://programmingpraxis.codepad.org/k8lxMxUC">run</a> a suggested solution, or to post your own solution or discuss the exercise in the comments below.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/programmingpraxis.wordpress.com/5313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/programmingpraxis.wordpress.com/5313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/programmingpraxis.wordpress.com/5313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/programmingpraxis.wordpress.com/5313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/programmingpraxis.wordpress.com/5313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/programmingpraxis.wordpress.com/5313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/programmingpraxis.wordpress.com/5313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/programmingpraxis.wordpress.com/5313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/programmingpraxis.wordpress.com/5313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/programmingpraxis.wordpress.com/5313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/programmingpraxis.wordpress.com/5313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/programmingpraxis.wordpress.com/5313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/programmingpraxis.wordpress.com/5313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/programmingpraxis.wordpress.com/5313/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programmingpraxis.com&amp;blog=6649073&amp;post=5313&amp;subd=programmingpraxis&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://programmingpraxis.com/2012/01/20/knights-on-a-keypad/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">programmingpraxis</media:title>
		</media:content>
	</item>
		<item>
		<title>Guess The Number</title>
		<link>http://programmingpraxis.com/2012/01/17/guess-the-number/</link>
		<comments>http://programmingpraxis.com/2012/01/17/guess-the-number/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 09:00:53 +0000</pubDate>
		<dc:creator>programmingpraxis</dc:creator>
				<category><![CDATA[Exercises]]></category>

		<guid isPermaLink="false">http://programmingpraxis.wordpress.com/?p=5334</guid>
		<description><![CDATA[We previously wrote a program to provide small exercises in arithmetic for children just learning their basic facts. Today&#8217;s exercise is similar; it plays a guessing game where children compete against the computer to see which can guess the number faster. Here&#8217;s a sample dialog: Let's play Guess-The-Number! You go first. I am thinking of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programmingpraxis.com&amp;blog=6649073&amp;post=5334&amp;subd=programmingpraxis&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We <a href="/2010/12/31/arithmetic-drill/">previously</a> wrote a program to provide small exercises in arithmetic for children just learning their basic facts. Today&#8217;s exercise is similar; it plays a guessing game where children compete against the computer to see which can guess the number faster. Here&#8217;s a sample dialog:</p>
<blockquote><p><code>Let's play Guess-The-Number!<br />
You go first.<br />
I am thinking of a number from 1 to 100<br />
What is your guess? 38<br />
My number is less than your guess.<br />
What is your next guess? 15<br />
Your guess is less than my number.<br />
What is your next guess? 25<br />
Your guess is less than my number.<br />
What is your next guess? 33<br />
My number is less than your guess.<br />
What is your next guess? 28<br />
Your guess is less than my number.<br />
What is your next guess? 31<br />
Your guess is less than my number.<br />
What is your next guess? 32<br />
You guessed my number 32 in 6 tries!<br />
Now it's my turn.<br />
Think of a number from 1 to 100.<br />
Is your number less than 50? Yes<br />
Is your number less than 25? No<br />
Is your number less than 37? Yes<br />
Is your number less than 31? No<br />
Is your number less than 34? Yes<br />
Is your number less than 32? No<br />
Is your number less than 33? Yes<br />
I guessed your number 32 in 7 tries.<br />
You made less guesses than me.<br />
You win! Congratulations!<br />
Would you like to play again? No<br />
Thanks for playing! Good-bye!</code></p></blockquote>
<p>Your task is to write a program that plays Guess-The-Number; the maximum number in play (100 in the sample dialog) should be a parameter to the program. When you are finished, you are welcome to <a href="/2012/01/17/guess-the-number/2/">read</a> or <a href="http://programmingpraxis.codepad.org/joeEXDmD">run</a> a suggested solution, or to post your own solution or discuss the exercise in the comments below.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/programmingpraxis.wordpress.com/5334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/programmingpraxis.wordpress.com/5334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/programmingpraxis.wordpress.com/5334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/programmingpraxis.wordpress.com/5334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/programmingpraxis.wordpress.com/5334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/programmingpraxis.wordpress.com/5334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/programmingpraxis.wordpress.com/5334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/programmingpraxis.wordpress.com/5334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/programmingpraxis.wordpress.com/5334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/programmingpraxis.wordpress.com/5334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/programmingpraxis.wordpress.com/5334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/programmingpraxis.wordpress.com/5334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/programmingpraxis.wordpress.com/5334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/programmingpraxis.wordpress.com/5334/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programmingpraxis.com&amp;blog=6649073&amp;post=5334&amp;subd=programmingpraxis&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://programmingpraxis.com/2012/01/17/guess-the-number/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">programmingpraxis</media:title>
		</media:content>
	</item>
		<item>
		<title>Excel&#8217;s XIRR Function</title>
		<link>http://programmingpraxis.com/2012/01/13/excels-xirr-function/</link>
		<comments>http://programmingpraxis.com/2012/01/13/excels-xirr-function/#comments</comments>
		<pubDate>Fri, 13 Jan 2012 09:00:06 +0000</pubDate>
		<dc:creator>programmingpraxis</dc:creator>
				<category><![CDATA[Exercises]]></category>

		<guid isPermaLink="false">http://programmingpraxis.com/?p=5311</guid>
		<description><![CDATA[We studied numerical integration in a previous exercise. In today&#8217;s exercise we will look at the inverse operation of numerically calculating a derivative. The function that interests us in today&#8217;s exercise is the XIRR function from Excel, which computes the internal rate of return of a series of cash flows that are not necessarily periodic. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programmingpraxis.com&amp;blog=6649073&amp;post=5311&amp;subd=programmingpraxis&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We studied numerical integration in a <a href="/2010/02/09/numerical-integration/">previous exercise</a>. In today&#8217;s exercise we will look at the inverse operation of numerically calculating a derivative.</p>
<p>The function that interests us in today&#8217;s exercise is the XIRR function from Excel, which computes the internal rate of return of a series of cash flows that are not necessarily periodic. The XIRR function calculates the value of <em>x</em> that makes the following equation go to 0, where <em>p<sub>i</sub></em> is the <em>i</em>th cash flow, <em>d<sub>i</sub></em> is the date of the <em>i</em>th cash flow, and <em>d<sub>0</sub></em> is the date of the first cash flow:</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Csum_i+%5Cfrac%7Bp_i%7D%7B%281%2Bx%29%5E%7B%28d_i-d_0%29%2F365%7D%7D&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='&#92;sum_i &#92;frac{p_i}{(1+x)^{(d_i-d_0)/365}}' title='&#92;sum_i &#92;frac{p_i}{(1+x)^{(d_i-d_0)/365}}' class='latex' /></p>
<p>The method used to estimate <em>x</em> was devised by Sir Isaac Newton about three hundred years ago. If <em>x<sub>n</sub></em> is an approximation to a function, then a better approximation <em>x</em><sub><em>n</em>+1</sub> is given by</p>
<p><img src='http://s0.wp.com/latex.php?latex=x_%7Bn%2B1%7D+%3D+x_n+-+%5Cfrac%7Bf%28x_n%29%7D%7Bf%27%28x_n%29%7D&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='x_{n+1} = x_n - &#92;frac{f(x_n)}{f&#039;(x_n)}' title='x_{n+1} = x_n - &#92;frac{f(x_n)}{f&#039;(x_n)}' class='latex' /></p>
<p>where <em>f</em>&#039;(<em>x<sub>n</sub></em>) is the derivative of <em>f</em> at <em>n</em>. Mathematically, the derivative of a function at a given point is the slope of the tangent line at that point. Arithmetically, we calculate the slope of the tangent line by knowing the value of the function at a point <em>x</em> and a nearby point <em>x</em>+&epsilon;, then using the equation</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cfrac%7Bf%28x%2B%5Cepsilon%29+-+f%28x%29%7D%7B%28x%2B%5Cepsilon%29-x%7D&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='&#92;frac{f(x+&#92;epsilon) - f(x)}{(x+&#92;epsilon)-x}' title='&#92;frac{f(x+&#92;epsilon) - f(x)}{(x+&#92;epsilon)-x}' class='latex' /></p>
<p>to determine the slope of the line. Thus, to find <em>x</em>, pick an initial guess (0.1 or 10% works well for most interest calculations) and iterate until the difference between two successive values is close enough. For example, with payments of -10000, 2750, 4250, 3250, and 2750 on dates 1 Jan 2008, 1 March 2008, 30 October 2008, 15 February 2009, and 1 April 2009, the internal rate of return is 37.3%.</p>
<p>Your task is to write a function that mimics Excel&#8217;s XIRR function. When you are finished, you are welcome to <a href="/2012/01/13/excels-xirr-function/2/">read</a> or <a href="http://programmingpraxis.codepad.org/z12ny3O7">run</a> a suggested solution, or to post your own solution or discuss the exercise in the comments below.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/programmingpraxis.wordpress.com/5311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/programmingpraxis.wordpress.com/5311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/programmingpraxis.wordpress.com/5311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/programmingpraxis.wordpress.com/5311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/programmingpraxis.wordpress.com/5311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/programmingpraxis.wordpress.com/5311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/programmingpraxis.wordpress.com/5311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/programmingpraxis.wordpress.com/5311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/programmingpraxis.wordpress.com/5311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/programmingpraxis.wordpress.com/5311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/programmingpraxis.wordpress.com/5311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/programmingpraxis.wordpress.com/5311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/programmingpraxis.wordpress.com/5311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/programmingpraxis.wordpress.com/5311/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programmingpraxis.com&amp;blog=6649073&amp;post=5311&amp;subd=programmingpraxis&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://programmingpraxis.com/2012/01/13/excels-xirr-function/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">programmingpraxis</media:title>
		</media:content>
	</item>
		<item>
		<title>Thirteen Anagram</title>
		<link>http://programmingpraxis.com/2012/01/10/thirteen-anagram/</link>
		<comments>http://programmingpraxis.com/2012/01/10/thirteen-anagram/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 09:00:04 +0000</pubDate>
		<dc:creator>programmingpraxis</dc:creator>
				<category><![CDATA[Exercises]]></category>

		<guid isPermaLink="false">http://programmingpraxis.com/?p=5302</guid>
		<description><![CDATA[On December 7, 2011, Neil deGrasse Tyson tweeted: Need a distraction today? Not only does 12+1=11+2, but the letters &#8220;twelve plus one&#8221; rearrange to give you &#8220;eleven plus two&#8221; Mitchell Perilstein forwarded that tweet to me and suggested that it would form the basis of an exercise for Programming Praxis. Your task is to write [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programmingpraxis.com&amp;blog=6649073&amp;post=5302&amp;subd=programmingpraxis&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>On December 7, 2011, Neil deGrasse Tyson tweeted:</p>
<blockquote><p>Need a distraction today? Not only does 12+1=11+2, but the letters &#8220;twelve plus one&#8221; rearrange to give you &#8220;eleven plus two&#8221;</p></blockquote>
<p>Mitchell Perilstein forwarded that tweet to me and suggested that it would form the basis of an exercise for Programming Praxis.</p>
<p>Your task is to write a program that finds equations similar to Tyson&#8217;s that form anagrams both in their symbols and in their letters. When you are finished, you are welcome to <a href="/2012/01/10/thirteen-anagram/2/">read</a> or <a href="http://programmingpraxis.codepad.org/WJAZ00em">run</a> a suggested solution, or to post your own solution or discuss the exercise in the comments below.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/programmingpraxis.wordpress.com/5302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/programmingpraxis.wordpress.com/5302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/programmingpraxis.wordpress.com/5302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/programmingpraxis.wordpress.com/5302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/programmingpraxis.wordpress.com/5302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/programmingpraxis.wordpress.com/5302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/programmingpraxis.wordpress.com/5302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/programmingpraxis.wordpress.com/5302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/programmingpraxis.wordpress.com/5302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/programmingpraxis.wordpress.com/5302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/programmingpraxis.wordpress.com/5302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/programmingpraxis.wordpress.com/5302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/programmingpraxis.wordpress.com/5302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/programmingpraxis.wordpress.com/5302/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programmingpraxis.com&amp;blog=6649073&amp;post=5302&amp;subd=programmingpraxis&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://programmingpraxis.com/2012/01/10/thirteen-anagram/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">programmingpraxis</media:title>
		</media:content>
	</item>
		<item>
		<title>Pritchard&#8217;s Wheel Sieve</title>
		<link>http://programmingpraxis.com/2012/01/06/pritchards-wheel-sieve/</link>
		<comments>http://programmingpraxis.com/2012/01/06/pritchards-wheel-sieve/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 09:00:14 +0000</pubDate>
		<dc:creator>programmingpraxis</dc:creator>
				<category><![CDATA[Exercises]]></category>

		<guid isPermaLink="false">http://programmingpraxis.com/?p=5212</guid>
		<description><![CDATA[We have seen several different sieves that enumerate the prime numbers not greater than n due to Eratosthenes, Atkin, Euler and Sundaram. In the 1980s, Paul Pritchard, an Australian mathematician, developed a family of sieve algorithms based on wheels, eventually finding an algorithm with O(n / log log n) time complexity and O(&#8730;n) space complexity. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programmingpraxis.com&amp;blog=6649073&amp;post=5212&amp;subd=programmingpraxis&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We have seen several different sieves that enumerate the prime numbers not greater than <em>n</em> due to <a href="/2009/02/19/sieve-of-eratosthenes/">Eratosthenes</a>, <a href="/2010/02/19/sieve-of-atkin-improved/">Atkin</a>, <a href="/2011/02/25/sieve-of-euler/">Euler</a> and <a href="/2011/10/07/sieve-of-sundaram/">Sundaram</a>. In the 1980s, Paul Pritchard, an Australian mathematician, developed a family of sieve algorithms based on wheels, eventually finding an algorithm with <em>O</em>(<em>n</em> / log log <em>n</em>) time complexity and <em>O</em>(&radic;<em>n</em>) space complexity. We examine a simple version of Pritchard&#8217;s wheel sieve in today&#8217;s exercise.</p>
<p>We begin with some definitions. <em>M<sub>k</sub></em> is the product of the first <em>k</em> primes; for instance, <em>M</em><sub>7</sub>= 2&times;3&times;5&times;7&times;11&times;13&times;17=510510. The totatives of <em>M<sub>k</sub></em> are those numbers from 1 to <em>M<sub>k</sub></em> that are coprime to <em>M<sub>k</sub></em> (that is, they have no factors in common). It is easy to determine the totatives of <em>M<sub>k</sub></em> by sieving: make a list of the integers from 1 to <em>M<sub>k</sub></em>, then for each of the primes that form the product <em>M<sub>k</sub></em>, strike out from the list the prime and all of its multiples; for instance, with <em>M</em><sub>3</sub>=2&times;3&times;5=30, sieving with 2 strikes out 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28 and 30, sieving with 3 strikes out 3, 6, 9, 12, 15, 18, 21, 24, 27, and 30, and sieving with 5 strikes out 5, 10, 15, 20, 25 and 30, leaving the totatives 1, 7, 11, 13, 17, 19, 23 and 29. A factoring wheel <em>W<sub>k</sub></em> contains the gaps between successive totatives, wrapping around at the end; for instance, <em>W</em><sub>3</sub> consists of the gaps 6, 4, 2, 4, 2, 4, 6 and 2, corresponding to the gaps 7&minus;1, 11&minus;7, and so on, ending with 29&minus;23 and 31&minus;29 when the wheel wraps around at the end.</p>
<p>Pritchard&#8217;s wheel sieve uses wheels repeatedly to strike out composite numbers from the sieve. It operates in two phases: a setup phase and a processing loop.</p>
<p>The setup phase first computes a parameter <em>k</em> such that <em>M<sub>k</sub></em> &lt; n / log<sub><em>e</em></sub> n &lt; <em>M</em><sub><em>k</em>+1</sub></em>, then computes the wheel <em>W<sub>k</sub></em> and forms the set <em>S</em> from 1 to <em>n</em> by rolling the <em>W<sub>k</sub></em> wheel. The setup phase also computes the list of <em>m</em> primes not greater than the square root of <em>n</em>.</p>
<p>We compute the primes not greater than 100 as an example. We compute k=2, since 100/log(100) is 21.714724 which is between <em>M</em><sub>2</sub>=6 and <em>M</em><sub>3</sub>=30. The <em>W</em><sub>2</sub> wheel is {4 2} and the set <em>S</em> is {1 5 7 11 13 17 19 23 25 29 31 35 37 41 43 47 49 53 55 59 61 65 67 71 73 77 79 83 85 89 91 95 97}; although there is only one set <em>S</em>, we will refer to this set as <em>S</em><sub>2</sub>, since it is the result of rolling the <em>W</em><sub>2</sub> wheel. Finally, the square root of 100 is 10, and the m=4 primes less than 10 are {2 3 5 7}.</p>
<p>The processing loop iterates from <em>k</em>+1 to <em>m</em>. At each loop we will strike some of the elements of <em>S</em>, reducing <em>S</em> from <em>S</em><sub><em>k</em></sub> to <em>S</em><sub><em>k</em>+1</sub>. Each time through the loop we first identify <em>p</em>, the smallest member of <em>S</em> that is greater than 1, and strike it from the set <em>S</em>. We also strike from <em>S</em> the successive multiples <em>p</em>(<em>s</em>&#039;&minus;<em>s</em>) less than <em>n</em>, where <em>s</em>&#039;&minus;<em>s</em> are the successive gaps in <em>S</em>. Finally, we increment <em>k</em> by 1 and repeat the loop as long as <em>k</em>&le;<em>m</em>.</p>
<p>In our example computing the primes not greater than 100, <em>i</em> will take the values 3 and 4. The first time through the loop, <em>p</em> = 5, the gaps are 5&minus;1=4, 7&minus;5=2, 11&minus;7=4, 13&minus;11=2, 17&minus;13=4 and 19&minus;17=2, and the numbers that are stricken are 5, 5+4&times;5=25, 25+2&times;5=35, 35+4&times;5=55, 55+2&times;5=65, 65+4&times;5=85, and 85+2&times;5=95, leaving <em>S</em><sub>3</sub> = {1 7 11 13 17 19 23 29 31 37 41 43 47 49 53 59 61 67 71 73 77 79 83 89 91 97}. The second time through the loop, <em>p</em> = 7, the gaps are 7&minus;1=6, 11&minus;7=4, 13&minus;11=6, 17&minus;13=4, and 19&minus;17=2, and the numbers that are stricken are 7, 7+6&times;7=49, 49+4&times;7=77, and 77+2&times;7=91, leaving <em>S</em><sub>4</sub> = {1 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97}.</p>
<p>Once <em>k</em>&gt;<em>m</em> and the final <em>S</em> has been computed, the list of primes is returned, consisting of the primes less than the square root of <em>n</em> followed by the elements of <em>S</em> excluding 1. Thus the primes not greater than 100 are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89 and 97.</p>
<p>This version of Pritchard&#8217;s sieve has time complexity and space complexity both equal to <em>O</em>(<em>n</em>), where the standard sieve of Eratosthenes has time complexity <em>O</em>(<em>n</em> log log <em>n</em>). The improvement comes from the fact that Pritchard&#8217;s sieve strikes each composite only once, whereas Eratosthenes&#8217; sieve strikes each composite once for each of its distinct prime factors; for instance, Eratosthenes&#8217; sieve strike 15 twice, one for the factor of 3 and once for the factor of 5. But despite the improvement in the asymptotic complexity, Eratosthenes&#8217; sieve is fast because its inner loop consists only of addition, while Pritchard&#8217;s sieve is slower because its inner loop consists of a subtraction to compute the gap in the wheel, a multiplication to extend that gap by the current sieving prime, and an addition to add the gap to the previously-stricken element. Thus, in practice, Eratosthenes&#8217; sieve is faster than Pritchard&#8217;s.</p>
<p>Your task is to write a program to compute the primes not greater than <em>n</em> using Pritchard&#8217;s wheel sieve. When you are finished, you are welcome to <a href="/2012/01/06/pritchards-wheel-sieve/2/">read</a> or <a href="http://programmingpraxis.codepad.org/22VkAlSX">run</a> a suggested solution, or to post your own solution or discuss the exercise in the comments below.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/programmingpraxis.wordpress.com/5212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/programmingpraxis.wordpress.com/5212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/programmingpraxis.wordpress.com/5212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/programmingpraxis.wordpress.com/5212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/programmingpraxis.wordpress.com/5212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/programmingpraxis.wordpress.com/5212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/programmingpraxis.wordpress.com/5212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/programmingpraxis.wordpress.com/5212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/programmingpraxis.wordpress.com/5212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/programmingpraxis.wordpress.com/5212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/programmingpraxis.wordpress.com/5212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/programmingpraxis.wordpress.com/5212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/programmingpraxis.wordpress.com/5212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/programmingpraxis.wordpress.com/5212/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programmingpraxis.com&amp;blog=6649073&amp;post=5212&amp;subd=programmingpraxis&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://programmingpraxis.com/2012/01/06/pritchards-wheel-sieve/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">programmingpraxis</media:title>
		</media:content>
	</item>
		<item>
		<title>Turtle Graphics</title>
		<link>http://programmingpraxis.com/2012/01/03/turtle-graphics/</link>
		<comments>http://programmingpraxis.com/2012/01/03/turtle-graphics/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 09:00:50 +0000</pubDate>
		<dc:creator>programmingpraxis</dc:creator>
				<category><![CDATA[Exercises]]></category>

		<guid isPermaLink="false">http://programmingpraxis.com/?p=5278</guid>
		<description><![CDATA[We had fun drawing a fractal snowflake last week. In today&#8217;s exercise, we will write a full library for turtle graphics. Our goal is to provide the commands described in Brian Harvey&#8217;s book about Logo. The turtle is a robotic device that moves and draws on a graphical output device (paper, screen) with a coordinate [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programmingpraxis.com&amp;blog=6649073&amp;post=5278&amp;subd=programmingpraxis&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img src="http://programmingpraxis.files.wordpress.com/2011/12/tree.jpg?w=640" align="right" width="30%" />We had fun drawing a fractal snowflake <a href="/2011/12/23/kochs-snowflake/">last week</a>. In today&#8217;s exercise, we will write a full library for turtle graphics. Our goal is to provide the commands <a href="http://www.cs.berkeley.edu/~bh/v1ch10/turtle.html">described</a> in Brian Harvey&#8217;s book about Logo. The turtle is a robotic device that moves and draws on a graphical output device (paper, screen) with a coordinate system that has <em>x</em> running west (negative) to east (positive) and <em>y</em> running south (negative) to north (positive); the ordinal compass points are 0 north, 90 east, 180 south and 270 west. Most commands ignore the global coordinate system in favor of commands from the turtle&#8217;s point of view, so instead of saying &#8220;turn to 135 degrees&#8221; a typical command is &#8220;turn right 45 degrees,&#8221; so that a shape can be drawn without knowledge of its global coordinates. The turtle commands are:</p>
<blockquote><p><code>clearscreen</code> &mdash; initialize the graphics system and place the turtle in the center of the graphical output pointing north</p>
<p><code>penup</code> &mdash; remove the pen from the drawing surface</p>
<p><code>pendown</code> &mdash; place the pen on the drawing surface</p>
<p><code>forward</code> <em>n</em> &mdash; move the turtle forward <em>n</em> steps, drawing a line if the pen is down</p>
<p><code>back</code> <em>n</em> &mdash; move the turtle back <em>n</em> steps, drawing a line if the pen is down</p>
<p><code>left</code> <em>n</em> &mdash; rotate the turtle <em>n</em> degrees left from its current heading</p>
<p><code>right</code> <em>n</em> &mdash; rotate the turtle <em>n</em> degrees right from its current heading</p>
<p><code>setpos</code> <em>x</em> <em>y</em> &mdash; move the turtle from its current position to the indicated coordinates, drawing a line if the pen is down</p>
<p><code>setheading</code> <em>n</em> &mdash; rotate the turtle from its current heading to the indicated heading</p>
<p><code>pos</code> &mdash; report the current position by its <em>x</em> and <em>y</em> coordinates</p>
<p><code>heading</code> &mdash; report the current heading in degrees</p></blockquote>
<p>Your task is to write a turtle graphics library. When you are finished, you are welcome to <a href="/2012/01/03/turtle-graphics/2/">read</a> or <a href="http://programmingpraxis.codepad.org/cX7wPlQa">run</a> a suggested solution, or to post your own solution or discuss the exercise in the comments below.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/programmingpraxis.wordpress.com/5278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/programmingpraxis.wordpress.com/5278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/programmingpraxis.wordpress.com/5278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/programmingpraxis.wordpress.com/5278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/programmingpraxis.wordpress.com/5278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/programmingpraxis.wordpress.com/5278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/programmingpraxis.wordpress.com/5278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/programmingpraxis.wordpress.com/5278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/programmingpraxis.wordpress.com/5278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/programmingpraxis.wordpress.com/5278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/programmingpraxis.wordpress.com/5278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/programmingpraxis.wordpress.com/5278/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/programmingpraxis.wordpress.com/5278/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/programmingpraxis.wordpress.com/5278/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programmingpraxis.com&amp;blog=6649073&amp;post=5278&amp;subd=programmingpraxis&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://programmingpraxis.com/2012/01/03/turtle-graphics/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">programmingpraxis</media:title>
		</media:content>

		<media:content url="http://programmingpraxis.files.wordpress.com/2011/12/tree.jpg" medium="image" />
	</item>
		<item>
		<title>Split</title>
		<link>http://programmingpraxis.com/2011/12/30/split/</link>
		<comments>http://programmingpraxis.com/2011/12/30/split/#comments</comments>
		<pubDate>Fri, 30 Dec 2011 09:00:30 +0000</pubDate>
		<dc:creator>programmingpraxis</dc:creator>
				<category><![CDATA[Exercises]]></category>

		<guid isPermaLink="false">http://programmingpraxis.com/?p=5234</guid>
		<description><![CDATA[Today&#8217;s exercise comes from our file of interview questions: Given a list, return the first half of the list as one list and the second half of the list as a second list. For instance, given the input list {1 2 3 4}, output the two lists {1 2} and {3 4}. If the input [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programmingpraxis.com&amp;blog=6649073&amp;post=5234&amp;subd=programmingpraxis&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s exercise comes from our file of interview questions:</p>
<blockquote><p>Given a list, return the first half of the list as one list and the second half of the list as a second list. For instance, given the input list {1 2 3 4}, output the two lists {1 2} and {3 4}. If the input list has an odd number of items, the middle item can go to either list, so that the input list {1 2 3 4 5} can result in the output lists {1 2} and {3 4 5} or the output lists {1 2 3} and {4 5}.</p></blockquote>
<p>Your task is to write the function that splits a list in two halves. When you are finished, you are welcome to <a href="/2011/12/30/split/2/">read</a> or <a href="http://programmingpraxis.codepad.org/jwHWMEXX">run</a> a suggested solution, or to post your own solution or discuss the exercise in the comments below.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/programmingpraxis.wordpress.com/5234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/programmingpraxis.wordpress.com/5234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/programmingpraxis.wordpress.com/5234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/programmingpraxis.wordpress.com/5234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/programmingpraxis.wordpress.com/5234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/programmingpraxis.wordpress.com/5234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/programmingpraxis.wordpress.com/5234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/programmingpraxis.wordpress.com/5234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/programmingpraxis.wordpress.com/5234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/programmingpraxis.wordpress.com/5234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/programmingpraxis.wordpress.com/5234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/programmingpraxis.wordpress.com/5234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/programmingpraxis.wordpress.com/5234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/programmingpraxis.wordpress.com/5234/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programmingpraxis.com&amp;blog=6649073&amp;post=5234&amp;subd=programmingpraxis&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://programmingpraxis.com/2011/12/30/split/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">programmingpraxis</media:title>
		</media:content>
	</item>
		<item>
		<title>Cheating Hangman</title>
		<link>http://programmingpraxis.com/2011/12/27/cheating-hangman/</link>
		<comments>http://programmingpraxis.com/2011/12/27/cheating-hangman/#comments</comments>
		<pubDate>Tue, 27 Dec 2011 09:00:02 +0000</pubDate>
		<dc:creator>programmingpraxis</dc:creator>
				<category><![CDATA[Exercises]]></category>

		<guid isPermaLink="false">http://programmingpraxis.com/?p=5270</guid>
		<description><![CDATA[We have a tradition here at Programming Praxis of celebrating milestones by having a party, and parties require games. Today, for our three-hundredth exercise we will write a cheating version of the hangman from a previous exercise. The idea is simple. Instead of choosing a single answer at the beginning of the game, choose a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programmingpraxis.com&amp;blog=6649073&amp;post=5270&amp;subd=programmingpraxis&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We have a tradition here at Programming Praxis of celebrating milestones by having a party, and parties require games. Today, for our three-hundredth exercise we will write a cheating version of the hangman from a <a href="/2011/12/20/hangman/">previous exercise</a>.</p>
<p>The idea is simple. Instead of choosing a single answer at the beginning of the game, choose a length, and make a list of all possible answers. Each time the player guesses a letter, delete as few words from the possible-answer list as possible consistent with the guesses the player has made; most of the time another body part will be added to the gibbet.</p>
<p>Your task is to write a referee for the game of cheating hangman. When you are finished, you are welcome to <a href="/2011/12/27/cheating-hangman/2/">read</a> or <a href="http://programmingpraxis.codepad.org/i2SJ4FcT">run</a> a suggested solution, or to post your own solution or discuss the exercise in the comments below.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/programmingpraxis.wordpress.com/5270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/programmingpraxis.wordpress.com/5270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/programmingpraxis.wordpress.com/5270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/programmingpraxis.wordpress.com/5270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/programmingpraxis.wordpress.com/5270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/programmingpraxis.wordpress.com/5270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/programmingpraxis.wordpress.com/5270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/programmingpraxis.wordpress.com/5270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/programmingpraxis.wordpress.com/5270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/programmingpraxis.wordpress.com/5270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/programmingpraxis.wordpress.com/5270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/programmingpraxis.wordpress.com/5270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/programmingpraxis.wordpress.com/5270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/programmingpraxis.wordpress.com/5270/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=programmingpraxis.com&amp;blog=6649073&amp;post=5270&amp;subd=programmingpraxis&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://programmingpraxis.com/2011/12/27/cheating-hangman/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">programmingpraxis</media:title>
		</media:content>
	</item>
	</channel>
</rss>
