Rename some input files

This commit is contained in:
daniele 2023-06-07 16:59:45 +02:00
parent b0b9705303
commit aa57c9b5b2
Signed by: fuxino
GPG Key ID: 981A2B2A3BBF5514
15 changed files with 21 additions and 21 deletions

View File

@ -40,13 +40,13 @@ def main():
start = default_timer() start = default_timer()
try: try:
with open('triang.txt', 'r', encoding='utf-8') as fp: with open('p018_triangle.txt', 'r', encoding='utf-8') as fp:
triang = [] triang = []
for line in fp: for line in fp:
triang.append(line.strip('\n').split()) triang.append(line.strip('\n').split())
except FileNotFoundError: except FileNotFoundError:
print('Error while opening file trian.txt') print('Error while opening file p018_triangle.txt')
sys.exit(1) sys.exit(1)
l = len(triang) l = len(triang)

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Using names.txt, a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. # Using p022_names.txt, a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order.
# Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score. # Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score.
# #
# For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. # For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list.
@ -16,10 +16,10 @@ def main():
start = default_timer() start = default_timer()
try: try:
with open('names.txt', 'r', encoding='utf-8') as fp: with open('p022_names.txt', 'r', encoding='utf-8') as fp:
names = list(fp.readline().replace('"', '').split(',')) names = list(fp.readline().replace('"', '').split(','))
except FileNotFoundError: except FileNotFoundError:
print('Error while opening file names.txt') print('Error while opening file p022_names.txt')
sys.exit(1) sys.exit(1)
names.sort() names.sort()

View File

@ -7,7 +7,7 @@
# By converting each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value. # By converting each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value.
# For example, the word value for SKY is 19 + 11 + 25 = 55 = t10. If the word value is a triangle number then we shall call the word a triangle word. # For example, the word value for SKY is 19 + 11 + 25 = 55 = t10. If the word value is a triangle number then we shall call the word a triangle word.
# #
# Using words.txt (right click and 'Save Link/Target As...'), a 16K text file containing nearly two-thousand common English words, # Using p042_words.txt (right click and 'Save Link/Target As...'), a 16K text file containing nearly two-thousand common English words,
# how many are triangle words? # how many are triangle words?
import sys import sys
@ -31,10 +31,10 @@ def main():
start = default_timer() start = default_timer()
try: try:
with open('words.txt', 'r', encoding='utf-8') as fp: with open('p042_words.txt', 'r', encoding='utf-8') as fp:
words = list(fp.readline().replace('"', '').split(',')) words = list(fp.readline().replace('"', '').split(','))
except FileNotFoundError: except FileNotFoundError:
print('Error while opening file words.txt') print('Error while opening file p042_words.txt')
sys.exit(1) sys.exit(1)
count = 0 count = 0

View File

@ -39,7 +39,7 @@
# Full House Full House # Full House Full House
# With Three Fours With Three Threes # With Three Fours With Three Threes
# #
# The file, poker.txt, contains one-thousand random hands dealt to two players. Each line of the file contains ten cards # The file, p054_poker.txt, contains one-thousand random hands dealt to two players. Each line of the file contains ten cards
# (separated by a single space): the first five are Player 1's cards and the last five are Player 2's cards. # (separated by a single space): the first five are Player 1's cards and the last five are Player 2's cards.
# You can assume that all hands are valid (no invalid characters or repeated cards), each player's hand is in no specific order, # You can assume that all hands are valid (no invalid characters or repeated cards), each player's hand is in no specific order,
# and in each hand there is a clear winner. # and in each hand there is a clear winner.
@ -447,10 +447,10 @@ def main():
start = default_timer() start = default_timer()
try: try:
with open('poker.txt', 'r', encoding='utf-8') as fp: with open('p054_poker.txt', 'r', encoding='utf-8') as fp:
games = fp.readlines() games = fp.readlines()
except FileNotFoundError: except FileNotFoundError:
print('Error while opening file poker.txt') print('Error while opening file p054_poker.txt')
sys.exit(1) sys.exit(1)
count = 0 count = 0

View File

