19
To each of these nine confusingly similar words, assign a number 1-9 in any way you like:
though
through
thorough
Thoreau
throw
threw
trough
tough
troll
Write a program that takes in a string. If the input is one of these nine words, output the number you assigned to it. If the input is not one of the words above, the program may do anything (including error or loop forever).
The words are case sensitive, e.g. Thoreau
, should produce a number from 1-9 but thoreau
will not necessarily do the same.
Example
Suppose you assign the numbers as follows:
though 9
through 2
thorough 7
Thoreau 6
throw 3
threw 5
trough 4
tough 1
troll 8
Then when tough
is input, 1
should be output.
When through
is input, 2
should be output.
When throw
is input, 3
should be output.
. . .
When though
is input, 9
should be output.
All other inputs may do anything.
Details
- Take the input string via stdin or the command line and output to stdout.
- The output may contain a single trailing newline.
- Instead of a program, you may write a function that takes in a string and prints the result normally or returns it.
- The shortest submission in bytes wins.
1Darn it! I had a clever solution to output zero when not found by using the Python string
find
method. Then the rules changed. Clever idea not so clever now. – Logic Knight – 2015-05-17T08:15:16.780@CarpetPython My bad really. Don't hesitate to downvote if you feel unsatisfied with the change. (Though I promise to everyone there will be no more changes.) – Calvin's Hobbies – 2015-05-17T08:21:01.210
That's ok. I think my answer is still valid (though I little verbose). – Logic Knight – 2015-05-17T08:29:33.213
Can I make it work regardless of capitalization? – ASCIIThenANSI – 2015-05-17T14:25:03.117
2@ASCIIThenANSI as long as it works for the 9 cases – Calvin's Hobbies – 2015-05-17T18:21:21.240