Corrected path for input file

This commit is contained in:
David Doblas Jiménez 2022-08-18 10:46:57 +02:00
parent ed8107e84c
commit d5fdd2a8fd
4 changed files with 17 additions and 12 deletions

View File

@ -10,6 +10,7 @@ https://projecteuler.net/problem=54
""" """
from pathlib import Path from pathlib import Path
from utils import timeit from utils import timeit
@ -115,7 +116,7 @@ def compute():
replace_map = {"T": 10, "J": 11, "Q": 12, "K": 13, "A": 14} replace_map = {"T": 10, "J": 11, "Q": 12, "K": 13, "A": 14}
score = [0, 0] score = [0, 0]
file = Path("/datos/Scripts/Gitea/Project_Euler/src/files/Problem54.txt") file = Path("../files/Problem54.txt")
for line in open(file, "r").read().splitlines(): for line in open(file, "r").read().splitlines():
line = replace_values_in_string(line, replace_map).split() line = replace_values_in_string(line, replace_map).split()
hands = line[:5], line[5:] hands = line[:5], line[5:]

View File

@ -10,6 +10,7 @@ https://projecteuler.net/problem=13
""" """
from pathlib import Path from pathlib import Path
from utils import timeit from utils import timeit
@ -19,7 +20,7 @@ def compute():
Work out the first ten digits of the sum of the following one-hundred Work out the first ten digits of the sum of the following one-hundred
50-digit numbers. 50-digit numbers.
""" """
file = Path("/datos/Scripts/Gitea/Project_Euler/src/files/Problem13.txt") file = Path("../files/Problem13.txt")
with open(file, "r") as f: with open(file, "r") as f:
num = f.readlines() num = f.readlines()
result = 0 result = 0

View File

@ -10,6 +10,7 @@ https://projecteuler.net/problem=22
""" """
from pathlib import Path from pathlib import Path
from utils import timeit from utils import timeit
@ -27,9 +28,9 @@ def compute():
What is the total of all the name scores in the file? What is the total of all the name scores in the file?
""" """
file = Path("/datos/Scripts/Gitea/Project_Euler/src/files/Problem22.txt") file = Path("../files/Problem22.txt")
with open(file, 'r') as f: with open(file, "r") as f:
names = sorted(f.read().replace('"', '').split(',')) names = sorted(f.read().replace('"', "").split(","))
result = 0 result = 0
for idx, name in enumerate(names, 1): for idx, name in enumerate(names, 1):

View File

@ -10,6 +10,7 @@ https://projecteuler.net/problem=42
""" """
from pathlib import Path from pathlib import Path
from utils import timeit from utils import timeit
@ -31,15 +32,15 @@ def compute():
""" """
def triangle_number(num): def triangle_number(num):
return int(0.5*num*(num+1)) return int(0.5 * num * (num + 1))
def word_to_value(word): def word_to_value(word):
return sum(ord(letter)-64 for letter in word) return sum(ord(letter) - 64 for letter in word)
triangular_numbers = [triangle_number(n) for n in range(27)] triangular_numbers = [triangle_number(n) for n in range(27)]
ans = 0 ans = 0
file = Path("/datos/Scripts/Gitea/Project_Euler/src/files/Problem42.txt") file = Path("../files/Problem42.txt")
with open(file, "r") as f: with open(file, "r") as f:
words = f.readline().strip('"').split('","') words = f.readline().strip('"').split('","')
for word in words: for word in words:
@ -48,6 +49,7 @@ def compute():
return ans return ans
if __name__ == "__main__": if __name__ == "__main__":
print(f"Result for Problem 42: {compute()}") print(f"Result for Problem 42: {compute()}")