Browse Source

Coded triangle numbers

Adel Qalieh 13 năm trước cách đây
mục cha
commit
5c52b45094
2 tập tin đã thay đổi với 24 bổ sung0 xóa
  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

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 0
words.txt