"Exercises in Programming Style consists of over 30 renditions of the same simple program written in various programming styles. The book illustrates the richness of human computational thought, and the teachings that have been accumulated during more than fifty years of computer programming. These teachings are scattered around, and are mostly passed to new generations of programmers by mentoring and self-teaching. The book presents this knowledge in a package that can be understood and referenced by all programming professionals and students, so that they have a more global vision of the conceptual tools at their disposal"
Link to book on Amazon: https://www.amazon.com/dp/0367350203
It's a little known book that explores different ways of solving the same problem under different constraints.
https://www.amazon.com/Exercises-Programming-Style-Cristina-...
(Copying from my comment the last time this was posted: https://news.ycombinator.com/item?id=26467684)
There's also a nice book "Exercises in Programming Style" about just this problem.