# 'Add' up the letters in a word

My dad is a retired teacher, and he used to give combined spelling and math quizzes, where the student would spell a word, and then 'score' the word by adding up the letters, where a=1, b=2, etc. (e.g. cat = 3+1+20=24). This made grading the quizzes easier, as he would just have to check for incorrect 'scores' rather than incorrectly spelled words, and had the added benefit of testing 2 skills at once.

He hired a friend of mine to write a program that would score words for him, so he could generate lengthy answer keys without error. This problem is inspired by that program.

Requirements:

1. Accept any word with uppercase and lowercase letters
2. Return an error for any special characters, i.e. spaces, hyphens, @^%# etc.
3. a=1, b=2,... and A=1, B=2,...
4. Print the score of the word
5. (Optional) check that the word is in a dictionary after scoring, and print a warning if it is not.
6. No importing an external letter->number dictionary. You must generate it yourself.

Any language is acceptable. This is similar to the 'digital root battle,' but much simpler.

• Is this supposed to be a code golf? – Peter Taylor Apr 23 '11 at 18:08
• @Zach Using the code-golf tag. – Lowjacker Apr 23 '11 at 18:24
• Did your dad even bother teaching the "I before E except after C" rule? – Nathan Merrill Dec 28 '15 at 12:28
• Yeah, only checking scores? I'd spell cat as aaaaaaaaaaaaaaaaaaaaaaaa. Dad: Score is 24? That's right! – ericw31415 May 8 '16 at 14:13
• @ericw31415 Every hashing function has collisions ;-). So far none of his students have tried that attack vector – Zach May 9 '16 at 15:39

# K, 44

{\$[=/x in\:a:.Q.a,.Q.A;+/(a!,/2#,1+!26)x;]}

Returns  for any non alphabetic input

## VBA 120

Sub s(t)
For i=1 To Len(t)
a=Asc(Mid(t,i,1))-64
a=IIf(a>32,a-32,a)
If a<1 Or a>26 Then Print
b=b+a
Next
MsgBox b
End Sub

Print does not cause a compile-time error, though the syntax is invalid, which causes an exception to be thrown and the program to exit if, and only if, the character is not an upper- or lower-case letter.

# C, 97 Chars

int r(c*z){int x=0;while(*z){char w=tolower(*(z++));if(w<96|w>122)return-1;x+=w-96;}return x;}

It returns -1 if there's an invalid character.