<?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: Palindrome Numbers</title>
	<atom:link href="http://blogs.mathworks.com/loren/2009/04/06/palindrome-numbers/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2009/04/06/palindrome-numbers/</link>
	<description>Loren Shure works on design of the MATLAB language at MathWorks. She writes here about once a week on MATLAB programming and related topics.</description>
	<lastBuildDate>Thu, 09 Feb 2012 04:19:21 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Dave S</title>
		<link>http://blogs.mathworks.com/loren/2009/04/06/palindrome-numbers/#comment-30394</link>
		<dc:creator>Dave S</dc:creator>
		<pubDate>Wed, 17 Jun 2009 05:44:11 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/04/06/palindrome-numbers/#comment-30394</guid>
		<description>Hi!  I know this is for MATLAB but I was very interested in doing this a different way.  I&#039;m using PHP to do the same thing.  I have a web page up to play with.  I used bcadd() and strrev() to find the palindrome and do the sums with infinite precision.

http://www.mrsankey.com/pal.php

I don&#039;t feel like escaping the code right now.  I&#039;m tired.  It wasn&#039;t that tricky.  Add and check, add and check, blah, blah...

We cannot assume that any of these numbers will not converge eventually, no matter how improbable.  The number 10715 converges after 547 iterations.  I haven&#039;t found a number that doesn&#039;t converge until you get above 1000 iterations.  There seemed to be a ceiling around 760.  Maybe we should offer a prize?</description>
		<content:encoded><![CDATA[<p>Hi!  I know this is for MATLAB but I was very interested in doing this a different way.  I&#8217;m using PHP to do the same thing.  I have a web page up to play with.  I used bcadd() and strrev() to find the palindrome and do the sums with infinite precision.</p>
<p><a href="http://www.mrsankey.com/pal.php" rel="nofollow">http://www.mrsankey.com/pal.php</a></p>
<p>I don&#8217;t feel like escaping the code right now.  I&#8217;m tired.  It wasn&#8217;t that tricky.  Add and check, add and check, blah, blah&#8230;</p>
<p>We cannot assume that any of these numbers will not converge eventually, no matter how improbable.  The number 10715 converges after 547 iterations.  I haven&#8217;t found a number that doesn&#8217;t converge until you get above 1000 iterations.  There seemed to be a ceiling around 760.  Maybe we should offer a prize?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Garrity</title>
		<link>http://blogs.mathworks.com/loren/2009/04/06/palindrome-numbers/#comment-30201</link>
		<dc:creator>Mike Garrity</dc:creator>
		<pubDate>Wed, 08 Apr 2009 19:53:15 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/04/06/palindrome-numbers/#comment-30201</guid>
		<description>Yes, 196, 295, 394, et al are called &quot;kin numbers&quot; and they converge on the same &quot;thread&quot;. The lowest number that leads to a thread is called the &quot;seed&quot;, so that would be 196 in this case. I think that the next seed after 879 is 1997. 

I&#039;ve been trying to come up with a good visual representation of the threads. It&#039;s tough because they&#039;re a very sparse set in a very big, linear space, but there are clearly some interesting patterns in how the threads are interwoven.</description>
		<content:encoded><![CDATA[<p>Yes, 196, 295, 394, et al are called &#8220;kin numbers&#8221; and they converge on the same &#8220;thread&#8221;. The lowest number that leads to a thread is called the &#8220;seed&#8221;, so that would be 196 in this case. I think that the next seed after 879 is 1997. </p>
<p>I&#8217;ve been trying to come up with a good visual representation of the threads. It&#8217;s tough because they&#8217;re a very sparse set in a very big, linear space, but there are clearly some interesting patterns in how the threads are interwoven.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yi Cao</title>
		<link>http://blogs.mathworks.com/loren/2009/04/06/palindrome-numbers/#comment-30199</link>
		<dc:creator>Yi Cao</dc:creator>
		<pubDate>Wed, 08 Apr 2009 16:18:29 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/04/06/palindrome-numbers/#comment-30199</guid>
		<description>Some numbers are clearly of this class. From 196, then 691, and 196+691=887. Then numbers, which can reach 887 are of this class, i.e. 196, 295, 394, 493, 592, 691, 788, 790 and 887. Further more, 689 and 986 this is because 689 + 986 = 1675 = 887 + 788. However, I do find another pair numerically, 879 and 978, which does not converge to (887, 788) pairs quickly.</description>
		<content:encoded><![CDATA[<p>Some numbers are clearly of this class. From 196, then 691, and 196+691=887. Then numbers, which can reach 887 are of this class, i.e. 196, 295, 394, 493, 592, 691, 788, 790 and 887. Further more, 689 and 986 this is because 689 + 986 = 1675 = 887 + 788. However, I do find another pair numerically, 879 and 978, which does not converge to (887, 788) pairs quickly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2009/04/06/palindrome-numbers/#comment-30198</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Wed, 08 Apr 2009 15:07:39 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/04/06/palindrome-numbers/#comment-30198</guid>
		<description>Another way to work with these numbers is via the Symbolic Math Toolbox.

&lt;pre class=&quot;code&quot;&gt;
reversechars = @(x) sym(fliplr(char(x)))
x = sym(124)
x = x+reversechars(x)
...
&lt;/pre&gt;

--Loren</description>
		<content:encoded><![CDATA[<p>Another way to work with these numbers is via the Symbolic Math Toolbox.</p>
<pre class="code">
reversechars = @(x) sym(fliplr(char(x)))
x = sym(124)
x = x+reversechars(x)
...
</pre>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel</title>
		<link>http://blogs.mathworks.com/loren/2009/04/06/palindrome-numbers/#comment-30197</link>
		<dc:creator>Daniel</dc:creator>
		<pubDate>Wed, 08 Apr 2009 14:48:38 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/04/06/palindrome-numbers/#comment-30197</guid>
		<description>@Mike
Yeah, my actual code has a test in it to detect precision problems. For starting numbers less than 10000, precision was not a problem.


BTW, shouldn&#039;t one be able to speed things up by alot if one used not one digit per piece but as many as can be fit in a 32-bit number. Then you just check if you have a carry on the most significant digit... just a thought.</description>
		<content:encoded><![CDATA[<p>@Mike<br />
Yeah, my actual code has a test in it to detect precision problems. For starting numbers less than 10000, precision was not a problem.</p>
<p>BTW, shouldn&#8217;t one be able to speed things up by alot if one used not one digit per piece but as many as can be fit in a 32-bit number. Then you just check if you have a carry on the most significant digit&#8230; just a thought.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: matt fig</title>
		<link>http://blogs.mathworks.com/loren/2009/04/06/palindrome-numbers/#comment-30195</link>
		<dc:creator>matt fig</dc:creator>
		<pubDate>Tue, 07 Apr 2009 16:30:01 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/04/06/palindrome-numbers/#comment-30195</guid>
		<description>I think John D&#039;Errico&#039;s variable precision integer toolbox could come in handy for large numbers!</description>
		<content:encoded><![CDATA[<p>I think John D&#8217;Errico&#8217;s variable precision integer toolbox could come in handy for large numbers!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Garrity</title>
		<link>http://blogs.mathworks.com/loren/2009/04/06/palindrome-numbers/#comment-30194</link>
		<dc:creator>Mike Garrity</dc:creator>
		<pubDate>Tue, 07 Apr 2009 12:32:24 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/04/06/palindrome-numbers/#comment-30194</guid>
		<description>Yes, your version is faster, but you need to worry about the fact that the numbers can get very large when you&#039;re doing this. For example, try this starting value: 1000689. It should take 78 turns to converge on 796,589,884,324,966,945,646,549,669,423,488,985,697. If you store that in a double precision number, you&#039;ll only get the first 16 digits. You can&#039;t check whether it&#039;s a palindrome without having all 39 digits. 

It is possible to get your approach to work, but you&#039;ll need to detect when you&#039;re about to start losing precision and break your number into pieces. I found it easier to just start out with the number in pieces. Of course my version is using a double precision value to represent each digit. That&#039;s obviously overkill. You really only need ~3.3 bits per digit rather than 64.</description>
		<content:encoded><![CDATA[<p>Yes, your version is faster, but you need to worry about the fact that the numbers can get very large when you&#8217;re doing this. For example, try this starting value: 1000689. It should take 78 turns to converge on 796,589,884,324,966,945,646,549,669,423,488,985,697. If you store that in a double precision number, you&#8217;ll only get the first 16 digits. You can&#8217;t check whether it&#8217;s a palindrome without having all 39 digits. </p>
<p>It is possible to get your approach to work, but you&#8217;ll need to detect when you&#8217;re about to start losing precision and break your number into pieces. I found it easier to just start out with the number in pieces. Of course my version is using a double precision value to represent each digit. That&#8217;s obviously overkill. You really only need ~3.3 bits per digit rather than 64.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel</title>
		<link>http://blogs.mathworks.com/loren/2009/04/06/palindrome-numbers/#comment-30192</link>
		<dc:creator>Daniel</dc:creator>
		<pubDate>Tue, 07 Apr 2009 06:58:53 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/04/06/palindrome-numbers/#comment-30192</guid>
		<description>It seems that just below every multiple of 100 there is at least one non-converging. Numbers just above an even multiple of 100 are either palindrome themselves or become so fast.</description>
		<content:encoded><![CDATA[<p>It seems that just below every multiple of 100 there is at least one non-converging. Numbers just above an even multiple of 100 are either palindrome themselves or become so fast.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel</title>
		<link>http://blogs.mathworks.com/loren/2009/04/06/palindrome-numbers/#comment-30191</link>
		<dc:creator>Daniel</dc:creator>
		<pubDate>Tue, 07 Apr 2009 06:28:43 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/04/06/palindrome-numbers/#comment-30191</guid>
		<description>Well, with all due respectr, improving on that code wasn&#039;t too difficult. The way you convert numbers to arrays and then implement your own addition isn&#039;t very efficient. I used a trick Loren mentioned a while back to use the string manipulation functions. 

I also removed all error handling to clarify the actual algorithm. This code (with error checking) runs about twice as fast as the code above. As almost all time is spent in the reverseNum(), I believe the speed can be halved once again by calling it only once per iteration and cacheing the result.

&lt;code&gt;&lt;pre&gt;
function [n p] = pal196(in)
    n = 0;
    a = fix(in);
    while ~all(a == reverseNum(a))
        a = a + reverseNum(a);
        n = n+1;
    end    
end

function [ a ] = reverseNum( b )
    string = num2str( b );
    a = str2double(string(end:-1:1));
end
&lt;/pre&gt;&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Well, with all due respectr, improving on that code wasn&#8217;t too difficult. The way you convert numbers to arrays and then implement your own addition isn&#8217;t very efficient. I used a trick Loren mentioned a while back to use the string manipulation functions. </p>
<p>I also removed all error handling to clarify the actual algorithm. This code (with error checking) runs about twice as fast as the code above. As almost all time is spent in the reverseNum(), I believe the speed can be halved once again by calling it only once per iteration and cacheing the result.</p>
<p><code>
<pre>
function [n p] = pal196(in)
    n = 0;
    a = fix(in);
    while ~all(a == reverseNum(a))
        a = a + reverseNum(a);
        n = n+1;
    end
end

function [ a ] = reverseNum( b )
    string = num2str( b );
    a = str2double(string(end:-1:1));
end
</pre>
<p></p></code></p>
]]></content:encoded>
	</item>
</channel>
</rss>

