Saw this after I read the book so obviously I knew the ending, but I saw it coming in the book. It may be easier to guess at the ending in the book because
you are constantly looking at the anagram names. If you're good at puzzles it's not long before you start thinking they look similar.
Nevertheless, I enjoyed the book and I imagine you are supposed to guess at the ending. There were several moments where I thought my guess was wrong so it was still fun even if you do end up being right.
They did add a line that changed one element of the ending -
In the last scene, when Teddy has "reverted" again and they are coming to collect him, in the book he simply says "we're smarter than them" and it's clear that he's totally delusional. In the movie they add a line (don't remember exactly) about dying as a good man rather than living as a monster. Seems to imply that he is aware of what he's doing but just doesn't want to live with his memories of being what he thinks of as a monster.
I could be remembering the movie wrong but something to that effect struck me when I saw it.