<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Euler Problem 75</title>
	<atom:link href="http://www.dailydoseofexcel.com/archives/2009/02/24/euler-problem-75/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dailydoseofexcel.com/archives/2009/02/24/euler-problem-75/</link>
	<description>Daily posts of Excel tips…and other stuff</description>
	<lastBuildDate>Thu, 09 Feb 2012 18:06:07 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Michael</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/02/24/euler-problem-75/#comment-38197</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Thu, 26 Feb 2009 14:43:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2138#comment-38197</guid>
		<description>&lt;p&gt;Good morning, Stephen -&lt;/p&gt;
&lt;p&gt;Thank you.  I left them as currency here to tie in with the Snipit thread.  Exactly as you say, they are very properly &quot;longs&quot; since I no longer had a need to store large square values.&lt;/p&gt;
&lt;p&gt;Have you seen the &quot;Code Snipit to test&quot; thread?  That came about because of a need I didn&#039;t really have in this problem.  When Dick allowed me to author, I didn&#039;t think I&#039;d become an insectologist.&lt;/p&gt;
&lt;p&gt;I also didn&#039;t quite realize whose notice I&#039;d attract.&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;
&lt;p&gt;...mrt&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Good morning, Stephen -</p>
<p>Thank you.  I left them as currency here to tie in with the Snipit thread.  Exactly as you say, they are very properly &#8220;longs&#8221; since I no longer had a need to store large square values.</p>
<p>Have you seen the &#8220;Code Snipit to test&#8221; thread?  That came about because of a need I didn&#8217;t really have in this problem.  When Dick allowed me to author, I didn&#8217;t think I&#8217;d become an insectologist.</p>
<p>I also didn&#8217;t quite realize whose notice I&#8217;d attract.</p>
<p>Thank you.</p>
<p>&#8230;mrt</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephen Bullen</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/02/24/euler-problem-75/#comment-38196</link>
		<dc:creator>Stephen Bullen</dc:creator>
		<pubDate>Thu, 26 Feb 2009 14:27:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2138#comment-38196</guid>
		<description>&lt;p&gt;Michael, with such a tight routine, all the variant/long conversions will probably have quite an impact. If you declare a and b &#039;As Long&#039;, you should see it improve.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Michael, with such a tight routine, all the variant/long conversions will probably have quite an impact. If you declare a and b &#8216;As Long&#8217;, you should see it improve.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/02/24/euler-problem-75/#comment-38195</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Thu, 26 Feb 2009 14:15:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2138#comment-38195</guid>
		<description>&lt;p&gt;Hi Mike -&lt;/p&gt;
&lt;p&gt;As a recursive kind of guy ;-) you no doubt have this, but for those who don&#039;t, here&#039;s the recursive GCD version, GCD1().&lt;/p&gt;
&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container vb default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;vb codecolorer&quot;&gt;&lt;span class=&quot;kw1&quot;&gt;Function&lt;/span&gt; GCD1(&lt;span class=&quot;kw1&quot;&gt;ByVal&lt;/span&gt; a, &lt;span class=&quot;kw1&quot;&gt;ByVal&lt;/span&gt; b) &#160; &lt;span class=&quot;co1&quot;&gt;&#039;Euclid&#039;s Algorithm&lt;br&gt;
&lt;/span&gt; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; b = 0 &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; GCD1 = a&lt;br&gt;
&#160; &#160;&lt;span class=&quot;kw1&quot;&gt;Else&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; GCD1 = GCD1(b, a &lt;span class=&quot;kw1&quot;&gt;Mod&lt;/span&gt; b)&lt;br&gt;
&#160; &#160;&lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Function&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;I&#039;ve found GCD2() above to be faster when I swap &#039;em out.&lt;/p&gt;
&lt;p&gt;...mrt&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi Mike -</p>
<p>As a recursive kind of guy <img src='http://www.dailydoseofexcel.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  you no doubt have this, but for those who don&#8217;t, here&#8217;s the recursive GCD version, GCD1().</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer"><span class="kw1">Function</span> GCD1(<span class="kw1">ByVal</span> a, <span class="kw1">ByVal</span> b) &nbsp; <span class="co1">&#8216;Euclid&#8217;s Algorithm<br />
</span> &nbsp; <span class="kw1">If</span> b = 0 <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; GCD1 = a<br />
&nbsp; &nbsp;<span class="kw1">Else</span><br />
&nbsp; &nbsp; &nbsp; GCD1 = GCD1(b, a <span class="kw1">Mod</span> b)<br />
&nbsp; &nbsp;<span class="kw1">End</span> <span class="kw1">If</span><br />
<span class="kw1">End</span> <span class="kw1">Function</span></div>
</div>
<p>I&#8217;ve found GCD2() above to be faster when I swap &#8216;em out.</p>
<p>&#8230;mrt</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Woodhouse</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/02/24/euler-problem-75/#comment-38193</link>
		<dc:creator>Mike Woodhouse</dc:creator>
		<pubDate>Thu, 26 Feb 2009 11:44:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2138#comment-38193</guid>
		<description>&lt;p&gt;I also worked the problem using the T1/2/3 transforms mentioned further down the Wikipedia page, which allow recursion to be applied. I try to take any opportunity to code a recursive function, since I still have to think them through very carefully. That solution ran in about half the time of the Euclid-based one.&lt;/p&gt;
