Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: PE help Date: Tue, 9 Nov 2010 03:57:03 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 33 Message-ID: <ibagqf$muk$1@fred.mathworks.com> References: <iba7po$kd0$1@fred.mathworks.com> <ibaa8h$q5b$1@fred.mathworks.com> <ibabus$eg6$1@fred.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: webapp-03-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1289275023 23508 172.30.248.38 (9 Nov 2010 03:57:03 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Tue, 9 Nov 2010 03:57:03 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1187260 Xref: news.mathworks.com comp.soft-sys.matlab:684977 "proecsm " <proecsm@gmail.com> wrote in message <ibabus$eg6$1@fred.mathworks.com>... > "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <ibaa8h$q5b$1@fred.mathworks.com>... > > "proecsm " <proecsm@gmail.com> wrote in message <iba7po$kd0$1@fred.mathworks.com>... > > > I am working on Project Euler # 55 and have code that give a 'tantilizingly' close answer to the generally accepted answer. It matches the first 45 terms given in OEIS, but am wondering if I am missing something from the int2str conversions or precision issues. I am only missing a few terms... > > > > > > <pre> > > > for n = 100:10000 > > > snum = int2str(n); > > > c = 0; > > > while ~all(snum-fliplr(snum)==0) > > > > > > c=c+1; > > > snum = int2str(str2double(snum)+str2double(fliplr(snum))); > > > > > > if c > 50 > > > lychrel = [lychrel n]; %#ok<*AGROW> > > > break > > > end > > > end > > > end > > > <\pre> > > - - - - - - - - - - > > If you multiply 10000 * 2^50, that gives a number in the neighborhood of 1e19, and that lies beyond the range of integers that double can represent exactly. You may have thought some of the numbers were not lychrel because of round off errors. > > > > Roger Stafford > > Thanks Roger, I will investigate using the symbolic toolbox or maple :( If anyone knows of a longer list of (potential) lychrel numbers that I can compare my results to, I'd be interested. I suspect they would be at the upper end of the range, however the number 89 (which I used for debug purposes) defies that assumption... > > thanks for the help - - - - - - - - - - One other observation. I think you would miss the lychrel number 4774 and other palindromes like it because you compare a number with its reversed form before having performed the first step in addition. You need to ensure that your while-loop takes at least one step before exiting. Roger Stafford