a1tD0000007kWSbIAM

Course: CTE IT with Dobot
Lesson 5: Recursion

  • 9-12 grade
  • Intermediate

Lesson Description:

Learn to use the concept of recursion, and program Dobot to solve the Tower of Hanoi puzzle.

image description

Lesson Modules


Teaching Tips:




Teaching Tips:

Explore Module Overview

Students discover how robots and coded functions can be used to solve puzzles.

Students learn to code using a combination of all previous learned material to solve a puzzle using Dobot.

The teacher should check for understanding by asking questions


Questions

  • What is a recursive function?
  • How can it be applied in a real world product or situation?
  • How can I modify the code?


Higher order thinking question

  • What other sort of problem cane I have Dobot solve with recursive functions?

Hint: this is the first part of the solution  in Blockly code

def hanoi(n, start, dest, aux)
     if n>0:

def hanoi(n, start, dest, aux):
      if n>0:
               # program stops
      else:
               # Move n-1 discs from Start to Aux
               # Since the function needs a third peg to act as its own "Aux",
               # we'll give our "Dest" peg as the third peg.
               hanoi(n-1, start, aux, dest)

 

Hint: Once the function has been completed, you will need to feed it the values with the variables.

Hint:  You definitely want to include “move from” and “to” print commands to make sure the function was done correctly and providing proper solution steps for Dobot as you execute the code.  



Teaching Tips:

Prototype Module Overview

Each group or individual is to program Dobot with the following guidelines:

  • Dobot must follow the steps printed out by the Hanoi recursive function
  • Dobot must successfully solve the puzzle without problems and errors


A video of Dobot solving the game is available here, but only show it to students who you feel really need a helping hand as it does show the solution.


Coding Challenge!

Part 1

Take a few minutes to try to solve the Tower of Hanoi yourself:

https://www.mathsisfun.com/games/towerofhanoi.html

Write down the steps you had to take to solve the problem.


Part 2

Work on your Hanoi function first. Make sure it’s printing out the solution steps you wrote down yesterday in your practice. Execute just this part of the code (without Dobot doing anything) to make sure it’s displaying the proper steps.

NOTE!! You want the code to easily be changeable by just changing the value of the disc and peg values. This challenge is not about hard-coding each individual step for Dobot!



Teaching Tips:

Reflect Module Overview

Review with class on the benefit of using recursive functions in their code as well as with robots

Have students reflect and rate their performance as robot programmers. How many failed attempts? How much time? 



Questions and Answers

  1. Describe RECURSION in your own words?
    1. the repeated application of a recursive procedure of definition
    2. a function that calls itself
    3. something similar
  2. Give an example of recursion.

    1. Answers will vary
  3. What is the recursive case?

    1. the place in a recursive method where the function is called again.
  4. What is the base case?

    1. the place in a recursive method where the function is NOT called again.

  5. Did Dobot do anything unexpected while you were testing?

    1. Answers will vary
  6. Where did you identify the cause of it in your code?

    1. Answers will vary
  7. What did you find to be the most challenging part of the project?

    1. Answers will vary
  8. What new things did you learn during the project?

    1. Answers will vary


Describe RECURSION in your own words?

Give an example of recursion.

What is the recursive case?

What is the base case?

Did Dobot do anything unexpected while you were testing?

Where did you identify the cause of it in your code?

What did you find to be the most challenging part of the project?

What new things did you learn during the project?