Coded Triangle Numbers
Problem 42
The nth term of the sequence of triangle numbers are given by, TN =? n (n+1); So the first ten triangle numbers is:
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
By converting 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 + one + + = = 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 中文版 wo RDS, how many is triangle words?
Answer:
162
Completed on Thu, 2015, 09:06
fromMathImportsqrt def istrianglenumber(word):Data=0 forIinchWord:data+=ord (i)-ord (' A ')+1K=int (sqrt (data*2))ifdata*2==k* (k +1):return 1 Else:return 0Count=0 forLineinchOpen' P042_words.txt ',' R '): Line=line.strip (' \ n '). Split (",") forWordinchLine:word=word.strip ("\"") Count+=istrianglenumber (Word) print (count)
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Eularproject 42: Number of triangles decoded by word