diff --git a/Python/p018.py b/Python/p018.py index 946e776..9b540b1 100644 --- a/Python/p018.py +++ b/Python/p018.py @@ -40,13 +40,13 @@ def main(): start = default_timer() try: - with open('triang.txt', 'r', encoding='utf-8') as fp: + with open('p018_triangle.txt', 'r', encoding='utf-8') as fp: triang = [] for line in fp: triang.append(line.strip('\n').split()) except FileNotFoundError: - print('Error while opening file trian.txt') + print('Error while opening file p018_triangle.txt') sys.exit(1) l = len(triang) diff --git a/Python/triang.txt b/Python/p018_triangle.txt similarity index 100% rename from Python/triang.txt rename to Python/p018_triangle.txt diff --git a/Python/p022.py b/Python/p022.py index 11af82d..57e1374 100644 --- a/Python/p022.py +++ b/Python/p022.py @@ -1,6 +1,6 @@ #!/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. # # 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() 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(',')) except FileNotFoundError: - print('Error while opening file names.txt') + print('Error while opening file p022_names.txt') sys.exit(1) names.sort() diff --git a/Python/names.txt b/Python/p022_names.txt similarity index 100% rename from Python/names.txt rename to Python/p022_names.txt diff --git a/Python/p042.py b/Python/p042.py index 189fcf2..9010457 100644 --- a/Python/p042.py +++ b/Python/p042.py @@ -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. # 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? import sys @@ -31,10 +31,10 @@ def main(): start = default_timer() 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(',')) except FileNotFoundError: - print('Error while opening file words.txt') + print('Error while opening file p042_words.txt') sys.exit(1) count = 0 diff --git a/Python/words.txt b/Python/p042_words.txt similarity index 100% rename from Python/words.txt rename to Python/p042_words.txt diff --git a/Python/p054.py b/Python/p054.py index 055afc7..bd00b3a 100644 --- a/Python/p054.py +++ b/Python/p054.py @@ -39,7 +39,7 @@ # Full House Full House # 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. # 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. @@ -447,10 +447,10 @@ def main(): start = default_timer() 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() except FileNotFoundError: - print('Error while opening file poker.txt') + print('Error while opening file p054_poker.txt') sys.exit(1) count = 0 diff --git a/Python/poker.txt b/Python/p054_poker.txt similarity index 100% rename from Python/poker.txt rename to Python/p054_poker.txt diff --git a/Python/p059.py b/Python/p059.py index 3100c29..6ce69a4 100644 --- a/Python/p059.py +++ b/Python/p059.py @@ -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 # 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 # ASCII values in the original text. @@ -82,7 +82,7 @@ def main(): enc_text = EncryptedText() - if enc_text.read_text('cipher.txt') == -1: + if enc_text.read_text('p059_cipher.txt') == -1: sys.exit(1) plain_text = enc_text.decrypt() diff --git a/Python/cipher.txt b/Python/p059_cipher.txt similarity index 100% rename from Python/cipher.txt rename to Python/p059_cipher.txt diff --git a/Python/p067.py b/Python/p067.py index 6b01b05..8c3201a 100644 --- a/Python/p067.py +++ b/Python/p067.py @@ -8,7 +8,7 @@ # 8 5 9 3 # # 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. # # 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 = [] 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: triang.append(line.strip('\n').split()) except FileNotFoundError: - print('Error while opening file triangle.txt') + print('Error while opening file p067_triangle.txt') sys.exit(1) l = len(triang) diff --git a/Python/triangle.txt b/Python/p067_triangle.txt similarity index 100% rename from Python/triangle.txt rename to Python/p067_triangle.txt diff --git a/Python/p079.py b/Python/p079.py index 181631a..7f8b02d 100644 --- a/Python/p079.py +++ b/Python/p079.py @@ -3,7 +3,7 @@ # 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. # -# 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 # secret passcode of unknown length. @@ -36,10 +36,10 @@ def main(): start = default_timer() 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() except FileNotFoundError: - print('Error while opening file keylog.txt') + print('Error while opening file p079_keylog.txt') sys.exit(1) digits = [0] * 10 diff --git a/Python/keylog.txt b/Python/p079_keylog.txt similarity index 100% rename from Python/keylog.txt rename to Python/p079_keylog.txt diff --git a/README.md b/README.md index 3f5eaba..456e67e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 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. -# Issues -- Solutions for problems 82 and 145 in Python run really slow. +# Notes +- 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.