If one assigns $ prices to a letter by its place in the English alphabet i.e. A=1, B=2, .. ..Y=25, Z=26 and the price of a word equals sum of its letters' values - (e.g, DOG is valued @ US$ 26)
find the n-letter words with the lowest and the highest prices:
n=3, 4, .... 10, 11
I get,
3 4 ['aba', 'baa'] 66 ['wry']
4 6 ['abba', 'baba'] 86 ['muzz']
5 8 ['abaca'] 111 ['muzzy']
6 18 ['acacia'] 127 ['syzygy']
7 21 ['cabbage'] 134 ['surtout']
8 30 ['dahabeah'] 156 ['susurrus']
9 37 ['beachhead'] 171 ['susurrous']
10 46 ['baldheaded'] 183 ['tumultuous']
11 39 ['cabbagehead'] 207 ['trustworthy']
the list "words" contains 46888 words in lower case
-------------
wlen = [[w for w in words if len(w) == i] for i in range(0,15)]
v = '0abcdefghijklmnopqrstuvwxyz'
for n in range(3,12):
scoremax = 0
maxwords = []
scoremin = 1000000
minwords = []
for w in wlen[n]:
score = 0
for c in w:
try:
score += v.index(c)
except:
print(w,c)
if score > scoremax:
scoremax = score
maxwords = [w]
elif score == scoremax:
maxwords.append(w)
if score < scoremin:
scoremin = score
minwords = [w]
elif score == scoremin:
minwords.append(w)
print(n,' ',scoremin, minwords,' ',scoremax, maxwords)
|
Posted by Larry
on 2023-08-16 09:40:56 |