Skip to content

Instantly share code, notes, and snippets.

@sudominnix
Forked from peterjmag/letters-to-100.py
Last active August 29, 2015 14:12
Show Gist options
  • Select an option

  • Save sudominnix/f3526244685c52d573e0 to your computer and use it in GitHub Desktop.

Select an option

Save sudominnix/f3526244685c52d573e0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# encoding: utf-8
"""
letters-to-100.py
"""
import string
winning_list = []
count = 1
while count <=300:
letter_values = dict((l, i) for i, l in enumerate(string.lowercase, start=1))
english_dict = open('/usr/share/dict/words', 'rU')
winning_words = []
for word in english_dict:
word = word.rstrip().replace('-', '')
value = sum([letter_values[l.lower()] for l in word])
if value is count:
winning_words.append(word)
totalup = len(winning_words)
winning_list.append(totalup)
count += 1
print winning_list
[2, 3, 4, 5, 6, 9, 8, 11, 13, 20, 11, 20, 23, 21, 29, 38, 44, 45, 60, 69, 72, 78, 104, 106, 116, 137, 153, 168, 185, 243, 246, 262, 278, 295, 302, 340, 368, 420, 436, 495, 486, 554, 536, 603, 598, 647, 689, 753, 757, 801, 840, 909, 968, 1021, 1005, 1087, 1047, 1099, 1128, 1142, 1232, 1282, 1343, 1332, 1367, 1420, 1460, 1444, 1519, 1618, 1630, 1640, 1670, 1814, 1748, 1773, 1878, 1771, 1919, 1924, 1970, 1973, 2010, 1959, 2052, 2091, 2130, 2126, 2113, 2065, 2175, 2211, 2217, 2170, 2174, 2239, 2316, 2275, 2194, 2296, 2271, 2356, 2211, 2258, 2177, 2220, 2331, 2265, 2227, 2264, 2228, 2170, 2216, 2204, 2274, 2247, 2180, 2219, 2044, 2175, 2076, 2136, 2116, 2057, 1999, 2001, 2065, 1939, 1956, 1968, 1893, 1870, 1773, 1841, 1818, 1738, 1677, 1725, 1666, 1683, 1577, 1534, 1477, 1470, 1534, 1440, 1374, 1401, 1362, 1384, 1316, 1270, 1176, 1227, 1199, 1126, 1135, 1142, 1101, 1070, 991, 1014, 986, 976, 900, 937, 832, 828, 808, 766, 776, 739, 727, 675, 680, 628, 636, 655, 617, 598, 557, 526, 535, 506, 491, 455, 485, 437, 434, 417, 411, 360, 380, 370, 330, 310, 318, 301, 296, 322, 253, 234, 256, 255, 202, 211, 208, 166, 176, 175, 172, 178, 157, 134, 141, 160, 140, 132, 119, 115, 107, 107, 89, 101, 93, 79, 82, 65, 63, 67, 58, 70, 61, 53, 65, 32, 53, 42, 54, 39, 51, 28, 29, 25, 33, 29, 26, 35, 27, 22, 24, 15, 13, 15, 12, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
@sudominnix
Copy link
Author

This is slightly modified version of peterjmag 's GIST that runs through a Linux desktop dictionary to determine which words consist of letters that add up to 100 (with a=1, b=2, c=3, etc.) I was curious the distribution of words with all totals so I ran his code through a while loop up to 300. As you can see, this turns out to be overkill. The value of 256 seems to be the highest an English word can be (and there are only 14 of them.) You can analyze the output.txt in a spreadsheet...distribution looks fairly normal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment