<?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>Boy Plankton</title>
	<atom:link href="http://www.boyplankton.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.boyplankton.com</link>
	<description>Stuff that interests me.</description>
	<lastBuildDate>Sun, 17 Apr 2011 23:59:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Deadpool 35</title>
		<link>http://www.boyplankton.com/2011/04/17/deadpool-35/</link>
		<comments>http://www.boyplankton.com/2011/04/17/deadpool-35/#comments</comments>
		<pubDate>Sun, 17 Apr 2011 23:59:02 +0000</pubDate>
		<dc:creator>vince</dc:creator>
				<category><![CDATA[Comics]]></category>
		<category><![CDATA[Deadpool]]></category>

		<guid isPermaLink="false">http://www.boyplankton.com/?p=16</guid>
		<description><![CDATA[I love the cover art for Deadpool 35.  The story &#8230; not so much.  I&#8217;m really glad that the Space Oddity storyline is over.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.boyplankton.com/wp-content/uploads/2011/04/6120944-deadpool-35.jpg"><img class="alignleft size-medium wp-image-17" title="Deadpool 35 Cover " src="http://www.boyplankton.com/wp-content/uploads/2011/04/6120944-deadpool-35-197x300.jpg" alt="" width="197" height="300" /></a>I love the cover art for Deadpool 35.  The story &#8230; not so much.  I&#8217;m really glad that the Space Oddity storyline is over.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.boyplankton.com/2011/04/17/deadpool-35/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My solution &#8230;</title>
		<link>http://www.boyplankton.com/2011/04/10/my-solution/</link>
		<comments>http://www.boyplankton.com/2011/04/10/my-solution/#comments</comments>
		<pubDate>Sun, 10 Apr 2011 23:13:57 +0000</pubDate>
		<dc:creator>vince</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Seven Languages in Seven Weeks]]></category>

		<guid isPermaLink="false">http://www.boyplankton.com/?p=13</guid>
		<description><![CDATA[Haskell is an interesting language.  Forces you to break the problem up into small pieces.  Haskell is the seventh language featured in Seven Languages in Seven Weeks and the fifth problem for day 1 of Haskell has kept me stumped for a couple of days now.  You are expected to write a Haskell version of the&#8230;]]></description>
			<content:encoded><![CDATA[<p>Haskell is an interesting language.  Forces you to break the problem up into small pieces.  Haskell is the seventh language featured in <a href="http://pragprog.com/titles/btlang/seven-languages-in-seven-weeks">Seven Languages in Seven Weeks</a> and the fifth problem for day 1 of Haskell has kept me stumped for a couple of days now.  You are expected to write a Haskell version of the map-coloring problem from the Prolog chapter.</p>
<p>You are given a map of the southeast corner of the United States.  You have to write a program to color the five states so that no two states that border each other are colored the same.</p>
<p>First you have to setup the problem.</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">states <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;Tennessee&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;Mississippi&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;Alabama&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;Georgia&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;Florida&quot;</span> <span style="color: green;">&#93;</span>
&nbsp;
borders <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span> <span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;Mississippi&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;Tennessee&quot;</span> <span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;Mississippi&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;Alabama&quot;</span> <span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;Alabama&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;Tennessee&quot;</span> <span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;Alabama&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;Mississippi&quot;</span> <span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;Alabama&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;Georgia&quot;</span> <span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;Alabama&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;Florida&quot;</span> <span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;Georgia&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;Florida&quot;</span> <span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;Georgia&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;Tennessee&quot;</span> <span style="color: green;">&#93;</span> <span style="color: green;">&#93;</span>
&nbsp;
colors <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;red&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;green&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;blue&quot;</span> <span style="color: green;">&#93;</span></pre></div></div>

<p>This is a quick function to get a list of the states that border one of the states.</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">getBorders y <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span> <span style="font-weight: bold;">last</span> x <span style="color: #339933; font-weight: bold;">|</span> x &amp;lt;<span style="color: #339933; font-weight: bold;">-</span> borders<span style="color: #339933; font-weight: bold;">,</span> <span style="font-weight: bold;">head</span> x <span style="color: #339933; font-weight: bold;">==</span> y <span style="color: green;">&#93;</span></pre></div></div>

<p>I needed a list of the colors of bordering states that had already been assigned colors.</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">getBorderColors y z <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span> <span style="font-weight: bold;">last</span> x <span style="color: #339933; font-weight: bold;">|</span> x &amp;lt;<span style="color: #339933; font-weight: bold;">-</span> y<span style="color: #339933; font-weight: bold;">,</span> <span style="font-weight: bold;">any</span> <span style="color: green;">&#40;</span> <span style="color: #339933; font-weight: bold;">==</span> <span style="font-weight: bold;">head</span> x <span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span> getBorders z <span style="color: green;">&#41;</span> <span style="color: green;">&#93;</span></pre></div></div>

<p>This function takes a list of colors and figures out which colors are still available for a state.</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">colorsLeft <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#91;</span><span style="color: green;">&#91;</span><span style="color: #cccc00; font-weight: bold;">Char</span><span style="color: green;">&#93;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-</span>&amp;gt; <span style="color: green;">&#91;</span><span style="color: green;">&#91;</span><span style="color: #cccc00; font-weight: bold;">Char</span><span style="color: green;">&#93;</span><span style="color: green;">&#93;</span>
colorsLeft <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">=</span> colors
colorsLeft <span style="color: green;">&#40;</span>x:xs<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span> y <span style="color: #339933; font-weight: bold;">|</span> y &amp;lt;<span style="color: #339933; font-weight: bold;">-</span> colorsLeft xs<span style="color: #339933; font-weight: bold;">,</span> x <span style="color: #339933; font-weight: bold;">/=</span> y <span style="color: green;">&#93;</span></pre></div></div>

<p>Finally, we iterate through the list of states and assign them colors.</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">mapColors xs <span style="color: #339933; font-weight: bold;">=</span> helper <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> xs
   <span style="color: #06c; font-weight: bold;">where</span> helper sol <span style="color: green;">&#40;</span>x:xs<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> helper <span style="color: green;">&#40;</span><span style="color: green;">&#91;</span> x<span style="color: #339933; font-weight: bold;">,</span> <span style="font-weight: bold;">head</span> <span style="color: green;">&#40;</span> colorsLeft <span style="color: green;">&#40;</span> getBorderColors sol x <span style="color: green;">&#41;</span><span style="color: green;">&#41;</span><span style="color: green;">&#93;</span> : sol <span style="color: green;">&#41;</span> xs
         helper sol <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">=</span> sol</pre></div></div>

<p>Load and execute &#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #339933; font-weight: bold;">*</span>Main<span style="color: #339933; font-weight: bold;">&gt;</span> mapColors states
<span style="color: green;">&#91;</span><span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;Florida&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;red&quot;</span><span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;Georgia&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;green&quot;</span><span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;Alabama&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;blue&quot;</span><span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;Mississippi&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;green&quot;</span><span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;Tennessee&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;red&quot;</span><span style="color: green;">&#93;</span><span style="color: green;">&#93;</span></pre></div></div>

<p>I&#8217;m certain that this solution is less than optimal.  Still, it&#8217;s the first one I came up with that produced the correct answer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.boyplankton.com/2011/04/10/my-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Charlieplexing</title>
		<link>http://www.boyplankton.com/2011/03/21/charlieplexing/</link>
		<comments>http://www.boyplankton.com/2011/03/21/charlieplexing/#comments</comments>
		<pubDate>Mon, 21 Mar 2011 03:08:20 +0000</pubDate>
		<dc:creator>vince</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[msp430]]></category>

		<guid isPermaLink="false">http://www.boyplankton.com/?p=9</guid>
		<description><![CDATA[Charlieplexing is a multiplexing technique for driving LED&#8217;s using fewer IO pins.  You can use it to control N*(N-1) LED&#8217;s where N is the number of IO pins that you are using.  It works because the IO pins on a microcontroller have three available states.  If the pin is set to output then it can&#8230;]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Charlieplexing">Charlieplexing</a> is a multiplexing technique for driving LED&#8217;s using fewer IO pins.  You can use it to control N*(N-1) LED&#8217;s where N is the number of IO pins that you are using.  It works because the IO pins on a microcontroller have three available states.  If the pin is set to output then it can output a 1 or 0.  The third state is input, where the pin is set to high impedance and is effectively disconnected from the circuit.</p>
<p>&nbsp;</p>
<p><a href="http://www.boyplankton.com/wp-content/uploads/2011/03/3_Pin_Charlieplexing.png"><img class="alignleft size-thumbnail wp-image-10" title="3_Pin_Charlieplexing" src="http://www.boyplankton.com/wp-content/uploads/2011/03/3_Pin_Charlieplexing-150x150.png" alt="" width="150" height="150" /></a>This is the example circuit from the Wikipedia entry referenced above.  There are three pins being used to drive six LED&#8217;s.  Two pins have to be set to output, one high and one low, and one pin has to be disconnected from the circuit in order to address an LED.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><a href="http://www.boyplankton.com/wp-content/uploads/2011/03/DSC_5035.jpg"><img class="alignleft size-thumbnail wp-image-11" title="DSC_5035" src="http://www.boyplankton.com/wp-content/uploads/2011/03/DSC_5035-150x150.jpg" alt="" width="150" height="150" /></a>Here is the example circuit on my breadboard.  It&#8217;s being driven by a TI MSP430.</p>
<p>I found that the quickest way to make it work was to set all the pins so that they were inputs, then override the two that I needed as outputs and finally set the one pin that I wanted to output a 1.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.boyplankton.com/2011/03/21/charlieplexing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calculating Distance</title>
		<link>http://www.boyplankton.com/2011/03/20/calculating-distance/</link>
		<comments>http://www.boyplankton.com/2011/03/20/calculating-distance/#comments</comments>
		<pubDate>Sun, 20 Mar 2011 01:07:23 +0000</pubDate>
		<dc:creator>vince</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Haversine]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.boyplankton.com/?p=8</guid>
		<description><![CDATA[The solution for calculating the distance between any two points on a sphere is an equation called the Haversine Formula.  It can be used to estimate the distance between any two points on Earth using their latitude and longitude by making the assumption that the Earth is a perfect sphere.  It isn&#8217;t, but for some&#8230;]]></description>
			<content:encoded><![CDATA[<p>The solution for calculating the distance between any two points on a sphere is an equation called the <a href="http://en.wikipedia.org/wiki/Haversine_formula">Haversine Formula</a>.  It can be used to estimate the distance between any two points on Earth using their latitude and longitude by making the assumption that the Earth is a perfect sphere.  It isn&#8217;t, but for some applications the approximation is good enough.</p>
<p>Here&#8217;s an example calculating the distance of two points using Python:</p>
<style type="text/css">
<!--
.Constant { color: #ffa0a0; }
.Identifier { color: #40ffff; }
.Statement { color: #ffff60; }
-->
</style>
<p></head><br />
<body></p>
<pre>
<span class="Statement">def</span> <span class="Identifier">min</span>( val1, val2 ):
   <span class="Statement">if</span> val1 &gt; val2: <span class="Statement">return</span> val2
   <span class="Statement">else</span>: <span class="Statement">return</span> val1

<span class="Statement">def</span> <span class="Identifier">haversine</span>( lat1, lon1, lat2, lon2 ):
   dlat = math.radians( lat2 - lat1 )
   dlon = math.radians( lon2 - lon1 )
   a = math.sin(dlat/<span class="Constant">2</span>)**<span class="Constant">2</span> + math.cos(math.radians(lat1)) * math.cos(math.radians(lat2)) * math.sin(dlon/<span class="Constant">2</span>)**<span class="Constant">2</span>
   <span class="Statement">return</span> <span class="Constant">2</span>*math.asin(<span class="Identifier">min</span>(<span class="Constant">1</span>,math.sqrt(a)))
</pre>
<p>Calculating the distance between Los Angeles and New York City in kilometers:</p>
<pre>
>>> haversine( 34.05, -118.24, 40.71, -74.00 ) * 6367
3933.5883159892405
</pre>
<p>Same example, miles this time:</p>
<pre>
>>> haversine( 34.05, -118.24, 40.71, -74.00 ) * 3956
2444.0514179446263
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.boyplankton.com/2011/03/20/calculating-distance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

