Skip to main content

Puzzles for Programmers and Pros

Puzzles for Programmers and Pros

Dennis E. Shasha

ISBN: 978-1-119-41927-3

May 2017

240 pages


  • Aimed at both working programmers who are applying for a job where puzzles are an integral part of the interview, as well as techies who just love a good puzzle, this book offers a cache of exciting puzzles
  • Features a new series of puzzles, never before published, called elimination puzzles that have a pedagogical aim of helping the reader solve an entire class of Sudoku-like puzzles
  • Provides the tools to solve the puzzles by hand and computer
  • The first part of each chapter presents a puzzle; the second part shows readers how to solve several classes of puzzles algorithmically; the third part asks the reader to solve a mystery involving codes, puzzles, and geography
  • Comes with a unique bonus: if readers actually solve the mystery, they have a chance to win a prize, which will be promoted on!
Acknowledgments v

Introduction xi

Part I: Mind Games 1

We can't all be winners. 3

Sweet Tooth 4

Byzantine Bettors 6

A Touch of Luck 8

Information Gain 10

Reach for the Sky! 12

Pork Politics 14

Social Games 15

Escape Management 19

Flu Math 21

Imagination rules... 23

Whipping Ice 24

Optimal Jargon 29

Using Your Marbles 31

Flipping Colors 33

Scheduling Tradition 34

Fractal Biology 35

As Easy as Pie 37

Getting on the right side of luck 41

Lucky Roulette 42

Legal Logic 44

The Box Chip Game 47

Feedback Dividends 49

What are you thinking? 53

Number Clues 54

Mind Games 56

Refuse and Reveal 59

A Biting Maze 61

Mad Mix 63

Doing more with less 65

Dig That! 66

Preferential Romance 68

No Change for the Holidays 71

Quiet in the Depths 73

Solutions 74

Solution to Sweet Tooth 74

Solution to Byzantine Bettors 74

Solution to A Touch of Luck 76

Solution to Information Gain 78

Solution to Reach for the Sky! 78

Solution to Pork Politics 79

Solution to Social Games 80

Solution to Escape Management 81

Solution to Flu Math 83

Solution to Whipping Ice 84

Solution to Optimal Jargon 86

Solution to Using Your Marbles 88

Solution to Flipping Colors 89

Solution to Scheduling Tradition 90

Solution to Fractal Biology 91

Solution to As Easy as Pie 94

Solution to Lucky Roulette 96

Solution to Legal Logic 96

Solution to The Box Chip Game 97

Solution to Feedback Dividends 102

Solution to Number Clues 103

Solution to Mind Games 104

Solution to Refuse and Reveal 108

Solution to A Biting Maze 110

Solution to Mad Mix 112

Solution to Dig That! 113

Solution to Preferential Romance 116

Solution to No Change for the Holidays 117

Solution to Quiet in the Depths 118

Part II: The Secret of the Puzzle 121

Order the Ages 126

Urban Planning 128

Solution to Urban Planning 129

Finding a Schedule That Works 131

Solution to Finding a Schedule That Works 132

Picturing the Treasure 133

Solution to Picturing the Treasure 135

Sudoku 138

Solution to Sudoku 146

Number Encoding 147

Solution to Number Encoding 149

Selective Greed 150

Solution to Selective Greed 155

Sweet Packs 156

Solution to Sweet Packs 158

Revisiting a Traveling Salesman 159

Solution to Revisiting a Traveling Salesman 163

Overloaded Scheduling and Freezing Crystals 164

Solution to Overloaded Scheduling and Freezing Crystals 170

Wordsnakes 171

Solution to Wordsnakes 173

Maximal Friends 174

Solution to Maximal Friends 176

Winning at the Slots 177

Solution to Winning at the Slots 179

Understanding Dice 181

Solution to Understanding Dice 183

Bait and Switch 184

Solution to Bait and Switch 186

Part III: Faithful Foes 189

Index 221

Code Downloads
Code downloads for this title are available here.
ChapterPageDetailsDatePrint Run
Part 114Error in Text
Currently reads:
in Solution to Warm-Up, "fraction 25/55 of the money"
Should be:
"fraction 25/51 of the money"
Currently reads:
In Warm-up "25/55"
Should be:
In Warm-up "25/51"
Currently reads:
In Q1 Which coalitions might form?
Should read:
Which other coalitions might form?
Currently reads:In Q2 for B to receive as much money as possible?
changed to be:
for B to guarantee to receive
3 June 2015

part150Error in Text
Currently reads:
Should read
3 June 2015

Part 164Error in Text
Question 4
Currently reads:
In addition, you have the big bucket again with capacity over 100 liters
Should Read:
In addition, you have the big bucket again with capacity just over 5 liters
6 June 2015

solutions75Error in Text
Currently reads:
On the second line after the displayed section."A and C" Should be:
"A and D"
3 June 2015

Soultions77Error in Text
Currently reads:
The second line of the answer, for question 6, "her 180"
Should be:
"her 190"
3 June 2015

solutions110-111Error in Text
The correct order for the maze puzzle should be:
f43, if,

f39, you

f34, would

f33, see

f41, all

f46, of

f29, nature

f54, gathered

f24, up

f52, at

f17, one

f13, point

f47, in

f55, all

f35, her

f30, loveliness

f14, and

f19, her

f37, skill

f0, and

f2, her

f15, deadliness

f16, and

f40, her

f10, sex

f51, where

f21, would

f31, you

f32, find

f12, a

f27, more

f7, exquisite

f23, symbol

f22, than

f53, the

f28, mosquito

f5, if you have found the whole route to get here, you have solved the maze. congratulations.
3 June 2015

Part 1116Error in Text
Solution to Dig That!
Readers found that seven probes always suffices. Start by probing the central street at the six places marked in Figure 26. If all six probes detect a tunnel, you are done; otherwise, the rows where no tunnel was detected indicate that the tunnel was dug either one street east or one street west (but not both, since there is not sufficient length for that). To resolve this, assume the missing sections are east and probe for one of them; if it is not found, all the missing sections must be west.
6 June 2015

Part 2126Error in Text
Currently reads:
"proceeding in clockwise order"
Should be:
"proceeding in counterclockwise order"
3 June 2015

sweet pack158Error in Text
Currently reads:
In solution 1 of the Sweet Packs problem, 1, 6, 29, and 37
should be:
1 5 24 37
3 June 2015

Part 2170Error in Text
Solution to Overloaded Scheduling and Freezing Crystals A reader found a total of 171 by suggesting a schedule of T14 T19 T16 T10 T1 T2 T12 T18 T4 T5 T7 T3
T14 T19 T16 T10 T8 T1 T12=T18 T6 T5 T7 T3