@ -14,7 +14,7 @@
# the message, which is likely, the key is repeated cyclically throughout the message. The balance for this method is using a sufficiently long # the message, which is likely, the key is repeated cyclically throughout the message. The balance for this method is using a sufficiently long
# password key for security, but short enough to be memorable. # password key for security, but short enough to be memorable.
# #
# Your task has been made easy, as the encryption key consists of three lower case characters. Using cipher.txt, a file containing the # Your task has been made easy, as the encryption key consists of three lower case characters. Using p059_cipher.txt, a file containing the
# encrypted ASCII codes, and the knowledge that the plain text must contain common English words, decrypt the message and find the sum of the # encrypted ASCII codes, and the knowledge that the plain text must contain common English words, decrypt the message and find the sum of the
# ASCII values in the original text. # ASCII values in the original text.
@ -82,7 +82,7 @@ def main():
enc_text = EncryptedText() enc_text = EncryptedText()
if enc_text.read_text('cipher.txt') == -1: if enc_text.read_text('p059_cipher.txt') == -1:
sys.exit(1) sys.exit(1)
plain_text = enc_text.decrypt() plain_text = enc_text.decrypt()

View File

@ -8,7 +8,7 @@
# 8 5 9 3 # 8 5 9 3
# #
# That is, 3 + 7 + 4 + 9 = 23. # That is, 3 + 7 + 4 + 9 = 23.
# Find the maximum total from top to bottom in triangle.txt (right click and 'Save Link/Target As...'), a 15K text file containing a triangle # Find the maximum total from top to bottom in p067_triangle.txt (right click and 'Save Link/Target As...'), a 15K text file containing a triangle
# with one-hundred rows. # with one-hundred rows.
# #
# NOTE: This is a much more difficult version of Problem 18. It is not possible to try every route to solve this problem, as there are 299 altogether! # NOTE: This is a much more difficult version of Problem 18. It is not possible to try every route to solve this problem, as there are 299 altogether!
@ -27,11 +27,11 @@ def main():
triang = [] triang = []
try: try:
with open('triangle.txt', 'r', encoding='utf-8') as fp: with open('p067_triangle.txt', 'r', encoding='utf-8') as fp:
for line in fp: for line in fp:
triang.append(line.strip('\n').split()) triang.append(line.strip('\n').split())
except FileNotFoundError: except FileNotFoundError:
print('Error while opening file triangle.txt') print('Error while opening file p067_triangle.txt')
sys.exit(1) sys.exit(1)
l = len(triang) l = len(triang)

View File

@ -3,7 +3,7 @@
# A common security method used for online banking is to ask the user for three random characters from a passcode. # A common security method used for online banking is to ask the user for three random characters from a passcode.
# For example, if the passcode was 531278, they may ask for the 2nd, 3rd, and 5th characters; the expected reply would be: 317. # For example, if the passcode was 531278, they may ask for the 2nd, 3rd, and 5th characters; the expected reply would be: 317.
# #
# The text file, keylog.txt, contains fifty successful login attempts. # The text file, p079_keylog.txt, contains fifty successful login attempts.
# #
# Given that the three characters are always asked for in order, analyse the file so as to determine the shortest possible # Given that the three characters are always asked for in order, analyse the file so as to determine the shortest possible
# secret passcode of unknown length. # secret passcode of unknown length.
@ -36,10 +36,10 @@ def main():
start = default_timer() start = default_timer()
try: try:
with open('keylog.txt', 'r', encoding='utf-8') as fp: with open('p079_keylog.txt', 'r', encoding='utf-8') as fp:
logins = fp.readlines() logins = fp.readlines()
except FileNotFoundError: except FileNotFoundError:
print('Error while opening file keylog.txt') print('Error while opening file p079_keylog.txt')
sys.exit(1) sys.exit(1)
digits = [0] * 10 digits = [0] * 10

View File

@ -1,6 +1,6 @@
# My Project Euler solutions # My Project Euler solutions
These are my solutions in C and Python, not necessarily the best solutions. I've solved most of the first 100 problems, currently working on cleaning the code and uploading it. I will try to solve more problems in the future. These are my solutions in C and Python, not necessarily the best solutions. I've solved most of the first 100 problems, currently working on cleaning the code and uploading it. I will try to solve more problems in the future.
# Issues # Notes
- Solutions for problems 82 and 145 in Python run really slow. - Solutions for problems 82 and 145 in Python are really slow.
- Solutions for problems 84, 85, 86, 87, 89, 92, 95, 96, 97. 99, 102, 112, 124 and 357 have been implemented in C but not in Python. - Solutions for problems 84, 85, 86, 87, 89, 92, 95, 96, 97. 99, 102, 112, 124 and 357 have been implemented in C but not in Python.