Karel #7: Look for and Make Use of Structure

What It Means

Find patterns and repeated reasoning that can help solve more complex problems. For young students this might be recognizing fact families, inverses, or the distributive property. As students get older, they can break apart problems and numbers into familiar relationships.

Computer Programming Teaches Students to Look for Patterns and Make Use of Structure

Looking for patterns and making use of structure is a fundamental component of computer programming. Students learn quickly that finding a pattern simplifies the logic, and makes the solution of the given problem easier. Often this is realized by means of custom commands. Custom command is nothing else than a “small program” that is used to solve a “small task” inside of the “bigger task”. As a result, the bigger task becomes simpler, and moreover, the custom command can be used to solve the “small problem” in a different context. Let us illustrate this on a simple example.
Karel is in his cellar. He needs to go through all four aisles, and move all objects to the opposite shelf across the isle:

Here, a repeating pattern is to proceed one step forward, move one object across the aisle, return into the aisle, and turn right. Let us create a custom command “oneobject” for that:

But this is not all. Another (higher-level) repeating pattern is to go through one aisle and move all nine objects from the left shelf to the right shelf. Let us create a custom command “oneaisle” for that:

With these two custom commands at hand, the task becomes much simpler. Can you do it?