# Puzzle Coding

#### Summary

Tactile activities or "tactivities" are one form of active learning that can increase student participation and enhance students' understanding of conceptual materials. In this tactile activity, students will solve problems by arranging physical strips of paper or textboxes online that contain Matlab code. This reduced the extraneous cognitive load on the students while reinforcing introductory programming concepts such as basic logic, programming structures, and debugging.

## Learning Goals

**Learning Objectives and Goals:**

- Review usage of for loops while loops, and if statements.
- Review of programming logic and logical operators.
- Review proper coding techniques including indentation and documentation.
- Practice testing and debugging techniques.
- Determine test cases.

**MATLAB Usage:**

In this activity, groups of students solve problems using prewritten snippets of MATLAB code. These code snippets must be rearranged to correctly solve the problem without causing errors. The students then use Matlab to check their work. This allows students to easily work in groups to discuss the programming logic needed to solve programs in Matlab.

## Context for Use

The activity described below was done in an introductory programming course taught within an applied mathematics department with an emphasis on programming to solve problems. The class consisted of approximately 20 students who were all either applied mathematics, physics, or engineering majors. This course was run as a flipped classroom, where students watch lecture videos outside of class and spend class periods working on programming exercises, projects, and tactile activities (tactivities).

Students should have some experience with programming structures such as if statements and loops. This activity reinforces these concepts. This activity could be implemented in any course where students are expected to program using MATLAB.

## Description and Teaching Materials

**Materials**

- Dry Erase Markers
- 2 Whiteboards per Group
- Sticky Notes per Group
- Code Strips (Strips of Paper with Lines of Code Written on Them) for Each Group

**Directions**

- Break into groups of 2-3 students and collect the group materials.
- Use the code strips to create a function or script that solves each of the problems (see Figure 1)
- When arranging the code strips, indent the strips appropriately. This means indent any lines of code that are within a function, loop, or if statement (see Figure 2).
- Use sticky notes to add comments to the lines of code.
- Determine appropriate test cases to check your functions.
- Desk check your code. Use one of the provided whiteboards as your command window and one to use as their workspace. "Run" your program by:
- Write appropriate command(s) into the command window.
- Read through your function line by line.
- Track the current value of all defined variables in the workspace whiteboard.

- Use MATLAB to verify your answer is correct.

**Example Coding Scenarios**

- Write a function to find all of the Fibonacci numbers that are less than N. Recall that the Fibonacci numbers are found by computing the sum of the two previous numbers in the sequence.
- Write a function to compute the first N Fibonacci numbers. Recall that the Fibonacci numbers are found by computing the sum of the two previous numbers in the sequence.
- Write a function that takes a numerical test score and determines the grade earned according to the standard ten-point grading scale.
- Write a function to determine if a number is prime.

**Code Strips for Scenarios 1 and 2**

function A=Fibonacci(N)

for j=3:N

while A(j)j=2;

j=j+1;

A(j)=A(j-1)+A(j-2);

A(1)=1;

A(2)=1;

end

end

**Code Strips for Scenario 3**

function grade=computeGrade(score)

if score>=90

elseif score>=80

elseif score>=70

elseif score>=60

else

else

if (score>=0 && score<=100)

if (score>=0 || score<=100)

grade='Illegal Input';

grade='A';

grade='B';

grade='C';

grade='D';

grade='F';

end

end

end

**Code Strips for Scenario 4**

function out=isPrime(n)

out = false;

out = false;

out = true;

out = true;

for k=2:n-1

if n==0 || n==1

if rem(n,k)==0

else

break

end

end

end

end

**Post-Activity Discussion**

- What skills have you learned from engaging in this task that you may be able to use to help you in your future programming assignments?
- What is the importance of determining good test cases? How did you determine your test cases?
- What kind of errors did you make with working through this task? How did you fix your errors?
- What's the purpose of the workspace, editor, and command window in MATLAB? What was each of these represented by in this activity?
- Explain the importance of indentation when writing a program.

**Extension**

If you have students that are able to quickly work through are or are highly engaged with this activity, you could ask them to create their own coding scenario by writing sample code on strips of paper for another group and have them arrange the strips in order.

Here is a PDF version of this task.

PuzzleCoding.pdf (Acrobat (PDF) 925kB Oct19 21)

Here is a PDF of a presentation on the activity given at JMM in 2021. This demonstrates how the task can be done in an online setting.

JMMTactivitiesPresentation.pdf (Acrobat (PDF) 764kB Sep16 21)

## Teaching Notes and Tips

**Class set up**

- In-person: Assign students into groups. Have a complete set of code pieces and a whiteboard for each group.

- Online: Assign students into breakout room groups. Give each group a link to a slide containing a picture of the MATLAB editor.

**Puzzle Coding Reflections**

- By removing the syntax of MATLAB, students could focus on logic and debugging.

- Students focus on understanding each line of code.

- Explore the relationship between workspace, editor, and command window.

- Could be done early on - as soon as students learn how to define variables.

**Challenges**

- Students who struggled with the workspace also struggled to get started.

- Some students focused too much on the ideas of proper coding habits (indentation and documentation), which possibly conflated the goal of the task.

- This was done in the second course in the sequence, so it mainly served as a review.

**Recommendations**

- Model this with a simple example (e.g. for loop that defines x to be the even numbers less than 10).

- Consider not asking students to indent and comment on their code and instead focus on the order of the lines and the variables defined in the workspace.

- This activity could be done as soon as students learn how to define variables.

## Assessment

Formative assessment could be used for this assignment to gain an understanding of student misconceptions related to programming logic. Students will be working in groups to arrange the code strips. Before students are given the next packet of code strips, they should check in with the instructor. During each check-in, have a different student explain the group's answer. Any misconceptions can be corrected at this time.

## References and Resources

[1] Barnes, J., & Libertini, J. M. (2018).*Tactile Learning Activities in Mathematics: A Recipe Book for the Undergraduate Classroom* (Vol. 54). American Mathematical Soc.