flâneur — a map of the web's best reading

CS106B Backtracking Warmup

web.stanford.edu · 2,408 words · saved by 1 readers

When you encounter a bug in a program, your first instinct is often to ask, “Why isn’t my program doing what I want it to do?” One of the best ways to find that answer is to instead start with a different question: “What is my program doing, and why is that different than what I intended?” The debugger is a powerful tool for observing exactly what a program is doing. With clear information about what is happening when a program is executing, you can relate that outcome to what the code asks for and then change the code to instead reflect your intentions. This warmup exercise will give you practice working with the debugger in the context of complex recursive problems. The Towers of Hanoi is a classic puzzle that has a beautiful recursive solution. You can read more about the puzzle and its history on the Towers of Hanoi wikipedia page. The recursive function below will move a tower of disks from the start peg to the end peg, following the puzzle rules (can only move single disk at a ti

CS106B Backtracking Warmup Backtracking Warmup Warmup from Julie Zelenski "Reproduce the bug" by Julia Evans When you encounter a bug in a program, your first instinct is often to ask, “Why isn’t my program doing what I want it to do?” One of the best ways to find that answer is to instead start with a different question: “What is my program doing, and why is that different than what I intended?” The debugger is a powerful tool for observing exactly what a program is doing. With clear information about what is happening when a program is executing, you can relate that outcome to what the code

Explore this link on the map →

related reading