Rename some input files
This commit is contained in:
parent
b0b9705303
commit
aa57c9b5b2
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user