<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Code Puzzle #1 - Solution</title><link>http://weblogs.asp.net/jgalloway/archive/2006/11/08/Code-Puzzle-_2300_1-_2D00_-Solution.aspx</link><description>If you haven't read the puzzle, you can read more about it on my previous post . The questions: (Answer this first) Take a guess - how many numbers do you think there are between 1 and 1 million that are divisible by their reverse. Any? Fifty? A thousand</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>re: Code Puzzle #1 - Solution</title><link>http://weblogs.asp.net/jgalloway/archive/2006/11/08/Code-Puzzle-_2300_1-_2D00_-Solution.aspx#7277823</link><pubDate>Sun, 13 Dec 2009 15:31:06 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7277823</guid><dc:creator>youtubeline</dc:creator><author>youtubeline</author><description>&lt;p&gt;I had to write it in Ruby, as that's the language I'm trying to gain proficiency in.&lt;/p&gt;
&lt;p&gt;It doesn't run fast, but it was fast to code :).&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7277823" width="1" height="1"&gt;</description></item><item><title>string puzzle solution</title><link>http://weblogs.asp.net/jgalloway/archive/2006/11/08/Code-Puzzle-_2300_1-_2D00_-Solution.aspx#6270447</link><pubDate>Thu, 12 Jun 2008 14:45:27 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6270447</guid><dc:creator>string puzzle solution</dc:creator><author>string puzzle solution</author><description>&lt;p&gt;Pingback from &amp;nbsp;string puzzle solution&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6270447" width="1" height="1"&gt;</description></item><item><title>re: Code Puzzle #1 - Solution</title><link>http://weblogs.asp.net/jgalloway/archive/2006/11/08/Code-Puzzle-_2300_1-_2D00_-Solution.aspx#4240514</link><pubDate>Sat, 29 Sep 2007 06:37:52 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:4240514</guid><dc:creator>Mark Tolonen</dc:creator><author>Mark Tolonen</author><description>&lt;p&gt;From the Python command prompt:&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt;&amp;gt; for n in xrange(1000000):&lt;/p&gt;
&lt;p&gt;... 	if n%10==0: continue&lt;/p&gt;
&lt;p&gt;... 	r=int(str(n)[::-1])&lt;/p&gt;
&lt;p&gt;... 	if n==r: continue&lt;/p&gt;
&lt;p&gt;... 	if n%r==0: print n&lt;/p&gt;
&lt;p&gt;... 	&lt;/p&gt;
&lt;p&gt;8712&lt;/p&gt;
&lt;p&gt;9801&lt;/p&gt;
&lt;p&gt;87912&lt;/p&gt;
&lt;p&gt;98901&lt;/p&gt;
&lt;p&gt;879912&lt;/p&gt;
&lt;p&gt;989901&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=4240514" width="1" height="1"&gt;</description></item><item><title>re: Code Puzzle #1 - Solution</title><link>http://weblogs.asp.net/jgalloway/archive/2006/11/08/Code-Puzzle-_2300_1-_2D00_-Solution.aspx#2510101</link><pubDate>Sun, 06 May 2007 20:21:57 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:2510101</guid><dc:creator>Jon Galloway</dc:creator><author>Jon Galloway</author><description>&lt;p&gt;@angel - The answer is a pearl. &lt;a rel="nofollow" target="_new" href="http://dan.hersam.com/riddles.html"&gt;http://dan.hersam.com/riddles.html&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2510101" width="1" height="1"&gt;</description></item><item><title>a little help please</title><link>http://weblogs.asp.net/jgalloway/archive/2006/11/08/Code-Puzzle-_2300_1-_2D00_-Solution.aspx#2509319</link><pubDate>Sun, 06 May 2007 17:34:09 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:2509319</guid><dc:creator>angel</dc:creator><author>angel</author><description>&lt;p&gt;hi your website is very nice i want a little sorry the solution for this puzzle&lt;/p&gt;
&lt;p&gt;&amp;quot;I live in water,if you cut my head iam at your door,if you cut my tail iam a fruit , if you cut both then iam with you&amp;quot;&lt;/p&gt;
&lt;p&gt;please send me the solution for this &lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2509319" width="1" height="1"&gt;</description></item><item><title>re: Code Puzzle #1 - Solution</title><link>http://weblogs.asp.net/jgalloway/archive/2006/11/08/Code-Puzzle-_2300_1-_2D00_-Solution.aspx#969582</link><pubDate>Mon, 20 Nov 2006 17:46:08 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:969582</guid><dc:creator>Jon Galloway</dc:creator><author>Jon Galloway</author><description>&lt;p&gt;@Helen - Take a look at the puzzle rules. I didn't &amp;nbsp;include them since I don't consider 001 a valid number. I'm sure James Bond might take issue with that.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=969582" width="1" height="1"&gt;</description></item><item><title>re: Code Puzzle #1 - Solution</title><link>http://weblogs.asp.net/jgalloway/archive/2006/11/08/Code-Puzzle-_2300_1-_2D00_-Solution.aspx#969375</link><pubDate>Mon, 20 Nov 2006 17:03:56 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:969375</guid><dc:creator>Helen</dc:creator><author>Helen</author><description>&lt;p&gt;Shouldn't you be getting results like 100 is divisible by 001? &lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=969375" width="1" height="1"&gt;</description></item><item><title>re: Code Puzzle #1 - Solution</title><link>http://weblogs.asp.net/jgalloway/archive/2006/11/08/Code-Puzzle-_2300_1-_2D00_-Solution.aspx#944471</link><pubDate>Fri, 17 Nov 2006 06:29:27 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:944471</guid><dc:creator>Scott Patten</dc:creator><author>Scott Patten</author><description>&lt;p&gt;Fun puzzle!&lt;/p&gt;
&lt;p&gt;I had to write it in Ruby, as that's the language I'm trying to gain proficiency in.&lt;/p&gt;
&lt;p&gt;It doesn't run fast, but it was fast to code :).&lt;/p&gt;
&lt;p&gt;#!/usr/bin/env ruby&lt;/p&gt;
&lt;p&gt;class Integer&lt;/p&gt;
&lt;p&gt; &amp;nbsp;def reverse&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;r = &amp;quot;#{self}&amp;quot;.reverse&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;return nil if r =~ /^0/ or r.to_i == self&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;return r.to_i&lt;/p&gt;
&lt;p&gt; &amp;nbsp;end&lt;/p&gt;
&lt;p&gt;end&lt;/p&gt;
&lt;p&gt;biggest = 1000000&lt;/p&gt;
&lt;p&gt;(1 .. biggest).each do |n|&lt;/p&gt;
&lt;p&gt; &amp;nbsp;if n.reverse&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;puts n if n % n.reverse == 0&lt;/p&gt;
&lt;p&gt; &amp;nbsp;end&lt;/p&gt;
&lt;p&gt;end&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=944471" width="1" height="1"&gt;</description></item><item><title>re: Code Puzzle #1 - Solution</title><link>http://weblogs.asp.net/jgalloway/archive/2006/11/08/Code-Puzzle-_2300_1-_2D00_-Solution.aspx#891593</link><pubDate>Thu, 09 Nov 2006 12:58:39 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:891593</guid><dc:creator>Mikael Kjellqvist</dc:creator><author>Mikael Kjellqvist</author><description>&lt;p&gt;Just wanted to point out a small 'error' in the otherwise very nice function Reverse(Integer).&lt;/p&gt;
&lt;p&gt;Function Reverse(ByVal n As Integer) As Integer&lt;/p&gt;
&lt;p&gt; &amp;nbsp; Dim rev As Integer = 0&lt;/p&gt;
&lt;p&gt; &amp;nbsp; While n &amp;gt; 0&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; rev = rev * 10 + (n Mod 10)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; n = n \ 10&lt;/p&gt;
&lt;p&gt; &amp;nbsp; End While&lt;/p&gt;
&lt;p&gt; &amp;nbsp; Return rev&lt;/p&gt;
&lt;p&gt;End Function&lt;/p&gt;
&lt;p&gt;Try calling the Reverse function with the number 581. the result will not be whats expected.&lt;/p&gt;
&lt;p&gt;This is becouse 58 / 10 does not return 5, but instead is rounder up to 6.&lt;/p&gt;
&lt;p&gt;One solution is to change the line to:&lt;/p&gt;
&lt;p&gt;n = Math.floor(n \ 10)&lt;/p&gt;
&lt;p&gt;I liked the puzzle btw :)&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=891593" width="1" height="1"&gt;</description></item><item><title>re: Code Puzzle #1 - Solution</title><link>http://weblogs.asp.net/jgalloway/archive/2006/11/08/Code-Puzzle-_2300_1-_2D00_-Solution.aspx#890614</link><pubDate>Thu, 09 Nov 2006 08:09:53 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:890614</guid><dc:creator>Haacked</dc:creator><author>Haacked</author><description>&lt;p&gt;Another interesting property of those numbers is that they all are divisible by 9.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=890614" width="1" height="1"&gt;</description></item></channel></rss>