Euler txt files now follow naming convention

main
Felix Martin 2021-04-22 15:17:19 -04:00
parent 5be3b11e54
commit 7825acbd73
21 changed files with 11 additions and 10 deletions

View File

@ -3,7 +3,7 @@ def get_score_for_name(name):
def euler_022():
with open('../txt/EulerProblem022.txt', 'r') as f:
with open('../txt/e022.txt', 'r') as f:
names = f.read().split(',')
names.sort()
s = sum([(i + 1) * get_score_for_name(name)
@ -15,3 +15,4 @@ if __name__ == "__main__":
assert(get_score_for_name('COLIN') == 53)
assert(euler_022() == 871198282)
print("e022.py: {}".format(euler_022()))

View File

@ -1,5 +1,5 @@
def get_words():
with open("../txt/EulerProblem042.txt", "r") as f:
with open("../txt/e042.txt", "r") as f:
s = f.read()
words = [w.strip('"') for w in s.split(",")]
return words

View File

@ -110,7 +110,7 @@ def read_hands():
in the tuple represents a hand.
"""
hands = []
with open("../txt/EulerProblem054.txt", "r") as f:
with open("../txt/e054.txt", "r") as f:
for line in f.readlines():
cards = line.strip().split(" ")
hands.append((cards[:5], cards[5:]))

View File

@ -1,12 +1,12 @@
def get_encrypted_msg():
with open("../txt/EulerProblem059.txt", "r") as f:
with open("../txt/e059.txt", "r") as f:
msg = [int(d) for d in f.read().split(',')]
return msg
def get_words():
with open("../txt/EulerProblem042.txt", "r") as f:
with open("../txt/e042.txt", "r") as f:
words = [w.strip('"') for w in f.read().split(",")]
return set(words)

View File

@ -2,7 +2,7 @@ from e018 import find_greatest_path_sum_in_triangle_string
def euler_067():
with open("../txt/EulerProblem067.txt") as f:
with open("../txt/e067.txt") as f:
return find_greatest_path_sum_in_triangle_string(f.read())

View File

@ -72,7 +72,7 @@ def add_single_digit(code, digit):
def euler_079():
tests()
with open("../txt/EulerProblem079.txt", "r") as f:
with open("../txt/e079.txt", "r") as f:
passcodes = sorted(list(set([line.strip() for line in f])))
codes = [""]

View File

@ -3,7 +3,7 @@ from lib_a_star import A_Star
def get_grid():
with open("../txt/EulerProblem081.txt", "r") as f:
with open("../txt/e081.txt", "r") as f:
grid = list(map(lambda line: list(map(int, line.split(","))),
f.readlines()))
return grid

View File

@ -63,7 +63,7 @@ def save_characters(numeral):
def euler_089():
tests()
with open("../txt/EulerProblem089.txt") as f:
with open("../txt/e089.txt") as f:
numerals = map(lambda l: l.strip(), f.readlines())
return sum(map(save_characters, numerals))

View File

@ -6,7 +6,7 @@ def exp_log(base, power):
def read_exps():
with open("../txt/EulerProblem099.txt", "r") as f:
with open("../txt/e099.txt", "r") as f:
return [(exp_log(int(s[0]), int(s[1])), i + 1)
for i, line in enumerate(f.readlines())
if (s := line.split(","))]