Anagram: read words only once.

The first commit fixes #531, but I plan to improve the code a bit more.