Thorough though Thoreau threw, Troll throws through tough troughs
CJam, 11 9 7 bytes
q1b2+B%
How it works:
We are making use of the fact that the sum of the ASCII codes + 2 moded with 11 gives very nice order of 1 through 9 and then 10 for the nine concerned words. Here is the ordering:
through -> 1
thorough -> 2
tough -> 3
Thoreau -> 4
throw -> 5
threw -> 6
trough -> 7
though -> 8
troll -> 9
Code explanation:
q e# Read the input
1b e# Sum the ASCII code values of all characters in this word
2+ e# Increment the sum by 2
B% e# Mod by 11 and automatically print the mod result at the end
4 bytes saved thanks to user23013
Try it online here
Pyth, 8 chars
e%Cz8109
Try it online: Demonstration or Test Suite
I'm using the assignment:
though 5
through 9
thorough 4
Thoreau 7
throw 3
threw 2
trough 8
tough 6
troll 1
Explanation:
z input()
C convert to int (convert each char to their ASCII value
and interprete the result as number in base 256)
% 8109 modulo 8109
e modulo 10
Btw, I found the magic number 8109 by using this script: fqr1 10Sme%CdT.z1
.
Python 2, 92 54 bytes
print'K{7j)yE<}'.find(chr(hash(raw_input())%95+32))+1
The index string is created with for word in words: print chr(hash(word)%95+32),
. As pointed out in Jakube's answer, the hash function will give different results depending on Python version. This index string is computed on 64 bit Python 2.7.6.
Longer (92 bytes) but less cryptic answer:
print'though through thorough Thoreau throw threw trough tough troll'.find(raw_input())/7+1
The programs returns 1-9 for though through thorough Thoreau throw threw trough tough troll in that order. When the input is not found, find will return a -1 which conveniently turns into a zero after the +1
.