Largest palindrome product

Problem 4

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99.

Find the largest palindrome made from the product of two 3-digit numbers.

The python code is as follows:

def isPalindromic(data):
list = []
while data > 10:
list.append(data%10)
data = int(data/10)
list.append(data)
print(list)
i = 0
j = len(list)-1
while i < j:
if list[i] != list[j]:
return False
i += 1
j -= 1
return True a = 999
total = 0
result = 0
targetA = 0
targetB = 0
while a >= 100:
b = 999
if a*b < result:
break
while b >= 100:
total = a*b
if total < result:
break
if isPalindromic(total):
result = total
targetA = a
targetB = b
b -= 1
a -= 1 print(result)
print(targetA)
print(targetB)

  Assuming b is large than a, we can rewrite the code like this:

def isPalindromic(data):
list = []
while data > 10:
list.append(data%10)
data = int(data/10)
list.append(data)
print(list)
i = 0
j = len(list)-1
while i < j:
if list[i] != list[j]:
return False
i += 1
j -= 1
return True a = 999
total = 0
result = 0
targetA = 0
targetB = 0
while a >= 100:
b = 999
if a*b < result:
break
while b >= a:
total = a*b
if total < result:
break
if isPalindromic(total):
result = total
targetA = a
targetB = b
b -= 1
a -= 1 print(result)
print(targetA)
print(targetB)

  

Project Euler Problem4的更多相关文章

  1. [project euler] program 4

    上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...

  2. Python练习题 029:Project Euler 001:3和5的倍数

    开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...

  3. Project Euler 9

    题意:三个正整数a + b + c = 1000,a*a + b*b = c*c.求a*b*c. 解法:可以暴力枚举,但是也有数学方法. 首先,a,b,c中肯定有至少一个为偶数,否则和不可能为以上两个 ...

  4. Project Euler 44: Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.

    In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentago ...

  5. project euler 169

    project euler 169 题目链接:https://projecteuler.net/problem=169 参考题解:http://tieba.baidu.com/p/2738022069 ...

  6. 【Project Euler 8】Largest product in a series

    题目要求是: The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × ...

  7. Project Euler 第一题效率分析

    Project Euler: 欧拉计划是一系列挑战数学或者计算机编程问题,解决这些问题需要的不仅仅是数学功底. 启动这一项目的目的在于,为乐于探索的人提供一个钻研其他领域并且学习新知识的平台,将这一平 ...

  8. Python练习题 049:Project Euler 022:姓名分值

    本题来自 Project Euler 第22题:https://projecteuler.net/problem=22 ''' Project Euler: Problem 22: Names sco ...

  9. Python练习题 048:Project Euler 021:10000以内所有亲和数之和

    本题来自 Project Euler 第21题:https://projecteuler.net/problem=21 ''' Project Euler: Problem 21: Amicable ...

随机推荐

  1. 101空降师506团2营E连全体成员

    吕天一 https://coding.net/u/Richardlv http://www.cnblogs.com/Richardlv/ 李伟亮 https://coding.net/u/201304 ...

  2. php实现文件上传,下载的常见文件配置

    配置文件,php.ini uploadfile  post_max_size 规定表单上传的最大文件:

  3. Prometheus 和 Grafana的简单学习

    1. 下载 暂时不采用 docker化部署 prometheus下载地址 https://github.com/prometheus/prometheus/releases/ prometheus的e ...

  4. memcache安装以及php_memcache.dll 扩展安装

    php_memcache.dll扩展下载地址:http://windows.php.net/downloads/pecl/releases/memcache/3.0.8/ 下载注意事项:选择匹配自己环 ...

  5. jmeter之 jp@gc - Stepping Thread Group

    1.   安装好插件 参考文档“扩展Jmeter插件获取更多监听器” 2.   添加线程组 右键测试计划->添加->Threads(Users)->jp@gc - Stepping ...

  6. MT【198】连乘积放缩

    (2018中科大自招最后一题)设$a_1=1,a_{n+1}=\left(1+\dfrac{1}{n}\right)^3(n+a_n)$证明:(1)$a_n=n^3\left(1+\sum\limit ...

  7. 内置函数sorted()

    这里顺便说一下sorted()和sort()的异同. sort 是 list 中的方法,只能对列表排序:sorted 可以对所有可迭代对象进行排序. list 的 sort 方法是对原列表进行操作,而 ...

  8. 部署tms过程记录

    背景:工作中经常需要进行工程部署,将过程记录下来,减少不必要的时间浪费. 1 问题总结 dubbo服务启动注册报 java.net.UnknownHostException 未知的名称或服务解决办法 ...

  9. Json对象与Json字符串

  10. 【CSS】盒子模型的计算

    1.标准盒子的尺寸计算 盒子自身的尺寸:内容的宽高+两侧内边距+两侧边框 盒子在页面中占位的尺寸:内容的宽高+两侧内边距+两侧边框+两侧外边距 <!DOCTYPE html> <ht ...