# spelltower-scoring / value.py

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66``` ```letters = dict( a = 1, d = 2, e = 1, f = 4, g = 2, h = 4, i = 1, m = 3, n = 1, o = 1, p = 3, r = 1, s = 1, t = 1, w = 4, x = 24, y = 4, z = 22, ) def score(word): """ Returns the Spelltower score for a word. """ total = 0 for letter in word: total += letters[letter] return total * len(word) def guess_letters(word, score, surrounding=0): if len(word) >= 5: print "Not even trying to guess long words like %s right now." % word return total = score/len(word) unknown = "" #print "%(points)d points in the letters of '%(word)s'." % dict(points=total, word=word) for letter in word: try: total -= letters[letter] #print "%(points)d points for %(letter)s" % dict(points=letters[letter], # letter=letter) except KeyError: #print "No score known for %(letter)s." % dict(letter=letter) unknown += letter if len(unknown) == 0 and total == 0: print "Solved for the word: %s" % word else: print "Remaining: %(total)d points for '%(unknown)s' from %(word)s." % dict(total=total, unknown=unknown, word=word) if __name__ == "__main__": for word, value in dict( quod=92, wqer=0, tyui=0, opl=0, asdf=0, ghjk=0, zxcv=0, bnm=0, ).items(): guess_letters(word, value) if False: # Ignore the long words for now. guess_letters("queer", 245) guess_letters("sulker", 216, 13) guess_letters("sulker", 234, 13) guess_letters("greet", 180, 7) guess_letters("greet", 170, 8) guess_letters("greed", 160, 7) ```