mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-30 16:31:08 +00:00
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
This commit is contained in:
parent
8107548cc1
commit
0e3357ae35
0
project_euler/problem_99/__init__.py
Normal file
0
project_euler/problem_99/__init__.py
Normal file
1000
project_euler/problem_99/base_exp.txt
Normal file
1000
project_euler/problem_99/base_exp.txt
Normal file
File diff suppressed because it is too large
Load Diff
33
project_euler/problem_99/sol1.py
Normal file
33
project_euler/problem_99/sol1.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
"""
|
||||
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())
|
Loading…
Reference in New Issue
Block a user