&lt;p&gt;I can&#039;t believe I&#039;d missed the stupid GCD function, by the way, although I didn&#039;t use it for this problem: I just used the formulae to crank out primitives until they reached the maximum, and added the multiples with a loop.&lt;/p&gt;
&lt;p&gt;I don&#039;t think dictionaries have much of an advantage - if any at all - over arrays in this case. They&#039;re very handy as a substitute for sparsely-populated arrays (vectors, really) of large size. When, as in this case, over 10% of the possible values are of interest (and many more are used but not really interesting) then the additional overhead of the hashing in the Dictionary lookup probably isn&#039;t worth it.&lt;/p&gt;
&lt;p&gt;Comparing Dictionaries against Collections:&lt;br&gt;
On the one hand, you lose &quot;For Each&quot; when you move from a Collection.&lt;br&gt;
On the other hand, you gain a lot of performance, plus the &quot;.Exist&quot; method.&lt;br&gt;
On the gripping hand they both suck against Arrays when you load them up with non-trivial quantities of non-primitive objects and then destroy them.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I also worked the problem using the T1/2/3 transforms mentioned further down the Wikipedia page, which allow recursion to be applied. I try to take any opportunity to code a recursive function, since I still have to think them through very carefully. That solution ran in about half the time of the Euclid-based one.</p>
<p>I can&#8217;t believe I&#8217;d missed the stupid GCD function, by the way, although I didn&#8217;t use it for this problem: I just used the formulae to crank out primitives until they reached the maximum, and added the multiples with a loop.</p>
<p>I don&#8217;t think dictionaries have much of an advantage &#8211; if any at all &#8211; over arrays in this case. They&#8217;re very handy as a substitute for sparsely-populated arrays (vectors, really) of large size. When, as in this case, over 10% of the possible values are of interest (and many more are used but not really interesting) then the additional overhead of the hashing in the Dictionary lookup probably isn&#8217;t worth it.</p>
<p>Comparing Dictionaries against Collections:<br />
On the one hand, you lose &#8220;For Each&#8221; when you move from a Collection.<br />
On the other hand, you gain a lot of performance, plus the &#8220;.Exist&#8221; method.<br />
On the gripping hand they both suck against Arrays when you load them up with non-trivial quantities of non-primitive objects and then destroy them.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/02/24/euler-problem-75/#comment-38183</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Wed, 25 Feb 2009 20:27:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2138#comment-38183</guid>
		<description>&lt;p&gt;Hi fzz -&lt;/p&gt;
&lt;p&gt;Different ways to get to P.  If one uses P = 2m(m+n), then you don&#039;t need a and b.  I used c only as a kick-out to shave some msecs that I might waste in calculating it.  Taking m to 999 and n to 2 does give c &gt; 1000000.&lt;/p&gt;
&lt;p&gt;Significantly less loops your way, though.  I put in a counter and I reach Next n an even 250000 times.&lt;/p&gt;
&lt;p&gt;My only experience with dictionaries, actually, is with this problem, and I found stuffing a series/array faster.&lt;/p&gt;
&lt;p&gt;What do you get for run time?&lt;/p&gt;
&lt;p&gt;...mrt&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi fzz -</p>
<p>Different ways to get to P.  If one uses P = 2m(m+n), then you don&#8217;t need a and b.  I used c only as a kick-out to shave some msecs that I might waste in calculating it.  Taking m to 999 and n to 2 does give c &gt; 1000000.</p>
<p>Significantly less loops your way, though.  I put in a counter and I reach Next n an even 250000 times.</p>
<p>My only experience with dictionaries, actually, is with this problem, and I found stuffing a series/array faster.</p>
<p>What do you get for run time?</p>
<p>&#8230;mrt</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fzz</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/02/24/euler-problem-75/#comment-38181</link>
		<dc:creator>fzz</dc:creator>
		<pubDate>Wed, 25 Feb 2009 18:44:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2138#comment-38181</guid>
		<description>&lt;p&gt;Iteration is again the key.&lt;/p&gt;
