【发布时间】:2011-09-18 09:13:29
【问题描述】:
我想通过两个 3 位数字相乘得到最大的回文数。
我从 a 和 b 都为 999 开始,并随着每次乘法的发生而递减 a 和 b。
a = 999 #Defining Variables
b = 999
for i in range (1000):
c= a*b #multiply a to b
if int(str(c)[::-1]) == c:
print c
a = a-1 #decrement the value of a
c=a*b #multiply a by the decremented a
if int(str(c)[::-1]) == c:
print c
b = b-1 #decrement b so that both a and b have been decremented
结果出现了 698896、289982、94249、69696...,其中 698896 是第一个数字。目前我仍在试图找出我缺少什么。
【问题讨论】:
-
不检查是一位数还是两位数。除非您将 010...090 视为三位数(但在这种情况下需要额外的代码:])
-
多么糟糕的cmets! “
c= a*b #multiply a to b”?什么样的程序员需要向他们解释这一行? -
感谢您专注于我的 cmets 而不是糟糕的代码:P 我认为这至少有助于理解我创造的可憎之物。
-
仅供参考,这是项目欧拉问题 #4...
-
@Rosh Oxymoron 感谢您让我查找 INTERCAL:D
标签: python palindrome