<?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>Dreamshire &#187; Series</title>
	<atom:link href="http://blog.dreamshire.com/tag/series/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.dreamshire.com</link>
	<description>Showing what's behind the curtain</description>
	<lastBuildDate>Wed, 01 Sep 2010 02:23:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Project Euler Problem 28 Solution</title>
		<link>http://blog.dreamshire.com/2009/05/02/project-euler-problem-28-solution/</link>
		<comments>http://blog.dreamshire.com/2009/05/02/project-euler-problem-28-solution/#comments</comments>
		<pubDate>Sat, 02 May 2009 08:24:03 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Project Euler Solutions]]></category>
		<category><![CDATA[Solutions 20-29]]></category>
		<category><![CDATA[Project Euler]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Series]]></category>
		<category><![CDATA[solution]]></category>

		<guid isPermaLink="false">http://blog.dreamshire.com/?p=1072</guid>
		<description><![CDATA[What is the sum of both diagonals in a 1001 by 1001 spiral?]]></description>
			<content:encoded><![CDATA[<h4><u>Problem Description</u></h4>
<p>Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows:</p>
<p style='text-align:center;font-family:courier new;'><span style='color:#ff0000;font-family:courier new;'>21</span> 22 23 24 <span style='color:#ff0000;font-family:courier new;'>25</span><br />
20 &nbsp;<span style='color:#ff0000;font-family:courier new;'>7</span> &nbsp;8 &nbsp;<span style='color:#ff0000;font-family:courier new;'>9</span> 10<br />
19 &nbsp;6 &nbsp;<span style='color:#ff0000;font-family:courier new;'>1</span> &nbsp;2 11<br />
18 &nbsp;<span style='color:#ff0000;font-family:courier new;'>5</span> &nbsp;4 &nbsp;<span style='color:#ff0000;font-family:courier new;'>3</span> 12<br />
<span style='color:#ff0000;font-family:courier new;'>17</span> 16 15 14 <span style='color:#ff0000;font-family:courier new;'>13</span></p>
<p>It can be verified that the sum of both diagonals is 101.</p>
<p>What is the sum of both diagonals in a 1001 by 1001 spiral formed in the same way?</p>
<h4><u>Analysis</u></h4>
<p>The &#8220;corners&#8221; which form the central diagonals form a simple series:  (3, 5, 7, 9),  (13, 17, 21, 25),  (31, 37, 43, 49), &#8230;<br />
Simply add the series for [2,1001] iterations, stepping by 2 since you can&#8217;t have even numbered sides  (2001 terms).</p>
<p>With the exception of the center, which is one, the four corners form another series when added together: 24, 76, 160, &#8230; for odd n>2 is 4n<sup>2</sup> &minus; 6n + 6.  Or, you could even take this one step further and summarize the sum for both diagonals based on the length of a side in one equation. </p>
<h4><u>Solution</u></h4>
<p>Runs < 1 second in Python.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #008000;">sum</span>, d, size = <span style="color: #ff4500;">1</span>, <span style="color: #ff4500;">1</span>, <span style="color: #ff4500;">1001</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> n <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span>, size, <span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>:
  <span style="color: #008000;">sum</span> += <span style="color: #ff4500;">4</span><span style="color: #66cc66;">*</span>d + <span style="color: #ff4500;">10</span><span style="color: #66cc66;">*</span>n
  d += n<span style="color: #66cc66;">*</span><span style="color: #ff4500;">4</span><span style="color: #66cc66;">;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Answer to PE28 = &quot;</span>,<span style="color: #008000;">sum</span></pre></div></div>

<h4><u>Comments</u></h4>
<p>The <tt>4*d + 10*n</tt> replaces a loop that looks like <tt>Sum += (d + n*i) for i (1..4)</tt><br />
See <a href="http://blog.dreamshire.com/2009/04/11/project-euler-problem-58-solution/">problem 58</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dreamshire.com/2009/05/02/project-euler-problem-28-solution/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
