[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.
I think a comment for this block would help. How do you arrive here? What are we doing in here? Why?