Common Computer Science References
At the end of this lesson, you will be able to:
understand and use recursion
Magic Squares
what is a recursion
a function that calls itself
read "Functions", Chapter 3, Computer Based Problem Solving
read "Recursion"
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:
create a 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
create a second flowchart for:
a recursive function that generates 3x3 magic squares using only the numbers 1 to 9
you will need your function above!
this starter repo might help
do the above in a second language