Programming for the Puzzled

Author: Srini Devadas
Publisher: MIT Press
Date: Nov 2017
Pages: 272
ISBN: 978-0262534307
Print: 0262534304
Kindle: B077GLCR99
Audience:Python Programmers
Rating: 5 (but see conclusion)
Reviewer: Mike James
Some of us are puzzled some of the time - can you learn Python this way?

The biggest problem with this book is its title. Programming for the Puzzled makes it sound as if it is a very low level introductory book suitable for the clueless. This is not a beginner's book and learning Python from scratch using it would be impossible.

So what is this book about?

In this case "Puzzled" should really be "Puzzler" because the book is full of puzzle analysis. The idea is:

"take a puzzle, usually one that is simple to explain, and then work through algorithmic solutions".

The algorithmic solutions are not complete in the sense that you aren't handled a full solution on a plate and just expected to admire it. Instead you are led through a sequence of mini-investigations that usually involve some coding in Python. It doesn't go in for explaining the Python language, it just uses it to solve the problems and you are expected to learn something about programming in general. The back jacket blurb states that you only need a rudimentary grasp of programming concepts, but then adds:

"that can be obtained from an introductory or AP computer science class".

I'd take issue with "rudimentary" being appropriate for the knowledge that someone has after taking an introductory class in programming and I also think that you would need to graduate with flying colors from such a class to benefit from reading this book.

There is a more obvious requirement, however, for liking this book - you have to be a puzzler. Not all programmers like contrived puzzles and so not all programmers are puzzlers. This doesn't mean that they won't try and invent an algorithmic solution to a puzzle that is forced on them, but they don't go seeking out Sudokus or logic puzzles to flex their muscles on.

If you don't like puzzles you can stop reading here.


The puzzles in the early chapters aren't really puzzles that you would find posed in any sort of puzzle pages. They are contrived situations that need a solution that calls for the application of simple algorithms.

Chapter 1 is about how to give instructions to get groups of people to switch hats the right way round. It seems to be about some sort of parallel programming problem, but in fact its about run length encoding and data compression. Chapter 2 is about finding the hour to attend a party so as to maximize the number of celebrities. Chapter 3 is about encoding, but wrapped up in the form of a card trick. 



Chapter 4 brings us to the first of the classic computer science problems - the Eight Queens problem. I encountered this for the first time courtesy of Dijkstra and still remember the solution today - sometimes a short presentation is better than a long one.

Chapter 5 is another classic but doesn't have a well known name. You have to drop something breakable out of a window and determine the maximum floor in the building from which it wil not break. You have to do it in the least number of steps.

Chapter 6 really doesn't deserve the title of "puzzle". It's about finding roots using a bisection search. I supose the puzzle is "find the root of this number".

From here the book works its way through a mix of classical CS problems - Towers of Hannoi, graph theory and so on - and a mix of more widely known puzzles such as Sudoku. In the main, however, the puzzles are mostly contrived to get the reader to find out about some algorithmic idea. This is not unreasonable, but it might be a surprise if you are expecting non-stop puzzles of the sort you might find in a puzzle magazine.


 Overall, this is a good book if it is what you are looking for.

To be algoritmic about it:

  • Don't buy it if you can't program reasonably well in Python.

  • Don't buy it if you don't like puzzles or if you do like puzzles but aren't interested in programming.

  • Do buy it if you are a reasonably good programmer wanting to look at some classic and not-so-classic programming problems.

  • Do buy it if you are building programming courses and you need inspiration for examples.

The aim of this book is more to get you to think like a programmer than to teach you to program. However, it is worth saying that not all programmers think like this. Many spend a happy career writing user interfaces or applications that do well defined and fairly straightforward things. The main struggle for the majority of programmers is with APIs rather than puzzles.

Still it is a good educationally sound book. Don't let me put you off buying it and trying it.


For recommendations of Python books see Python Books For Beginners and Books for Pythonistas in our Programmer's Bookshelf section.


Essential C# 8.0, 7th Ed (Addison-Wesley)

Author: Mark Michaelis
Publisher: Addison-Wesley
Date: October 2020
Pages: 1088
ISBN: 978-0135972267
Print: 0135972264
Kindle: B08Q84TH84
Audience: C# developers
Rating: 4.5
Reviewer: Mike James
The latest edition of a highly recommended book that combines reference and tutorial material.

Programming Essentials Using Java

Author: William McAllister and S. Jane Fritz
Publisher: Mercury
Pages: 540
ISBN: 978-1683920373
Print: 1683920376
Kindle: B06WWFW2HB
Audience: Would-be Java programmers
Rating: 3
Reviewer: Alex Armstrong
It's not too late to learn Java!

More Reviews

Last Updated ( Tuesday, 02 October 2018 )