Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Make a flow chart and pseudocode a function called oddMyMagic that inputs a scalar n and outputs a n-by-n magic square array. A magic square

Make a flow chart and pseudocode a function called oddMyMagic that inputs a scalar n and outputs a n-by-n magic square array. A magic square is an arrangement of the numbers 1 to n^2 in an n-by-n array with each number occuring exactly once such that the sum of the elements of any row, any column, or either of the diagonals is the same.

For example if you type in

A = oddMyMagic(3)

a 3-by-3 matrix is created where the sum of all squares in every direction is 15.

The output is obviously the matrix that is created. image text in transcribed

Problem 3: Make a flow chart and pseudocode then code the corresponding function called oddMyMagic that inputs a scalar n and outputs an n- n magic square array. A magic square is an arrangement of the numbers 1 to n? in an n-by-n array with each number occuring exactly once such that the sum of the elements of any row, any column, or either of the diagonals is the same. The figure below shows a magic square for n 3. Per Wikipedia there exists a quick, elegant 2 7 6 15 9 5 1 15 4 3 81 15 15 15 15 15 15 Figure 2: A 3-by-3 magic square in which any row, column, or diagonal sums to 15. method to construct the magic square when n is odd. In the central column of the first row, place the number 1. After that, the fundamental movement for filling the square is diagonally up and right, one step at a time. If a filled square is encountered, one moves vertically down one square instead, then continues as before. When an "up-and-to-the-right" move would leave the square, it is wrapped around to the last row and first column, respectively. This is demonstrated in the figure below step 3 step 4 step 22 step 1 3 21 2 Move up and to the right. Moving up and to the right Place 1 in the first row, Move up and to the right. In this case, up is off the board in this case, right is off the board encounters a filled space. center column the movement is wrapped Move down instead. the movement is wrapped around to the left. around to the bottom step 9 step 8 step 5 step 7 step 65 816 38 1 6 3 5 7 3 5 7 479 2 4 2 4 2 4 2 Move up and to the right. Move up and to the right Moving up and to the right Move up and to the right. In this case, right is off the board In this case, up is off the board encounters a filled space The movement is wrapped (after wrapping around). The movement is wrapped around to the bottom. Move down instead. around to the left Figure 3: The Siamese method for solving the magic square when n is odd

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions

Question

start to review and develop your employability skills

Answered: 1 week ago