Python/project_euler/problem_99/sol1.py
vinayak 0e3357ae35
added solution 1 for problem_99 in project_euler (#1545)
* Create sol1.py

* Create __init__.py

* Update sol1.py

* corrected range

* Add files via upload

* Update DIRECTORY.md

* Create sol1.py

* Update sol1.py

* Create __init__.py

* Update DIRECTORY.md

* Delete isotonic.py

* Update sol1.py

* Problem_27_project_euler

* project_euler/Problem_27/sol1.py

* project_euler/Problem_27/sol1.py

* project_euler/problem_27/

* project_euler/problem_27

* project_euler/problem_27

* update sol1 of Euler Problem 27 solution script Added

* Remove slow test, wrap long comments, format with psf/black

* Delete __init__.py

* Add type hints

* Add doctests to function is_prime()

* Rename project_euler/problem_27/project_euler/problem_27/sol1.pysol1.py to project_euler/problem_27/problem_27_sol1.py

* Added Problem 33

* added solution 1 for problem_99

* update added solution 1 for problem_99

* update

* Update sol1.py
2019-11-01 13:57:16 +05:30

34 lines
1.0 KiB
Python

"""
Problem:
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.
NOTE: The first two lines in the file represent the numbers in the example given above.
"""
import os
from math import log10
def find_largest(data_file: str="base_exp.txt") -> int:
"""
>>> find_largest()
709
"""
largest = [0, 0]
for i, line in enumerate(
open(os.path.join(os.path.dirname(__file__), data_file))
):
a, x = list(map(int, line.split(",")))
if x * log10(a) > largest[0]:
largest = [x * log10(a), i + 1]
return largest[1]
if __name__ == "__main__":
print(find_largest())