Your task is to determine if a given string is of proper length and can be represented with Scrabble tiles and, if so, output the sum of each letter's score.
If you don't know how to play Scrabble:, you have 100 tiles with various letters A–Z printed on them, as well as two wildcards that can represent any letter. Each letter has a certain number of points, and each tile (but not necessarily word) can only be used once. When a word is played, the point value of each tile used is added up, which becomes the score. As there are a limited number of letters available, a word can only have a certain letter as many times as that letter has tiles + any unused wildcards. The Scrabble board is 15×15 cells, so the word must be between 2 and 15 characters long.
For a list of the quantity and score of each letter in the English version, see below or http://boardgames.about.com/od/scrabble/a/tile_distribute.htm (archive).
Letter Qty Points Letter Qty Points ------------------- ------------------- A 9 1 O 8 1 B 2 3 P 2 3 C 2 3 Q 1 10 D 4 2 R 6 1 E 12 1 S 4 1 F 2 4 T 6 1 G 3 2 U 4 1 H 2 4 V 2 4 I 9 1 W 2 4 J 1 8 X 1 8 K 1 5 Y 2 4 L 4 1 Z 1 10 M 2 3 [wild] 2 0 N 6 1
Further rules
- The program shall take a single string of input from STDIN or the like.
- The input will always contain only uppercase letters.
- If the string contains more copies of a letter than there are unused wildcards or tiles for that letter OR the string's length is not between 2 and 15 inclusive, the program should output
Invalid
. - Otherwise, the score should be added up with using data from the chart above and output.
- Do not use wildcards unless necessary.
- Do not worry about bonuses such as double word scores or whether the string is a real word.
- The program shall output the result through STDOUT or the like.
- Loopholes that are forbidden by default are not allowed.
- Using an external source such as a website, as well as any libraries, APIs, functions, or the like that calculate Scrabble scores or proper quantities are not alllowed.
- This is code-golf, so fewest bytes wins.
Walkthrough
Input: CODEGOLF
C -> 3, O -> 1, D -> 2, E -> 1, G -> 2, O -> 1, L -> 1, F -> 4
3 + 1 + 2 + 1 + 2 + 1 + 1 + 4 = 15
Output: 15
Testcases
Input Output ------------------------ SCRABBLE 14 JAZZ 19 STACKEXCHANGE 32 XYWFHQYVZVJKHFW 81 PIZZAZZ Invalid KIXOKEJAJAX Invalid MISUNDERSTANDING Invalid
-1
? \$\endgroup\$Invalid
. \$\endgroup\$