<?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 206</title>
	<atom:link href="http://www.dailydoseofexcel.com/archives/2009/05/29/euler-problem-206/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dailydoseofexcel.com/archives/2009/05/29/euler-problem-206/</link>
	<description>Daily posts of Excel tips…and other stuff</description>
	<lastBuildDate>Thu, 09 Feb 2012 19:28:40 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: fzz</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/05/29/euler-problem-206/#comment-39619</link>
		<dc:creator>fzz</dc:creator>
		<pubDate>Mon, 01 Jun 2009 02:23:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2516#comment-39619</guid>
		<description>&lt;p&gt;No squared integer can end with 0 without ending with 00. So the max is actually 1929394959697989900. The answer is 10 N with N^2 satisfying 1_2_3_4_5_6_7_8_9, and if N^2 ends in 9, then N must end in either 3 or 7. So N = 10 M + {3&#124;7} for some other integer M, so N^2 = 100 M^2 + {60&#124;140} M + {9&#124;49}. No need to check for the final 9, so M^2 + {.6&#124;1.4} M + {0&#124;.4} must be of the form 1_2_3_4_5_6_7_8.#, so it&#039;s sufficient to find such M.&lt;/p&gt;
&lt;p&gt;The reason for the speed of your second macro is searching backwards from max to min. The answer is close to max.&lt;/p&gt;
&lt;p&gt;Here&#039;s an alternative.&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;Sub&lt;/span&gt; foo()&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;Const&lt;/span&gt; p &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;String&lt;/span&gt; = &lt;span class=&quot;st0&quot;&gt;&quot;1?2?3?4?5?6?7?8&quot;&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;Dim&lt;/span&gt; m &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Double&lt;/span&gt;, dt &lt;span class=&quot;kw1&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Double&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&#160; dt = Timer&lt;br&gt;
&lt;br&gt;
&#160; m = &lt;span class=&quot;kw1&quot;&gt;CLng&lt;/span&gt;(Sqr(&lt;span class=&quot;kw1&quot;&gt;CDec&lt;/span&gt;(&lt;span class=&quot;st0&quot;&gt;&quot;192939495969798&quot;&lt;/span&gt;))) &#160;&lt;span class=&quot;co1&quot;&gt;&#039;start at the max&lt;br&gt;
&lt;/span&gt;&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;Do&lt;/span&gt;&lt;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; Int(m * (m + 0.6)) &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; p &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; m = 100 * m + 30&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Exit&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Do&lt;/span&gt;&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;br&gt;
&#160; &#160; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; Int(m * (m + 1.4) + 0.4) &lt;span class=&quot;kw1&quot;&gt;Like&lt;/span&gt; p &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; &#160; &#160; m = 100 * m + 70&lt;br&gt;
&#160; &#160; &#160; &lt;span class=&quot;kw1&quot;&gt;Exit&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Do&lt;/span&gt;&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;br&gt;
&#160; &#160; m = m - 1# &#160;&lt;span class=&quot;co1&quot;&gt;&#039;and decrement&lt;br&gt;
&lt;/span&gt;&lt;br&gt;
&#160; &lt;span class=&quot;kw1&quot;&gt;Loop&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&#160; Debug.&lt;span class=&quot;kw1&quot;&gt;Print&lt;/span&gt; m, &lt;span class=&quot;kw1&quot;&gt;CDec&lt;/span&gt;(m) * &lt;span class=&quot;kw1&quot;&gt;CDec&lt;/span&gt;(m), Timer - dt&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Sub&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
</description>
		<content:encoded><![CDATA[<p>No squared integer can end with 0 without ending with 00. So the max is actually 1929394959697989900. The answer is 10 N with N^2 satisfying 1_2_3_4_5_6_7_8_9, and if N^2 ends in 9, then N must end in either 3 or 7. So N = 10 M + {3|7} for some other integer M, so N^2 = 100 M^2 + {60|140} M + {9|49}. No need to check for the final 9, so M^2 + {.6|1.4} M + {0|.4} must be of the form 1_2_3_4_5_6_7_8.#, so it&#8217;s sufficient to find such M.</p>
<p>The reason for the speed of your second macro is searching backwards from max to min. The answer is close to max.</p>
<p>Here&#8217;s an alternative.</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer"><span class="kw1">Sub</span> foo()<br />
&nbsp; <span class="kw1">Const</span> p <span class="kw1">As</span> <span class="kw1">String</span> = <span class="st0">&#8220;1?2?3?4?5?6?7?8&#8243;</span></p>
<p>&nbsp; <span class="kw1">Dim</span> m <span class="kw1">As</span> <span class="kw1">Double</span>, dt <span class="kw1">As</span> <span class="kw1">Double</span></p>
<p>&nbsp; dt = Timer</p>
<p>&nbsp; m = <span class="kw1">CLng</span>(Sqr(<span class="kw1">CDec</span>(<span class="st0">&#8220;192939495969798&#8243;</span>))) &nbsp;<span class="co1">&#8216;start at the max<br />
</span><br />
&nbsp; <span class="kw1">Do</span><br />
&nbsp; &nbsp; <span class="kw1">If</span> Int(m * (m + 0.6)) <span class="kw1">Like</span> p <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; m = 100 * m + 30<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">Exit</span> <span class="kw1">Do</span><br />
&nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span></p>
<p>&nbsp; &nbsp; <span class="kw1">If</span> Int(m * (m + 1.4) + 0.4) <span class="kw1">Like</span> p <span class="kw1">Then</span><br />
&nbsp; &nbsp; &nbsp; m = 100 * m + 70<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">Exit</span> <span class="kw1">Do</span><br />
&nbsp; &nbsp; <span class="kw1">End</span> <span class="kw1">If</span></p>
<p>&nbsp; &nbsp; m = m &#8211; 1# &nbsp;<span class="co1">&#8216;and decrement<br />
</span><br />
&nbsp; <span class="kw1">Loop</span></p>
<p>&nbsp; Debug.<span class="kw1">Print</span> m, <span class="kw1">CDec</span>(m) * <span class="kw1">CDec</span>(m), Timer &#8211; dt<br />
<span class="kw1">End</span> <span class="kw1">Sub</span></div>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/05/29/euler-problem-206/#comment-39616</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Sun, 31 May 2009 16:10:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2516#comment-39616</guid>
		<description>&lt;p&gt;Hi Dan -&lt;/p&gt;
&lt;p&gt;Exactly so...that&#039;s why the step can go from -1 to -10.  I didn&#039;t see it, but Mike W pointed the same out above.  Thinking about it, it goes the other way too...if the square root ends in zero, the square must end in 00.&lt;/p&gt;
&lt;p&gt;...mrt&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi Dan -</p>
<p>Exactly so&#8230;that&#8217;s why the step can go from -1 to -10.  I didn&#8217;t see it, but Mike W pointed the same out above.  Thinking about it, it goes the other way too&#8230;if the square root ends in zero, the square must end in 00.</p>
<p>&#8230;mrt</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/05/29/euler-problem-206/#comment-39613</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Sun, 31 May 2009 13:54:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2516#comment-39613</guid>
		<description>&lt;p&gt;Not sure if you&#039;ve factored this in (I&#039;m not a VB expert by any stretch), but the square root must end in a zero, given that its square ends in a zero.&lt;/p&gt;
&lt;p&gt;Does this reduce your possible answers by a factor of ten?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Not sure if you&#8217;ve factored this in (I&#8217;m not a VB expert by any stretch), but the square root must end in a zero, given that its square ends in a zero.</p>
<p>Does this reduce your possible answers by a factor of ten?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/05/29/euler-problem-206/#comment-39606</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Sun, 31 May 2009 00:50:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2516#comment-39606</guid>
		<description>&lt;p&gt;Hi Mike -&lt;/p&gt;
&lt;p&gt;I added one line of code below the MAX = Int(Sqr(Cdbl(...))) line:&lt;/p&gt;
&lt;p&gt;Max = Max + 10 - (Max Mod 10)&lt;/p&gt;
&lt;p&gt;And then I changed &quot;Step -1? to &quot;Step -10?&lt;/p&gt;
&lt;p&gt;And now Timer - t is 0 seconds!  Maximum cool!  Thanks.&lt;/p&gt;
&lt;p&gt;...mrt&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi Mike -</p>
<p>I added one line of code below the MAX = Int(Sqr(Cdbl(&#8230;))) line:</p>
<p>Max = Max + 10 &#8211; (Max Mod 10)</p>
<p>And then I changed &#8220;Step -1? to &#8220;Step -10?</p>
<p>And now Timer &#8211; t is 0 seconds!  Maximum cool!  Thanks.</p>
<p>&#8230;mrt</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/05/29/euler-problem-206/#comment-39600</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Sat, 30 May 2009 19:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2516#comment-39600</guid>
		<description>&lt;p&gt;Hi Mike -&lt;/p&gt;
&lt;p&gt;Please optimize away.  I asked Dick if I could do this just as much to learn as maybe to teach.  I&#039;m a systems engineer.  Even with a CS grad degree, all my code is for my personal use.  This makes me not too much more than a hobbyist conversing with pro&#039;s.  &lt;/p&gt;
&lt;p&gt;Reading the Euler fine print, I saw that you could sort the problems by increasing difficulty, which in practice I think is a descending sort on number of solvers.  Problem 206 was right near where my checkmarks ran out.&lt;/p&gt;
&lt;p&gt;I added to the Problem 73 thread how I saw the recursive function working.  Didn&#039;t help doing problem 72.  I&#039;m stalled too.  No more snowy weekends for a while to stay inside ;-)  Chores aplenty await.&lt;/p&gt;
&lt;p&gt;...mrt&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi Mike -</p>
<p>Please optimize away.  I asked Dick if I could do this just as much to learn as maybe to teach.  I&#8217;m a systems engineer.  Even with a CS grad degree, all my code is for my personal use.  This makes me not too much more than a hobbyist conversing with pro&#8217;s.  </p>
<p>Reading the Euler fine print, I saw that you could sort the problems by increasing difficulty, which in practice I think is a descending sort on number of solvers.  Problem 206 was right near where my checkmarks ran out.</p>
<p>I added to the Problem 73 thread how I saw the recursive function working.  Didn&#8217;t help doing problem 72.  I&#8217;m stalled too.  No more snowy weekends for a while to stay inside <img src='http://www.dailydoseofexcel.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />   Chores aplenty await.</p>
<p>&#8230;mrt</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Woodhouse</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/05/29/euler-problem-206/#comment-39592</link>
		<dc:creator>Mike Woodhouse</dc:creator>
		<pubDate>Sat, 30 May 2009 10:07:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=2516#comment-39592</guid>
		<description>&lt;p&gt;I hadn&#039;t noticed this one; I&#039;ve been busy getting stuck on some around the 100 point. Nice one.&lt;/p&gt;
&lt;p&gt;Ever the optimiser of other peoples&#039; code, however, I did notice the following: the answer has to be a multiple of 10 to give a square that ends in zero, so your step size can be -10 providing you adjust start and end values accordingly. That also means you don&#039;t need the i=19/j=0 test, which will always be true. Also, I wonder if the CStr(j) is slower than creating a string constant and applying Mid() to that. It would reduce the size of the code somewhat:&lt;/p&gt;
&lt;p&gt;      SAT = True&lt;br&gt;
      For i = 1 To 19 Step 2&lt;br&gt;
         SAT = ( Mid(Answer_Sqrd, i, 1) = Mid(TEST_STRING, i, 1) )&lt;br&gt;
         If Not SAT Then Exit For&lt;br&gt;
      Next i&lt;/p&gt;
&lt;p&gt;...but it&#039;s a bit nit-picky for a 0.04 second runtime!&lt;/p&gt;
&lt;p&gt;I think there&#039;s probably some more mathemtical work that can be done: my solution took 0.015 sec counting down, but 444 sec counting up.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I hadn&#8217;t noticed this one; I&#8217;ve been busy getting stuck on some around the 100 point. Nice one.</p>
<p>Ever the optimiser of other peoples&#8217; code, however, I did notice the following: the answer has to be a multiple of 10 to give a square that ends in zero, so your step size can be -10 providing you adjust start and end values accordingly. That also means you don&#8217;t need the i=19/j=0 test, which will always be true. Also, I wonder if the CStr(j) is slower than creating a string constant and applying Mid() to that. It would reduce the size of the code somewhat:</p>
<p>      SAT = True<br />
      For i = 1 To 19 Step 2<br />
         SAT = ( Mid(Answer_Sqrd, i, 1) = Mid(TEST_STRING, i, 1) )<br />
         If Not SAT Then Exit For<br />
      Next i</p>
<p>&#8230;but it&#8217;s a bit nit-picky for a 0.04 second runtime!</p>
<p>I think there&#8217;s probably some more mathemtical work that can be done: my solution took 0.015 sec counting down, but 444 sec counting up.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

