Comments on: Largest Palindromic Number In Python https://pthree.org/2007/09/15/largest-palindromic-number-in-python/ Linux. GNU. Freedom. Thu, 15 Feb 2018 18:04:15 +0000 hourly 1 https://wordpress.org/?v=5.0-alpha-42199 By: Nicholas https://pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-116874 Fri, 31 Aug 2012 16:14:52 +0000 http://www.pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-116874 Another thing to remember: If you want a number that starts with 9, and it's a palindrome, you should only try numbers that can come out with 9's if you follow a multiplication table. That means only try with the following sets in the last slot: {1,9},{3,3},{7,7}
If that doesn't work, you'll need to do the same thing with 8s and stop incrementing as soon as the result goes over 900,000, and so on in that order until all humans are eaten.

]]>
By: vince https://pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-109856 Mon, 16 Mar 2009 19:47:23 +0000 http://www.pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-109856 actually, you only perform 900 * 900

]]>
By: vince https://pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-109855 Mon, 16 Mar 2009 19:46:54 +0000 http://www.pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-109855 Actually, you only perform 900 * 900 my mistake.

]]>
By: vince https://pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-109854 Mon, 16 Mar 2009 19:45:57 +0000 http://www.pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-109854 999 * 999 = 998001 iterations through every number, but I will be testing each one at least twice, so I only need to test half.

This point is an error if you consider the first one where you only go until 100.

Following your first point, means that you only do 999 * 900 iterations as opposed to 999 * 999. Why? you stop at 100. This means that you don't consider 999 * 99, 999 * 98, and so on.

Remember: the number of digits from 100 to 999 = (999 - 100) + 1 = 900.

]]>
By: leed https://pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-108855 Sun, 26 Oct 2008 09:29:02 +0000 http://www.pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-108855 I think follow code is the fastest I have tried.
maxnum = 0
for i in range(990, 99, -11):
for j in range(999, i, -1):
num = i * j
if num <= maxnum:
break
else:
strnum = str(num)
if strnum == strnum[::-1]:
maxnum = num
break
print maxnum

]]>
By: i dont know https://pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-107970 Thu, 11 Sep 2008 15:50:14 +0000 http://www.pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-107970 what's are biggest 2 3-dgits palindrome?

]]>
By: Athropos https://pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-69317 Sun, 16 Sep 2007 12:52:44 +0000 http://www.pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-69317 You should use the timeit module when you need to time something. It's better than using the time command because you then don't measure the startup time of the Python interpreter which can be a big part of the total time.

1
2
3
4
5
6
import timeit

...

t1 = timeit.Timer('palindrome()', 'from __main__ import palindrome')
print t1.timeit(20)
]]>
By: phoenyx https://pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-69305 Sun, 16 Sep 2007 09:13:16 +0000 http://www.pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-69305 FYI, it's considered bad form to post answers to problems outside of the forum.

]]>
By: Duccio https://pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-69298 Sun, 16 Sep 2007 07:38:38 +0000 http://www.pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-69298 Good post...only a doubt.
When you reach the column of the table of multiple of 11 (990,979,etc.) i think you must multiplicate this number for all the numbers smaller than this, and not only for multiple of 11 smaller than this. For example I don't see 990*989,990*988,etc. that are multiple of 11 too. Don't you think?

]]>
By: Aaron https://pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-69283 Sun, 16 Sep 2007 02:56:05 +0000 http://www.pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-69283 @Peter- Ahh, yes. Good call. I've updated my post to reflect the change.

@Seth- No problem. Let me know how far you get. 🙂

]]>
By: Seth https://pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-69279 Sun, 16 Sep 2007 02:23:25 +0000 http://www.pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-69279 Never seen Project Euler before. Thanks for posting about it. 🙂

]]>
By: Peter https://pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-69277 Sun, 16 Sep 2007 02:06:38 +0000 http://www.pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-69277 A few thoughts:

- 5 digit palindromes are not necessarily divisible by 11, though that doesn't matter too much here as we're looking for 6 digit ones
abcba = 10001a + 1010b + 100c

- quick one liner (takes a few seconds here)

1
max([x*y for x in range(100,1000) for y in range(100,1000) if str(x*y)==str(x*y)[::-1]])
]]>
By: Justin https://pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-69256 Sat, 15 Sep 2007 23:19:13 +0000 http://www.pthree.org/2007/09/15/largest-palindromic-number-in-python/#comment-69256
1
2
3
def is_palin(num):
    s = str(num)
    return s == s[::-1]
]]>