<?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>Matt Bowcock // mbowcock.com &#187; notebook</title>
	<atom:link href="http://www.mbowcock.com/category/notebook/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mbowcock.com</link>
	<description></description>
	<lastBuildDate>Wed, 21 Oct 2009 18:21:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Project Euler Problem 3 in Scheme</title>
		<link>http://www.mbowcock.com/notebook/project-euler-problem-3-in-scheme/</link>
		<comments>http://www.mbowcock.com/notebook/project-euler-problem-3-in-scheme/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 18:21:54 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[notebook]]></category>
		<category><![CDATA[project euler]]></category>

		<guid isPermaLink="false">http://www.mbowcock.com/?p=114</guid>
		<description><![CDATA[Since I&#8217;m working my way through SICP I ended up using some of the code from the examples in section 1.2.6 to search for prime numbers.  Six of the eight functions below are used to test if a number is prime.  (next-prime &#8230;) just starts at the current prime number and iterate upward [...]]]></description>
			<content:encoded><![CDATA[<p>Since I&#8217;m working my way through SICP I ended up using some of the code from the examples in section 1.2.6 to search for prime numbers.  Six of the eight functions below are used to test if a number is prime.  (next-prime &#8230;) just starts at the current prime number and iterate upward until it finds the next prime number.  (search-for-factors &#8230;) does the actual searching for prime factors.</p>
<pre>
<div class="codesnip-container" >
<div class="lisp codesnip" style="font-family:monospace;"><span class="br0">&#40;</span>define <span class="br0">&#40;</span>smallest-divisor n<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span>find-divisor n 2<span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>divides? a b<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="sy0">=</span> <span class="br0">&#40;</span>remainder b a<span class="br0">&#41;</span> 0<span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>square n<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span>* n n<span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>next-divisor n<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">=</span> n 2<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; 3
&nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>+ n 2<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>find-divisor n test-divisor<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="kw1">cond</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="sy0">&gt;</span> <span class="br0">&#40;</span>square test-divisor<span class="br0">&#41;</span> n<span class="br0">&#41;</span> n<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span><span class="br0">&#40;</span>divides? test-divisor n<span class="br0">&#41;</span> test-divisor<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>else <span class="br0">&#40;</span>find-divisor n <span class="br0">&#40;</span>next-divisor test-divisor<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>prime? n<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="sy0">=</span> n <span class="br0">&#40;</span>smallest-divisor n<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>next-prime n<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="kw1">let</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>m <span class="br0">&#40;</span>+ n 1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; <span class="br0">&#40;</span><span class="kw1">if</span> <span class="br0">&#40;</span>prime? m<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#40;</span>next-prime m<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>search-for-factors n factor<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="kw1">cond</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="sy0">=</span> <span class="br0">&#40;</span>/ n factor<span class="br0">&#41;</span> <span class="nu0">1</span><span class="br0">&#41;</span> <span class="br0">&#40;</span>display factor<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>newline<span class="br0">&#41;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span><span class="br0">&#40;</span>divides? factor n<span class="br0">&#41;</span> <span class="br0">&#40;</span>display factor<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#40;</span>newline<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#40;</span>search-for-factors <span class="br0">&#40;</span>/ n factor<span class="br0">&#41;</span> factor<span class="br0">&#41;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>else <span class="br0">&#40;</span>search-for-factors n <span class="br0">&#40;</span>next-prime factor<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>search-for-factors <span class="nu0">600851475143</span> <span class="nu0">2</span><span class="br0">&#41;</span></div>
</div>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.mbowcock.com/notebook/project-euler-problem-3-in-scheme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SICP Section 1.2.4</title>
		<link>http://www.mbowcock.com/notebook/sicp-1-2/</link>
		<comments>http://www.mbowcock.com/notebook/sicp-1-2/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 02:24:58 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[notebook]]></category>
		<category><![CDATA[sicp]]></category>

		<guid isPermaLink="false">http://www.mbowcock.com/?p=106</guid>
		<description><![CDATA[The code below is exercises 1.16 and 1.17.  I&#8217;ll finish up 1.18 and 1.19 some time in the future.  I&#8217;ve created a repository on github to store the code I write while working through SICP &#8211; if you&#8217;re interested it can be found at http://github.com/mbowcock/SICP.
Exercise 1.16 -


&#40;define &#40;square n&#41;
&#160; &#40;* n n&#41;&#41;

&#40;define &#40;fast-expt-iter [...]]]></description>
			<content:encoded><![CDATA[<p>The code below is exercises 1.16 and 1.17.  I&#8217;ll finish up 1.18 and 1.19 some time in the future.  I&#8217;ve created a repository on github to store the code I write while working through SICP &#8211; if you&#8217;re interested it can be found at <br /><a href="http://github.com/mbowcock/SICP">http://github.com/mbowcock/SICP</a>.</p>
<p>Exercise 1.16 -</p>
<pre>
<div class="codesnip-container" >
<div class="lisp codesnip" style="font-family:monospace;"><span class="br0">&#40;</span>define <span class="br0">&#40;</span>square n<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span>* n n<span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>fast-expt-iter b n a<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="kw1">cond</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="sy0">=</span> n <span class="nu0">0</span><span class="br0">&#41;</span> a<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span><span class="br0">&#40;</span>even? n<span class="br0">&#41;</span> <span class="br0">&#40;</span>fast-expt-iter b <span class="br0">&#40;</span>- n <span class="nu0">2</span><span class="br0">&#41;</span> <span class="br0">&#40;</span>* a <span class="br0">&#40;</span>square b<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>else <span class="br0">&#40;</span>fast-expt-iter b <span class="br0">&#40;</span>- n <span class="nu0">1</span><span class="br0">&#41;</span> <span class="br0">&#40;</span>* a b<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>fast-expt-new b n<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span>fast-expt-iter b n <span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</div>
</pre>
<p>Exercise 1.17 &#8211; </p>
<pre>
<div class="codesnip-container" >
<div class="lisp codesnip" style="font-family:monospace;"><span class="br0">&#40;</span>define <span class="br0">&#40;</span>double n<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span>* n 2<span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>halve n<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span>/ n 2<span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>*<span class="sy0">.</span> a b<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="kw1">cond</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="sy0">=</span> b <span class="nu0">0</span><span class="br0">&#41;</span> <span class="nu0">0</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span><span class="br0">&#40;</span>even? b<span class="br0">&#41;</span> <span class="br0">&#40;</span>*<span class="sy0">.</span> <span class="br0">&#40;</span>double a<span class="br0">&#41;</span> <span class="br0">&#40;</span>halve b<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>else <span class="br0">&#40;</span>+ a <span class="br0">&#40;</span>*<span class="sy0">.</span> a <span class="br0">&#40;</span>- b <span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</div>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.mbowcock.com/notebook/sicp-1-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SICP Problem 1.12</title>
		<link>http://www.mbowcock.com/notebook/sicp-problem-1-12/</link>
		<comments>http://www.mbowcock.com/notebook/sicp-problem-1-12/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 19:20:21 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[notebook]]></category>
		<category><![CDATA[sicp]]></category>

		<guid isPermaLink="false">http://www.mbowcock.com/?p=102</guid>
		<description><![CDATA[Had a little time and got it done quicker than I expected.  Problem 1.12 was to write a procedure to calculate elements of pascals triangle.  I took that to mean calculate the value at position n of a given row.  Take a look -


&#40;define &#40;pascal row n&#41;
&#160; &#40;cond &#40;&#40;&#62; n row&#41; 0&#41;
&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Had a little time and got it done quicker than I expected.  Problem 1.12 was to write a procedure to calculate elements of pascals triangle.  I took that to mean calculate the value at position n of a given row.  Take a look -</p>
<pre>
<div class="codesnip-container" >
<div class="lisp codesnip" style="font-family:monospace;"><span class="br0">&#40;</span>define <span class="br0">&#40;</span>pascal row n<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="kw1">cond</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="sy0">&gt;</span> n row<span class="br0">&#41;</span> 0<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="kw1">or</span> <span class="br0">&#40;</span><span class="sy0">=</span> n <span class="nu0">1</span><span class="br0">&#41;</span> <span class="br0">&#40;</span><span class="sy0">=</span> n row<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="nu0">1</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>else <span class="br0">&#40;</span>+ <span class="br0">&#40;</span>pascal <span class="br0">&#40;</span>- row <span class="nu0">1</span><span class="br0">&#41;</span> n<span class="br0">&#41;</span> <span class="br0">&#40;</span>pascal <span class="br0">&#40;</span>- row <span class="nu0">1</span><span class="br0">&#41;</span> <span class="br0">&#40;</span>- n <span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</div>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.mbowcock.com/notebook/sicp-problem-1-12/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SICP Problem 1.11</title>
		<link>http://www.mbowcock.com/notebook/sicp-problem-1-11/</link>
		<comments>http://www.mbowcock.com/notebook/sicp-problem-1-11/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 18:05:57 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[notebook]]></category>
		<category><![CDATA[sicp]]></category>

		<guid isPermaLink="false">http://www.mbowcock.com/?p=100</guid>
		<description><![CDATA[As I said in a post earlier this week I&#8217;ve begun reading and working on the problems in SICP.  I just read chapter 1 section 2.2 on tree recursion and completed problem 1.11 and plan to do 1.12 and 1.13.  Problem 1.11 was creating recursive and iterative procedures to calculate the following function:
f(n) [...]]]></description>
			<content:encoded><![CDATA[<p>As I said in a post earlier this week I&#8217;ve begun reading and working on the problems in SICP.  I just read chapter 1 section 2.2 on tree recursion and completed problem 1.11 and plan to do 1.12 and 1.13.  Problem 1.11 was creating recursive and iterative procedures to calculate the following function:</p>
<div class="codesnip-container" >f(n) = n if n<3 and f(n) = f(n - 1) + 2f(n - 2) + 3f(n - 3) if n> 3</div>
<p>The recursive function was straight-forward: </p>
<pre>
<div class="codesnip-container" >
<div class="lisp codesnip" style="font-family:monospace;"><span class="br0">&#40;</span>define <span class="br0">&#40;</span>f n<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">&lt;</span> n <span class="nu0">3</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; n
&nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>+ <span class="br0">&#40;</span>f <span class="br0">&#40;</span>- n <span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#40;</span>* <span class="nu0">2</span> <span class="br0">&#40;</span>f <span class="br0">&#40;</span>- n <span class="nu0">2</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#40;</span>* <span class="nu0">3</span> <span class="br0">&#40;</span>f <span class="br0">&#40;</span>- n <span class="nu0">3</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</div>
</pre>
<p>Writing the procedure as an iterative process wasn&#8217;t as trivial.  I initially expected it would be easy and sat down to write the code without really thinking about the problem, but wrapping my head around how to maintain the state needed for 3 function calls didn&#8217;t compute. So I resorted to pencil and paper &#8211; I wrote out the iterations of the function for n=0 through n=5 and the solution became clear: </p>
<pre>
<div class="codesnip-container" >
<div class="lisp codesnip" style="font-family:monospace;"><span class="br0">&#40;</span>define <span class="br0">&#40;</span>f-iter a b c count n<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="kw1">cond</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="sy0">&lt;</span> n <span class="nu0">3</span><span class="br0">&#41;</span> n<span class="br0">&#41;</span>
&nbsp; &nbsp; <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="sy0">=</span> count n<span class="br0">&#41;</span> c<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>else <span class="br0">&#40;</span>f-iter b c <span class="br0">&#40;</span>+ c <span class="br0">&#40;</span>* <span class="nu0">2</span> b<span class="br0">&#41;</span> <span class="br0">&#40;</span>* <span class="nu0">3</span> a<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#40;</span>+ count <span class="nu0">1</span><span class="br0">&#41;</span> n<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp;
<span class="br0">&#40;</span>define <span class="br0">&#40;</span>f2 n<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span>f-iter <span class="nu0">0</span> <span class="nu0">1</span> <span class="nu0">2</span> <span class="nu0">2</span> n<span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</div>
</pre>
<p>As a quick comparison of run-time for the 2 procedures I ran them with the same n value (n=30).  For f(30) (recursive) the procedure took approximately 16 seconds to finish.  For f2(30) (iterative) the procedure finished in less than a second.  I tried higher numbers but the recursive process just takes to long &#8211; I killed the process at 3 minutes when running it for n=35.  I&#8217;ve run the iterative process with n up to 150 and it completes in less than 1 second.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mbowcock.com/notebook/sicp-problem-1-11/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Euler Problem 2 in Scheme</title>
		<link>http://www.mbowcock.com/notebook/project-euler-problem-2-in-scheme/</link>
		<comments>http://www.mbowcock.com/notebook/project-euler-problem-2-in-scheme/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 02:16:33 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[notebook]]></category>
		<category><![CDATA[project euler]]></category>

		<guid isPermaLink="false">http://www.mbowcock.com/?p=94</guid>
		<description><![CDATA[This one was relatively straight forward.


&#40;define &#40;fib-iter last-one last-two total max&#41;
&#160; &#40;if &#40;or &#40;&#62; &#40;+ last-one last-two&#41; max&#41; &#40;= &#40;+ last-one last-two&#41; max&#41;&#41;
&#160; &#160; &#160; total
&#160; &#160; &#160; &#40;fib-iter &#40;+ last-one last-two&#41;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; last-one
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#40;if &#40;= &#40;modulo &#40;+ last-one last-two&#41; 2&#41; 0&#41;
&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>This one was relatively straight forward.</p>
<pre>
<div class="codesnip-container" >
<div class="lisp codesnip" style="font-family:monospace;"><span class="br0">&#40;</span>define <span class="br0">&#40;</span>fib-iter last-one last-two total <span class="kw1">max</span><span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw1">or</span> <span class="br0">&#40;</span><span class="sy0">&gt;</span> <span class="br0">&#40;</span>+ last-one last-two<span class="br0">&#41;</span> <span class="kw1">max</span><span class="br0">&#41;</span> <span class="br0">&#40;</span><span class="sy0">=</span> <span class="br0">&#40;</span>+ last-one last-two<span class="br0">&#41;</span> <span class="kw1">max</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; total
&nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>fib-iter <span class="br0">&#40;</span>+ last-one last-two<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; last-one
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span><span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">=</span> <span class="br0">&#40;</span>modulo <span class="br0">&#40;</span>+ last-one last-two<span class="br0">&#41;</span> 2<span class="br0">&#41;</span> 0<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>+ total last-one last-two<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; total<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">max</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>fib-iter <span class="nu0">1</span> <span class="nu0">0</span> <span class="nu0">0</span> <span class="nu0">4000000</span><span class="br0">&#41;</span></div>
</div>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.mbowcock.com/notebook/project-euler-problem-2-in-scheme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SICP and Project Euler</title>
		<link>http://www.mbowcock.com/notebook/sicp-and-project-euler/</link>
		<comments>http://www.mbowcock.com/notebook/sicp-and-project-euler/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 15:40:30 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[notebook]]></category>
		<category><![CDATA[project euler]]></category>
		<category><![CDATA[sicp]]></category>

		<guid isPermaLink="false">http://www.mbowcock.com/?p=58</guid>
		<description><![CDATA[Working my way through SICP has a goal I&#8217;ve had for a while but never seemed to get to.  However &#8211; this past week I started reading the book and working on the exercises and am looking forward to the challenge.  I skipped a couple of exercises in the first section but came up with [...]]]></description>
			<content:encoded><![CDATA[<p>Working my way through <a href="http://mitpress.mit.edu/sicp/">SICP</a> has a goal I&#8217;ve had for a while but never seemed to get to.  However &#8211; this past week I started reading the book and working on the exercises and am looking forward to the challenge.  I skipped a couple of exercises in the first section but came up with the following to exercise 1.8:</p>
<pre>
<div class="codesnip-container" >
<div class="lisp codesnip" style="font-family:monospace;"><span class="br0">&#40;</span>define <span class="br0">&#40;</span>cube x<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span>* x x x<span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>abs-val x<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="kw1">cond</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="sy0">&amp;</span>gt<span class="co1">; x 0) x)</span>
&nbsp; &nbsp; <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="sy0">=</span> x 0<span class="br0">&#41;</span> 0<span class="br0">&#41;</span>
&nbsp; &nbsp; <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="sy0">&lt;</span> x 0<span class="br0">&#41;</span> <span class="br0">&#40;</span>- x<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>improve guess x<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span>/ <span class="br0">&#40;</span>+ <span class="br0">&#40;</span>/ x <span class="br0">&#40;</span>* guess guess<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#40;</span>* 2 guess<span class="br0">&#41;</span><span class="br0">&#41;</span> 3<span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>good-enough? guess x<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="sy0">&lt;</span> <span class="br0">&#40;</span>abs-val <span class="br0">&#40;</span>- <span class="br0">&#40;</span>cube guess<span class="br0">&#41;</span> x<span class="br0">&#41;</span><span class="br0">&#41;</span> 0<span class="sy0">.</span>001<span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>cube-root-iter guess x<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="kw1">if</span> <span class="br0">&#40;</span>good-enough? guess x<span class="br0">&#41;</span>
&nbsp; &nbsp; guess
&nbsp; &nbsp; <span class="br0">&#40;</span>cube-root-iter <span class="br0">&#40;</span>improve guess x<span class="br0">&#41;</span> x<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>cube-root x<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span>cube-root-iter <span class="nu0">1.0</span> x<span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</div>
</pre>
<p>Along with the exercises in SICP I plan to also apply my new found knowledge to some of the problems from <a href="http://projecteuler.net/">Project Euler</a>.  The solution I came up with for exercise 1 was probably overkill but it worked and should work for larger sets of numbers:</p>
<pre>
<div class="codesnip-container" >
<div class="lisp codesnip" style="font-family:monospace;"><span class="br0">&#40;</span>define <span class="br0">&#40;</span>calc-iter total count limit<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span><span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">=</span> count limit<span class="br0">&#41;</span>
&nbsp; &nbsp; total
&nbsp; &nbsp; <span class="br0">&#40;</span>calc-iter
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>+ <span class="br0">&#40;</span><span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw1">or</span> <span class="br0">&#40;</span><span class="sy0">=</span> <span class="br0">&#40;</span>modulo count <span class="nu0">3</span><span class="br0">&#41;</span> <span class="nu0">0</span><span class="br0">&#41;</span> <span class="br0">&#40;</span><span class="sy0">=</span> <span class="br0">&#40;</span>modulo count <span class="nu0">5</span><span class="br0">&#41;</span> <span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#41;</span> count <span class="nu0">0</span><span class="br0">&#41;</span> total<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>+ count <span class="nu0">1</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; limit<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>define <span class="br0">&#40;</span>calc x<span class="br0">&#41;</span>
&nbsp; <span class="br0">&#40;</span>calc-iter <span class="nu0">0</span> <span class="nu0">0</span> x<span class="br0">&#41;</span><span class="br0">&#41;</span>

<span class="br0">&#40;</span>calc <span class="nu0">1000</span><span class="br0">&#41;</span></div>
</div>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.mbowcock.com/notebook/sicp-and-project-euler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MIT Scheme on Arch Linux Issue</title>
		<link>http://www.mbowcock.com/notebook/mit-scheme-on-arch-linux-issue/</link>
		<comments>http://www.mbowcock.com/notebook/mit-scheme-on-arch-linux-issue/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 04:02:28 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[notebook]]></category>
		<category><![CDATA[arch linux]]></category>
		<category><![CDATA[scheme]]></category>

		<guid isPermaLink="false">http://www.mbowcock.com/?p=56</guid>
		<description><![CDATA[I installed the latest MIT/GNU Scheme version and ran into an issue with a missing dependency.  When attempting to start scheme I would get the following message -
error while loading shared libraries: libmhash.so.2: cannot open shared object file: No such file or directory
This ended up being an easy fix -
pacman -S mhash
]]></description>
			<content:encoded><![CDATA[<p>I installed the latest MIT/GNU Scheme version and ran into an issue with a missing dependency.  When attempting to start scheme I would get the following message -</p>
<div class="codesnip-container" >error while loading shared libraries: libmhash.so.2: cannot open shared object file: No such file or directory</div>
<p>This ended up being an easy fix -</p>
<div class="codesnip-container" >pacman -S mhash</div>
]]></content:encoded>
			<wfw:commentRss>http://www.mbowcock.com/notebook/mit-scheme-on-arch-linux-issue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Networking for Non-Network Engineers &#8211; Part 1</title>
		<link>http://www.mbowcock.com/notebook/networking-for-non-network-engineers-part-1/</link>
		<comments>http://www.mbowcock.com/notebook/networking-for-non-network-engineers-part-1/#comments</comments>
		<pubDate>Sat, 30 Aug 2008 04:08:36 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[notebook]]></category>

		<guid isPermaLink="false">http://www.mbowcock.com/?p=26</guid>
		<description><![CDATA[This post is a work in progress and will be expanded on in the future.
I work with developers, DBAs, etc. all the time who have no practical knowledge of computer networking.  I&#8217;m going to try to shed a little light on the magic that happens behind the scenes.  Initially this will be really [...]]]></description>
			<content:encoded><![CDATA[<p><em>This post is a work in progress and will be expanded on in the future.</em></p>
<p>I work with developers, DBAs, etc. all the time who have no practical knowledge of computer networking.  I&#8217;m going to try to shed a little light on the magic that happens behind the scenes.  Initially this will be really basic but will become more technical.</p>
<p>A computer network can be broken up into two distinct pieces &#8211; the edge and the core.  The network edge is made of things we are all familiar with &#8211; client PCs, servers, network attached storage, etc.  The network core is what connects the systems on the edge to each other.  The core is made up of routers, switches, hubs, etc.</p>
<p><strong>Network Edge</strong></p>
<p>Systems on the edge are sometimes referred to as <em>hosts</em> and hosts can be further broken down into clients and servers.  Clients are typically desktop PCs, thin clients, IP enabled phones and servers are typically more powerful systems such as web &amp; database servers.  In general software terms &#8211; a client is a program running on one edge system that requests a service from a program running on another edge system.  So &#8211; essentially one computer requests a service from another computer- AKA Client/Server architecture.</p>
<p><span id="more-26"></span></p>
<p>These edge systems communicate with each other by sending messages over the network core.  IP networks  (more on that later) allow for two forms of end-to-end communication &#8211; connection-oriented and connectionless.</p>
<p><strong>Connection-oriented services</strong> are provided by Transmission Control Protocol (TCP).  TCP provides services reliable communication, and flow and congestion control.  These assurances allow a client/server application to enjoy reliable data transfer.  The TCP protocol ensure reliable data transmission by following an initial handshaking procedure and then sending control packets along with real data.  These control packets allow the communicating systems to correctly order the data sent back and forth.  Common application that use TCP are email, and web servers.</p>
<p><strong>Connectionless services</strong> are provided by User Datagram Protocol (UDP).  UDP makes no assurances that data sent from one system to another will be received or what order it will be received in.  The benefit of UDP is speed &#8211; since there is no initial handshaking or error correction &#8211; data is sent once and forgotten.  UDP is popular where some loss of data is acceptable like IP phone, and streaming video.</p>
<p><strong>Network Core</strong></p>
<p>The core of modern networks is based on packet switching.  Edge systems communicate by sending messages back and forth.  These messages can be email, HMTL, data from a database, etc.  Large messages are broken down into<em> packets</em> which are a standard size based on the network service.  These packets are then transmitted through the network core &#8211; over network cables, switches/routers.</p>
<p><strong>Network Core Components</strong></p>
<p>Router &#8211; A router is used to connect multiple computers and networks.  For home usage a router would typically be used to connect a home network (LAN) to the Internet (WAN).  For a large corporate network a router may be used to connect LANs from different geographic locations on different network segment.</p>
<p>Switch &#8211; A switch is used to connect edge devices (PCs, servers) to one another over a LAN.  Devices on a  switch communicate directly with each other &#8211; as far as the devices are concerned &#8211; they are connected with each other directly.  Switches are not able to connect multiple networks together.</p>
<p>Hub &#8211; A hub is similar to switches in that they are used for connected devices to communicate with each other and that they can&#8217;t be used to connect networks together.  However &#8211; hubs differ from switches in that when a packet is transmitted on a switch it is forwarded to all connected devices not just the destination system.</p>
<p>You&#8217;ll often hear people refer to a router as a switch or a hub as a router &#8211; they perform similar functions in that they facilitate network communication &#8211; but they are all distinctly different.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mbowcock.com/notebook/networking-for-non-network-engineers-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.658 seconds -->
<!-- Cached page served by WP-Cache -->
