"Odd" Challenge in Computer Science

Our learners in Navy Band and Auburn Band are learning to read, analyze, write, and debug Python programs. As part of their experience, the kids spend a significant portion of each Computer Science block creating programs to solve coding challenges.

Creating a program to solve a challenge often takes significant cognitive work. It isn’t just the syntax of Python that one needs to know; a programmer must work to understand a problem deeply, and will often need to break it into its components parts to find his or her way to a viable solution. She will also need to consider computer science concepts that may facilitate a potential solution. Tenacity, collaboration, logical thinking, error correction, creativity, and the willingness to continuously iterate to a working program are all key to success.

At times, the coding challenges that our kids are presented cross over with mathematics and require thoughtful consideration of mathematical ideas. Often we see that this mathematical crossover means they may need to learn new ideas or deepen their understanding of familiar mathematical ideas.

Recently, Navy Band was presented this “spicy” challenge:

What is the sum of the first n odd numbers?

The learners were also given the following prompt for creating a Python program to investigate this question.

Add the first N odd numbers, where the user provides the value of N. That is, prompt the user for a number. Then, add up that many odd numbers. For example, if the user enters 3, add the first three odd numbers: 1, 3, and 5.

Writing a program to find the sum of a sequence of odd numbers poses a very difficult challenge for these 2nd and 3rd graders, many of whom are quite new to the discipline of Computer Science. The kids have worked with if statements and for loops, as well as integers and lists, but there is not one obvious path forward to answering this challenge.  There are several ways to approach it, which, in some sense, adds to its difficulty.

After being confronted with the challenge, several kids tried jumping right to a coding solution, and quickly met frustration.

Others turned first to a peer to talk through the challenge, and this paved the way for them recognizing important ideas and steps in their mathematical thinking, and articulating those important ideas and steps as a potential algorithm. Slowing down, thinking carefully, and collaborating before attempting to implement a solution in code proved to be a fruitful path forward.

With prompting from Mr. Mann, a pair of learners considered the question of finding the sum of the first four odd numbers. One learner offered, “I would add 1 and 3 to get 4. Then, I would add 5 to 4 to get 9. Then, I would add 7 to 9 to get 16.” In articulating how he would find the sum, this child offered a part of an algorithm for summing a sequence of odd numbers – an algorithm that would involve a loop when implemented in code.

During this conversation, the pair also posed two big questions: “How will the computer know what odd numbers are, and how will it know when to stop?” One of the learners began to see that starting from 1, each consecutive odd number could be generated by adding 2. That insight helped him begin to move toward a solution.

In that one Computer Science block, the Navy Band learners walked away from the conversation with a better understanding of the challenge and of their own mathematical thinking.  They began to understand parts of a viable algorithm and had the important experience of leaving a challenge unsolved. They also walked away with questions to consider. Over the next week, they will likely continue to wrestle with this challenge and possibly generate insights that will fuel them next class block. We can’t wait to see what they will do next!