-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathsolution_1.py
More file actions
44 lines (35 loc) · 1.07 KB
/
solution_1.py
File metadata and controls
44 lines (35 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
# coding=utf-8
#
# Python Script
#
# Copyleft © Manoel Vilela
#
#
"""
Largest exponential
Problem 99
Comparing two numbers written in index form like 211 and 37 is not difficult,
as any calculator would confirm that 211 = 2048 < 37 = 2187.
However, confirming that 632382518061 > 519432525806
would be much more difficult, as both numbers
contain over three million digits.
Using base_exp.txt (right click and 'Save Link/Target As...'),
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.
"""
from math import log
from os.path import dirname, join
filedic = join('../p099_base_exp.txt')
dic_evalued = {}
with open(filedic, 'r') as f:
nums = f.readlines()
for line in range(len(nums)):
num = nums[line].strip()
base, exp = num.split(',')
value = log(int(base)) * int(exp)
dic_evalued[value] = line + 1
print(dic_evalued[max(dic_evalued)])