Think Like a Programmer
An Introduction to Creative Problem Solving
Book by V. Anton Spraul - 2012
Chapter 1 - Strategies for Problem Solving
General Problem Solving Techniques
- Always Have A Plan
- Restate The Problem
- Divide The Problem
- Start With What You Know
- Reduce The Problem
- Look For Analogies
- Experiment
- Don’t Get Frustrated
1. Always Have A Plan
This is the most important rule!
- Having a plan is always possible.
- Plans may require alteration or scrapping altogether, but you should always have one before you tackle a problem.
- ✅ Planning allows you to set and reach smaller, immediate goals.
- ❌ Without a plan, your only goal is to solve the whole problem.
- The first step of every plan is: “Formally restate the problem.”
- Once you do that, you’ve already accomplished your first objective!
“I have always found that plans are useless, but planning is indispensable.”
– General Dwight D. Eisenhower.
“No plan survives first contact with the enemy.”
– Helmuth von Moltke
2. Restate The Problem
- Before starting a climb, circle the hill and see if there’s an easier way up.
- Restatement confirms your understanding of the problem.
The Fox, the Goose, and the Corn
- Think about the nature of the problem itself. It can be just as, if not more, productive than thinking about the path to a solution.
- 🫤 OK: List specific actions/tasks required to solve the problem.
- Carry the fox across the river.
- Carry the goose across the river.
- Carry the corn across the river.
- ✅ Better: Parameterize (make generic) the operations.
- Row the boat across the shore.
- If the boat is empty, load an item from the shore.
- If the boat isn’t empty, unload the item onto the shore.
3. Divide The Problem
- Dividing the problem into smaller chunks can lower difficulty by an order of magnitude!
- ❌ Alphabetize 100 files individually, one after another.
- ✅ Sort files into 2 piles, A-M and N-Z, before alphabetizing.
Sliding Tile Puzzles
- Strategy > Trial & Error
- Working with a specific goal is always better than random effort.
- Look for ways to divide the problem.
- Experiment with reduced versions of problem.
4. Start With What You Know
- Start with what you can do and work outward from there.
- Partial solutions often inspire solutions elsewhere.
- Try to make repairs with the tools you have before purchasing new ones.
Sudoku
- Constraints are your friend; look for the most constrained variable first.
- They eliminate choices and simplify possible solutions.
- most constrained variable: the variable that has the lowest number of possible values (i.e., the most restrictive consideration).
- Start with what’s obvious.
- If you can solve part of a problem, do it!
5. Reduce The Problem
- Stuck? Add or remove constraints until you know how to solve a particular condition.
- Reducing problems allows you to pinpoint where remaining difficulty lies.
6. Look For Analogies
- Recognizing analogies is the most difficult skill because it requires experience and solutions to reference.
The Quarrasi Lock
- This puzzle is analogous to the Fox, Goose, and Corn problem from earlier.
- The sooner you make connections to analogies for which you already have solutions, the less work you’ll have to do.
7. Experiment
- Experimentation ≠ Guessing
- Hypothesize about what will happen and observe the results of your trial.
8. Don’t Get Frustrated
- Frustration is an excuse to continue to fail.
- Take a real break and don’t think about the problem.
- Or focus your attention on another problem and return to the original problem later.
- Never forget the first rule: Always have a plan.
- If your original plan doesn’t pan out, make another plan. And repeat.