1. Ed Brannin
  2. spelltower-scoring

Source

spelltower-scoring / value.py

letters = dict( 
    a= 1,
                d= 2,
                e= 1,
                h= 4,
                n= 1,
                o= 1,
                r= 1,
                s= 1,
                t= 1,
                z= 22,
                w=4,
                y=4,
                g=2,
                x=24,
                i=1,
                p=3,
                )

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." % dict(total=total, unknown=unknown)

if __name__ == "__main__":
  for word, value in dict(
        quod=92,
        defi=32,
        mite=24,
        nix=78,
        sax=78,
      ).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)