1 Star 0 Fork 0

阿坚/projecteuler

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
p099.py 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
阿坚 提交于 2022-06-09 23:57 . 99,doned
"""
Problem 99: https://projecteuler.net/problem=99
Comparing two numbers written in index form like 2'11 and 3'7 is not difficult, as any
calculator would confirm that 2^11 = 2048 < 3^7 = 2187.
However, confirming that 632382^518061 > 519432^525806 would be much more difficult, as
both numbers contain over three million digits.
Using base_exp.txt, a 22K text file containing one thousand lines with a base/exponent
pair on each line, determine which line number has the greatest numerical value.
"""
# _*_ conding:UTF-8 _*_
'''
@author = Kuperain
@email = kuperain@aliyun.com
@IDE = VSCODE Python3.8.3
@creat_time = 2022/6/9
'''
from math import log10
DataFile = 'p099_base_exp.txt'
def readData(filepath: str = DataFile) -> list:
data = []
with open(filepath, 'r') as fp:
for line in fp:
linedata = eval('[' + line.strip() + ']')
data.append(linedata)
return data
Data = readData(DataFile)
def solution(data: list = Data):
res = (0, data[0][1]*log10(data[0][0]))
for i in range(1, len(data)):
tmp = data[i][1]*log10(data[i][0])
if tmp > res[1]:
res = (i, tmp)
return res[0]+1, data[res[0]] # line = 1,2,3...
if __name__ == "__main__":
import doctest
doctest.testmod(verbose=False)
print(solution())
# (709, [895447, 504922])
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/kuperain/projecteuler.git
git@gitee.com:kuperain/projecteuler.git
kuperain
projecteuler
projecteuler
master

搜索帮助