Karel #5: Use Appropriate Tools Strategically

What It Means

Students can select the appropriate math tool to use and use it correctly to solve problems. In the real world, no one tells you that it is time to use the meter stick instead of the protractor.

Computer Programming Teaches Students to Be Selective About Tools They Use to Solve Problems

Computer programming offers many tools, of which only one or a few are optimal to use in a given situation. For example, there are two types of loops – the counting loop (repeat) and the conditional loop (while). The former should be used when the number of repetitions is know in advance, the latter in a situation when something needs to be repeated while some condition is satisfied. There are conditional statements (if-else) that students use to design general algorithms that are applicable to a variety of situations as opposed to a single scenario. In this way, they learn how to generalize and think abstractly. Let us give a simple example.

It is Halloween! Karel needs to pick up three eyeballs and enter his home square!

Below are six different programs which all solve the given task. However, looking at their differences reveals the ability of the student to use the most appropriate tools to solve the given problem. Program #1 uses just elementary commands without any programming logic (really bad code!):

Program #2 takes advantage of a repeating pattern, but it fails to realize that there is one additional repeating pattern on a finer scale:

Program #3 takes advantage of two levels of repeating patterns:

Program #4 uses an if-else statement to reduce the logic to a single nested loop:

Program #5 uses an if-else statement to reduce the logic to a single loop. One extra advantage of this approach is that the eyeballs can be anywhere in the row connecting the robot with the home square:

Last, Program #6 also works for randomly distributed objects, but moreover it does not require the home square to be exactly 12 steps away from the robot – it is more general than Program #5: