Karel #8: Look for and Express Regularity in Repeated Reasoning

What It Means

Keep an eye on the big picture while working out the details of the problem. You don’t want kids that can solve the one problem you’ve given them; you want students who can generalize their thinking.

Computer Programming Teaches Students to Generalize Their Thinking:
Use Solutions to Simpler Problems to Solve More Complicated Ones

This standard makes sure that students can generalize their thinking, and use what they already know, to solve a more complicated problem. Let me illustrate this on the game “Square Shelf” from the Karel Course. Here, Karel is in a diamond mine, and his task is to move all gems on the marks and enter his home square:

Let’s not discuss how this problem is solved – we will just assume that the student solved it. The solution program is:

Our concern is different – lets make the problem harder, and see if the students can generalize what they did before to solve it. New there will be additional walls in between the gems and the marks:

The key here is to realize that with the exception of the very first and very last “go” command, every other “go” command would mean to cross the wall. Of course this is impossible, the robot would crash. So all we need to do is replace the “go” commands on lines 5 and 7 with a custom command “goaround” that makes the robot go around the new walls. The complete solution then looks as follows:

We can see that almost the entire logic from the solution of the simpler problem was preserved. Only minor adjustments were needed to solve the more complicated problem. Isn’t this beautiful?