Initial commit
This commit is contained in:
21
src/task42 - Coded triangle numbers.py
Normal file
21
src/task42 - Coded triangle numbers.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import csv
|
||||
import math
|
||||
|
||||
with open('42.txt') as file:
|
||||
reader = csv.reader(file, delimiter=",", quotechar='"')
|
||||
words = list(reader)[0]
|
||||
|
||||
def wordValue(n):
|
||||
return sum([ord(i.lower())-96 for i in n])
|
||||
|
||||
def triangleBase(n):
|
||||
return (math.sqrt(8*n+1)-1)/2
|
||||
|
||||
result = 0
|
||||
for i in words:
|
||||
n = wordValue(i)
|
||||
if triangleBase(n).is_integer():
|
||||
result+=1
|
||||
print(result)
|
||||
|
||||
#inverse triangle: (sqrt(8*n+1)-1)/2
|
Reference in New Issue
Block a user