&lt;p&gt;It can be shown that for a .LT. b .LT. c, c - b = 1 or 2 only for primitive triples. When c - b = 1, this means the difference between sequential squares b2 and c2 must also be a square. Since n2 is the sum of the first n positive odd integers, the square of every odd number is in a primitive triple, so&lt;/p&gt;
&lt;p&gt;a = 3, b = 4, c = 5, a + b + c = 12 = 3 * 4 = a(a + 1)&lt;br&gt;
a = 5, b = c - 1 = 12, c = (a2 + 1)/2 = 13, a + b + c = 30 = 5 * 6 = a(a + 1)&lt;br&gt;
a = 7, b = c - 1 = 24, c = (a2 + 1)/2 = 25, a + b + c = 56 = 7 * 8 = a(a + 1)&lt;br&gt;
a = 9, b = c - 1 = 40, c = (a2 + 1)/2 = 41, a + b + c = 90 = 9 * 10 = a(a + 1)&lt;/p&gt;
&lt;p&gt;So sufficient to iterate a = 3 to a = 1413 step 2. For c - b = 2, a can be every multiple of 4 starting with 8 (a = 4 corresponds to b = 3, but that violates a .LT. b).&lt;/p&gt;
&lt;p&gt;a = 8, b = 15, c = 17, a + b + c = 40 = 8 * 5 = a(a/2 + 1)&lt;br&gt;
a = 12, b = 35, c = 37, a + b + c = 84 = 12 * 7 = a(a/2 + 1)&lt;br&gt;
a = 16, b = 63, c = 65, a + b + c = 144 = 16 * 9 = a(a/2 + 1)&lt;/p&gt;
&lt;p&gt;So sufficient to iterare a = 8 to 1996 step 4.&lt;/p&gt;
&lt;p&gt;The a(a + 1) and a(a/2 + 1) terms give the perimeters of primitive triples. Their multiples are perimeters of nonprimitive triples. Easiest to iterate from 1 to 2E6  primitive perimeter storing the multiples of the primitive perimeters as keys in a WSH Dictionary object with the count as the key&#039;s values. Then get the result by counting the resulting .Item values equal to 1.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Iteration is again the key.</p>
<p>It can be shown that for a .LT. b .LT. c, c &#8211; b = 1 or 2 only for primitive triples. When c &#8211; b = 1, this means the difference between sequential squares b2 and c2 must also be a square. Since n2 is the sum of the first n positive odd integers, the square of every odd number is in a primitive triple, so</p>
<p>a = 3, b = 4, c = 5, a + b + c = 12 = 3 * 4 = a(a + 1)<br />
a = 5, b = c &#8211; 1 = 12, c = (a2 + 1)/2 = 13, a + b + c = 30 = 5 * 6 = a(a + 1)<br />
a = 7, b = c &#8211; 1 = 24, c = (a2 + 1)/2 = 25, a + b + c = 56 = 7 * 8 = a(a + 1)<br />
a = 9, b = c &#8211; 1 = 40, c = (a2 + 1)/2 = 41, a + b + c = 90 = 9 * 10 = a(a + 1)</p>
<p>So sufficient to iterate a = 3 to a = 1413 step 2. For c &#8211; b = 2, a can be every multiple of 4 starting with 8 (a = 4 corresponds to b = 3, but that violates a .LT. b).</p>
<p>a = 8, b = 15, c = 17, a + b + c = 40 = 8 * 5 = a(a/2 + 1)<br />
a = 12, b = 35, c = 37, a + b + c = 84 = 12 * 7 = a(a/2 + 1)<br />
a = 16, b = 63, c = 65, a + b + c = 144 = 16 * 9 = a(a/2 + 1)</p>
<p>So sufficient to iterare a = 8 to 1996 step 4.</p>
<p>The a(a + 1) and a(a/2 + 1) terms give the perimeters of primitive triples. Their multiples are perimeters of nonprimitive triples. Easiest to iterate from 1 to 2E6  primitive perimeter storing the multiples of the primitive perimeters as keys in a WSH Dictionary object with the count as the key&#8217;s values. Then get the result by counting the resulting .Item values equal to 1.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

