소스 검색

Coded triangle numbers

Adel Qalieh 13 년 전
부모
커밋
5c52b45094
2개의 변경된 파일24개의 추가작업 그리고 0개의 파일을 삭제
  1. 23 0
      42.py
  2. 1 0
      words.txt

+ 23 - 0
42.py

@@ -0,0 +1,23 @@
+import string
+letterscore = dict(zip(string.ascii_lowercase, range(1, 27)))
+triangle = [x*(x+1)/2 for x in range(1000)]
+
+f = open("words.txt", "r")
+f = f.read()
+f = f.strip().split(',')
+f.sort()
+
+for index in range(len(f)):
+	f[index] = f[index][1:-1]
+
+wordlist = [x.lower() for x in f]
+
+trianglewords = 0
+for word in wordlist:
+	wordscore = 0
+	for char in word:
+		wordscore += letterscore[char]
+	if wordscore in triangle:
+		trianglewords += 1
+
+print trianglewords

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 1 - 0
words.txt