Skip to content

Commit

Permalink
add euler042 and euler045 solutions (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
kailanefelix authored Oct 2, 2021
1 parent 388bb67 commit 87eefd0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions euler0XX/euler042.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from string import ascii_uppercase

triangle_numbers = [n * (n + 1) // 2 for n in range(40)]

with open("euler042_words.txt", "r") as fp:
words = sorted(word[1:-1] for word in fp.read().split(","))

count = 0
for word in words:
score = sum(ascii_uppercase.index(letter) + 1 for letter in word)
if score in triangle_numbers:
count = count + 1

print(count)
8 changes: 8 additions & 0 deletions euler0XX/euler045.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from itertools import count

for h in count(144):
y = 2 * h * h - h
p = (1 + (1 + 24 * y) ** 0.5) / 6
if p.is_integer():
print(y)
break

0 comments on commit 87eefd0

Please sign in to comment.