Learning Outcome
At the end of this lesson, you will be able to:
- understand and use Recursion
Silent Watching
Review
Lesson
- go over "Procedures & Functions", Chapter 4
- Computer Based Problem Solving
- read "Recursion"
Activity
- read over this on Magic squares
- find out your magic number related to your birthday!
- email me your magic number
Daily Assignment
- magic squares are another great example of a problem that can be solved by using recursion
- Problem: create a program that generates all the magic squares with a magical number equal to 15
- this means all the integers from 1 to 9
- the easiest way to do this internally is to save the magic square in a 1 dimensional array of size 9 (ex [2,7,6,9,5,1,4,3,8])
- Before you start anything, ensure you have a design:
- this might help: http://www.math.colostate.edu/~betten/courses/M152/LECTURE/lecture9.html
- email me first your flowchart for:
- a function that accepts an array that is the magic square and returns whether it is a magic square or not (if it is not a valid 9 element array, automatically return False)
- to be magic all the rows, columns and diagonals must all be equal.
- as soon as this is not true, return false
- email me second your flowchart for:
- a recursive function that generates 3x3 magic squares using only the numbers 1 to 9
- you will need your function above
- Once I have both of your flowcharts, then you can start to code