'Add' up the letters in a word

Ruby, 43 characters

$_=gets.upcase;p~/[^A-Z]/?_: $_.sum-64*~/$/

The error message this generates isn't exactly helpful, though. Both solutions posted here assume the input has no trailing linebreak, so to test them, use echo -n.

Ruby, 76 characters with dictionary check

l=STDIN.gets;$_=l.upcase;p~/[^A-Z]/?_: $_.sum-64*~/$/;[*$<].index(l)||$><<?W

The warning message consists of the single character "W". The path to the dictionary has to be supplied via ARGV. Example usage:

$ echo -n asd | ruby addletters.rb /usr/share/dict/words
24
W
$ echo -n cat | ruby addletters.rb /usr/share/dict/words
24

Python (65 64)

print sum(['',ord(i)-64]['@'<i<'[']for i in raw_input().upper())

This raises an error if the word contains non-letter characters, but not a helpful or informative one. (Edit: tip of the hat to st0le for the indexing trick.)


Golfscript - 23 chars

0\{.31&.(.26%=@64///+}/

Ensure there are no trailing newlines in input (e.g. use echo -n).

Tags:

Code Golf

Word