#!/usr/bin/python # # This script scores its input words according to Scrabble scoring rules # (per-letter; no bingoes). Assumes single-word inputs. # # Sample usage: # # I want to know how many points I can get for the word "tweet" # echo tweet | ./score # # I have tiles [telewto] and I want the highest scoring options. # ./anagram telewto | ./score | sort -n | tail import sys # Constants SCORE = { 'a': 1, 'b': 3, 'c': 3, 'd': 2, 'e': 1, 'f': 4, 'g': 2, 'h': 4, 'i': 1, 'j': 8, 'k': 5, 'l': 1, 'm': 3, 'n': 1, 'o': 1, 'p': 3, 'q': 10, 'r': 1, 's': 1, 't': 1, 'u': 1, 'v': 4, 'w': 4, 'x': 8, 'y': 4, 'z': 10 } # Returns the score of a word def get_score(word): if not word: return 0 return SCORE.get(word[0], 0) + get_score(word[1:]) # Main --- for line in sys.stdin: word = line.strip("\n").lower() print "%3d \t%s" % (get_score(word), word)