 




<?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: Puzzle &#8211; Find the number?</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/puzzle-find-the-number/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/puzzle-find-the-number/</link>
	<description></description>
	<lastBuildDate>Wed, 22 May 2013 12:21:28 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: kccrosser</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/puzzle-find-the-number/#comment-61930</link>
		<dc:creator>kccrosser</dc:creator>
		<pubDate>Mon, 06 Apr 2009 20:35:31 +0000</pubDate>
		<guid isPermaLink="false">#comment-61930</guid>
		<description><![CDATA[A somewhat obvious speed enhancement to any of the brute force algorithms is that the first condition (&quot;divided by 10 the remainder is 9&quot;) means that the last digit must be a &quot;9&quot;.

Ergo, any loop can be of the form:

for i = 9 to 9999 step 10     --  use your favorite language syntax here

And then, of course, you don&#039;t need to execute the &quot;X mod 10 = 9&quot; test.  Further, since 9 is odd, you can skip the &quot;X mod 2 = 1&quot; test as well.

Last bit of tuning is to recognize that the modulo function is more likely to succeed for false answers for small modulus values than for large modulus values, thus the optimum series is &quot;for modulus = 8 downto 3&quot;.

Resulting in (pseudo code):

&lt;pre&gt;integer i
integer m
boolean bfound
for i = 9 to 9999 step 10
  bfound = true
  for m = 8 downto 3 step -1
    if (i mod m) != (m-1) then
       bfound = false
       exit for    &#039; exit inner loop on first modulus test failure
    end if
  next &#039; m
  if bfound then
    msgbox i
    exit for
  end if
next &#039; i&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>A somewhat obvious speed enhancement to any of the brute force algorithms is that the first condition (&#8220;divided by 10 the remainder is 9&#8243;) means that the last digit must be a &#8220;9&#8243;.</p>
<p>Ergo, any loop can be of the form:</p>
<p>for i = 9 to 9999 step 10     &#8212;  use your favorite language syntax here</p>
<p>And then, of course, you don&#8217;t need to execute the &#8220;X mod 10 = 9&#8243; test.  Further, since 9 is odd, you can skip the &#8220;X mod 2 = 1&#8243; test as well.</p>
<p>Last bit of tuning is to recognize that the modulo function is more likely to succeed for false answers for small modulus values than for large modulus values, thus the optimum series is &#8220;for modulus = 8 downto 3&#8243;.</p>
<p>Resulting in (pseudo code):</p>
<pre>integer i
integer m
boolean bfound
for i = 9 to 9999 step 10
  bfound = true
  for m = 8 downto 3 step -1
    if (i mod m) != (m-1) then
       bfound = false
       exit for    ' exit inner loop on first modulus test failure
    end if
  next ' m
  if bfound then
    msgbox i
    exit for
  end if
next ' i</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: roaddust</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/puzzle-find-the-number/#comment-61866</link>
		<dc:creator>roaddust</dc:creator>
		<pubDate>Fri, 03 Apr 2009 21:19:20 +0000</pubDate>
		<guid isPermaLink="false">#comment-61866</guid>
		<description><![CDATA[Sorry it took so long to respond, here is the code that I used to figure the same number.  The MOD function returns just the remainder.

For i = 1 To 10000
    If i Mod 10 = 9 And i Mod 9 = 8 And i Mod 8 = 7 And i Mod 7 = 6 And i Mod 6 = 5 And i Mod 5 = 4 And i Mod 4 = 3 And i Mod 3 = 2 And i Mod 2 = 1 Then
        MsgBox i
    End If
    i = i + 1
Next

Dustin]]></description>
		<content:encoded><![CDATA[<p>Sorry it took so long to respond, here is the code that I used to figure the same number.  The MOD function returns just the remainder.</p>
<p>For i = 1 To 10000<br />
    If i Mod 10 = 9 And i Mod 9 = 8 And i Mod 8 = 7 And i Mod 7 = 6 And i Mod 6 = 5 And i Mod 5 = 4 And i Mod 4 = 3 And i Mod 3 = 2 And i Mod 2 = 1 Then<br />
        MsgBox i<br />
    End If<br />
    i = i + 1<br />
Next</p>
<p>Dustin</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: carlosdl</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/puzzle-find-the-number/#comment-59229</link>
		<dc:creator>carlosdl</dc:creator>
		<pubDate>Fri, 16 Jan 2009 01:19:49 +0000</pubDate>
		<guid isPermaLink="false">#comment-59229</guid>
		<description><![CDATA[Nice,

This was my first algorith (Oracle PL/SQL), just to check Flame&#039;s answer ( :-) ):

&lt;pre&gt;create or replace PROCEDURE test IS
	found boolean := false;
	theNumber number := 9;
BEGIN
	while not found loop												-- test all constraints
		if mod(theNumber,10) = 9 then
			if mod(theNumber,9) = 8 then
				if mod(theNumber,8) = 7 then
					if mod(theNumber,7) = 6 then
						if mod(theNumber,6) = 5 then
							if mod(theNumber,5) = 4 then
								if mod(theNumber,4) = 3 then
									if mod(theNumber,3) = 2 then
										if mod(theNumber,2) = 1 then
											dbms_output.put_line(&#039;The number is: &#039;&#124;&#124;theNumber);
											found := true;
										end if;
									end if;
								end if;
							end if;
						end if;
					end if;
				end if;
			end if;
		end if;
		theNumber := theNumber + 10;
	exit when theNumber &gt; 100000;		-- Just in case
	end loop;
END;&lt;/pre&gt;

&lt;b&gt;Then I changed it to a shorter one:&lt;/b&gt;

&lt;pre&gt;	while not found loop
		for i in 2 .. 9 loop
			if mod(theNumber,i) != i-1 then
				exit;
			elsif i = 9 then
				dbms_output.put_line(&#039;The number is: &#039;&#124;&#124;theNumber);
				found := true;
			end if;
		end loop;
		theNumber := theNumber + 10;	
	exit when theNumber &gt; 100000;		-- Just in case
	end loop;&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>Nice,</p>
<p>This was my first algorith (Oracle PL/SQL), just to check Flame&#8217;s answer ( <img src='http://itknowledgeexchange.techtarget.com/itanswers/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ):</p>
<pre>create or replace PROCEDURE test IS
	found boolean := false;
	theNumber number := 9;
BEGIN
	while not found loop												-- test all constraints
		if mod(theNumber,10) = 9 then
			if mod(theNumber,9) = 8 then
				if mod(theNumber,8) = 7 then
					if mod(theNumber,7) = 6 then
						if mod(theNumber,6) = 5 then
							if mod(theNumber,5) = 4 then
								if mod(theNumber,4) = 3 then
									if mod(theNumber,3) = 2 then
										if mod(theNumber,2) = 1 then
											dbms_output.put_line('The number is: '||theNumber);
											found := true;
										end if;
									end if;
								end if;
							end if;
						end if;
					end if;
				end if;
			end if;
		end if;
		theNumber := theNumber + 10;
	exit when theNumber &gt; 100000;		-- Just in case
	end loop;
END;</pre>
<p><b>Then I changed it to a shorter one:</b></p>
<pre>	while not found loop
		for i in 2 .. 9 loop
			if mod(theNumber,i) != i-1 then
				exit;
			elsif i = 9 then
				dbms_output.put_line('The number is: '||theNumber);
				found := true;
			end if;
		end loop;
		theNumber := theNumber + 10;	
	exit when theNumber &gt; 100000;		-- Just in case
	end loop;</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: sbelectric</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/puzzle-find-the-number/#comment-59217</link>
		<dc:creator>sbelectric</dc:creator>
		<pubDate>Thu, 15 Jan 2009 20:32:11 +0000</pubDate>
		<guid isPermaLink="false">#comment-59217</guid>
		<description><![CDATA[Well  ... it is nice to know that so many people got the number by different methods.  That was my thought of seeing how others solve it.  Initially, I also used brute force method (like Carlosdl) &amp; then developed the simple Excel/VB program.  Flame reminded the LCM process - which I totally forgot since the high school days!    I was not aware that LCM function is available in Excel.  I now know and used it --- so simper to use. 

I noticed Hendi used Java &amp; RoadDust used MOD function.   Is it possible to share the code - this will keep us informed of various techniques.  I am copying my Excel/VB code for others to critiques.  I set up Excel/VB to populate the number and the corresponding remainder values (from Row 10 and onwards).  Then I compared the remainder pattern with “987654321” to check if the number is found.
I do realize this is not the most elegant programming code! 

Sub DisplayNumber()
&#039;  Ctrl + Shft+ N  is the shortcut to Run this macro
&#039; Initial analysis reveals that the number must end with 9
&#039; Also start with 89 &amp; then increment by 90 so that remainder
&#039; by dividing with 9 will be 8.  This is just to save excessive display
&#039; You can start with 9 &amp; then increment by 10
X = 89
For I = 10 To 100
 Cells(I, 1) = X
 Y = 10
For J = 2 To 10
 C = Int(X / Y)
 R = X - (C * Y)
 Cells(I, J) = R
 Y = Y - 1
Next J
&#039;  Form the pattern &amp; compare with 9876...
   Cells(I, 11) = Cells(I, 2) &amp; Cells(I, 3) &amp; Cells(I, 4) &amp; Cells(I, 5) &amp; Cells(I, 6) &amp; Cells(I, 7) &amp; Cells(I, 8) &amp; Cells(I, 9) &amp; Cells(I, 10)
   If (Cells(I, 11) = &quot;987654321&quot;) Then Cells(I, 12) = &quot;Result&quot;
   X = X + 90
Next I

End Sub]]></description>
		<content:encoded><![CDATA[<p>Well  &#8230; it is nice to know that so many people got the number by different methods.  That was my thought of seeing how others solve it.  Initially, I also used brute force method (like Carlosdl) &amp; then developed the simple Excel/VB program.  Flame reminded the LCM process &#8211; which I totally forgot since the high school days!    I was not aware that LCM function is available in Excel.  I now know and used it &#8212; so simper to use. </p>
<p>I noticed Hendi used Java &amp; RoadDust used MOD function.   Is it possible to share the code &#8211; this will keep us informed of various techniques.  I am copying my Excel/VB code for others to critiques.  I set up Excel/VB to populate the number and the corresponding remainder values (from Row 10 and onwards).  Then I compared the remainder pattern with “987654321” to check if the number is found.<br />
I do realize this is not the most elegant programming code! </p>
<p>Sub DisplayNumber()<br />
&#8216;  Ctrl + Shft+ N  is the shortcut to Run this macro<br />
&#8216; Initial analysis reveals that the number must end with 9<br />
&#8216; Also start with 89 &amp; then increment by 90 so that remainder<br />
&#8216; by dividing with 9 will be 8.  This is just to save excessive display<br />
&#8216; You can start with 9 &amp; then increment by 10<br />
X = 89<br />
For I = 10 To 100<br />
 Cells(I, 1) = X<br />
 Y = 10<br />
For J = 2 To 10<br />
 C = Int(X / Y)<br />
 R = X &#8211; (C * Y)<br />
 Cells(I, J) = R<br />
 Y = Y &#8211; 1<br />
Next J<br />
&#8216;  Form the pattern &amp; compare with 9876&#8230;<br />
   Cells(I, 11) = Cells(I, 2) &amp; Cells(I, 3) &amp; Cells(I, 4) &amp; Cells(I, 5) &amp; Cells(I, 6) &amp; Cells(I, 7) &amp; Cells(I, 8) &amp; Cells(I, 9) &amp; Cells(I, 10)<br />
   If (Cells(I, 11) = &#8220;987654321&#8243;) Then Cells(I, 12) = &#8220;Result&#8221;<br />
   X = X + 90<br />
Next I</p>
<p>End Sub</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: roaddust</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/puzzle-find-the-number/#comment-59209</link>
		<dc:creator>roaddust</dc:creator>
		<pubDate>Thu, 15 Jan 2009 15:48:02 +0000</pubDate>
		<guid isPermaLink="false">#comment-59209</guid>
		<description><![CDATA[I used the MOD function with a For statement in VBA to find the same answer.

Dustin]]></description>
		<content:encoded><![CDATA[<p>I used the MOD function with a For statement in VBA to find the same answer.</p>
<p>Dustin</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: carlosdl</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/puzzle-find-the-number/#comment-59191</link>
		<dc:creator>carlosdl</dc:creator>
		<pubDate>Wed, 14 Jan 2009 20:44:37 +0000</pubDate>
		<guid isPermaLink="false">#comment-59191</guid>
		<description><![CDATA[Amazing, Flame.

I used a brute force algorithm, and got the same answer.]]></description>
		<content:encoded><![CDATA[<p>Amazing, Flame.</p>
<p>I used a brute force algorithm, and got the same answer.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: itke</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/puzzle-find-the-number/#comment-59185</link>
		<dc:creator>itke</dc:creator>
		<pubDate>Wed, 14 Jan 2009 19:23:09 +0000</pubDate>
		<guid isPermaLink="false">#comment-59185</guid>
		<description><![CDATA[Flame,

Going old school with the pencil and paper.

Nice

Sean]]></description>
		<content:encoded><![CDATA[<p>Flame,</p>
<p>Going old school with the pencil and paper.</p>
<p>Nice</p>
<p>Sean</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jennymack</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/puzzle-find-the-number/#comment-59184</link>
		<dc:creator>jennymack</dc:creator>
		<pubDate>Wed, 14 Jan 2009 18:42:00 +0000</pubDate>
		<guid isPermaLink="false">#comment-59184</guid>
		<description><![CDATA[Hi SbElectric,

Thanks for sharing this; I don&#039;t think there&#039;s anything wrong with the community helping to hone each other&#039;s skills. I&#039;ll have to try this later in Excel with VB as you mentioned. I&#039;d love to see how other members figure this one out. Feel free to post your methods here!

&lt;img src=&quot;http://itknowledgeexchange.techtarget.com/itke-community-blog/files/2008/11/jsignature.jpg&quot; alt=&quot;Jenny&quot; /&gt;
Community Moderator]]></description>
		<content:encoded><![CDATA[<p>Hi SbElectric,</p>
<p>Thanks for sharing this; I don&#8217;t think there&#8217;s anything wrong with the community helping to hone each other&#8217;s skills. I&#8217;ll have to try this later in Excel with VB as you mentioned. I&#8217;d love to see how other members figure this one out. Feel free to post your methods here!</p>
<p><img src="http://itknowledgeexchange.techtarget.com/itke-community-blog/files/2008/11/jsignature.jpg" alt="Jenny" /><br />
Community Moderator</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 3/10 queries in 0.043 seconds using memcached
Object Caching 369/375 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-05-22 12:50:01 -->