[WIP] Anagram: read words only once.

The first commit fixes #531, but I plan to improve the code a bit more.
I will refactor the code in the following commits.