Concept explainers
As early as 650 BC, mathematicians have been composing magic squares, a sequence of n numbers arranged in a square such that all rows, columns, and diagonals sum to the same constant. Used in China, India, and Arab countries for centuries, artist Albrecht Durer’s engraving Melencolia I (year: 1514) is considered the first time a magic square appears in European art. Each row, column, and diagonal of Dürer’s magic square sums to 34. In addition, each quadrant, the center four squares, and the corner squares all sum to 34. The following is an example of a magic square:
Write a program to determine if a series of numbers is indeed a 4 × 4 magic square. Your program should complete the following steps, in this order
- a. Ask the user to enter the proposed magic square in a single input statement (e.g., [1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16]—note this example is a 4 × 4 matrix, but NOT a magic square). You may assume the user will enter whole numbers; they will not enter either decimal values or text.
- b. Check that all values are positive; ** for-loop or nested for-loop required in the solution. If one or more of the values in the matrix are negative or zero, issue a statement to the command window informing the user of the mistake and ask the user to enter another matrix. This check should be repeated until the user enters a matrix with positive values. This check should work even if the user does not enter a 4 × 4 matrix; it should work regardless of the size of matrix entered.
- c. Check for an arrangement of 4 × 4 If the matrix is not a 4 × 4, issue a statement to the command window informing the user of the mistake, and ask the user to enter another matrix. This check should be repeated until the user enters a 4 × 4 matrix. You may assume the reentered matrix contains only positive values; you do not need to recheck the new matrix for positive values, only for matrix dimensions.
- d. Determine if the matrix is a form of a magic square. The minimum requirement to be classified as a magic square is each row and column sums to the same value. ** for-loop or nested for-loop required in the solution. If this criterion is not met, issue a statement to the command window informing the user they have not entered a magic square and ask the user if they wish to try another magic square. This question can be posed using either a text answer entered by the user (Yes, No) or by using a menu. If the user chooses to run the program again, the entire program starting with step (a) should begin again.
- e. Determine the classification of the magic square using the following requirements:
- 1. If each row and column sums to the same value, the magic square is classified as semi-magic; the summation value is ca led the magic constant. **for-loop or nested for-loop required in the solution.
- 2. If, in addition to criterion 1, each diagonal sums to the same value, the magic square is classified as normal; **for-loop or nested for-loop required in the solution. The use of built-in functions such as diag, flipir, rot90, trace or similar built-in functions is forbidden.
- 3. If, in addition to 1 and 2, the largest value in the magic square is equal to 16, the magic square is classified as perfect.
Format your magic square classification similar to the format shown below. You may choose to format your table differently, but each classification should contain a Yes or No next to each magic square category.
The magic constant for your magic square is 24. The classification for your magic square:
Semi-magic | Normal | Perfect |
Yes | Yes | Yes |
After this table appears, ask users if they wish to try another magic square following the instructions given earlier. A few test cases for you to consider:
- Albrecht Dürer magic square: [16, 3, 2, 13; 5, 10, 11, 8; 9, 6, 7, 12, 4, 15, 14, 1];
- Chautisa Yantra magic square: [7, 12, 1, 14, 2, 13, 8, 11; 16, 3, 10, 5; 9, 6, 15, 4];
- Sangrada Familia church, Barcelona magic square: [1, 14, 14, 4; 11, 7, 6, 9; 8, 10, 10, 5; 13, 2, 3, 15].
- Random magic square: [80, 15, 10, 65; 25, 50, 55, 40; 45, 30, 35, 60; 20, 75, 70, 5];
- Steve Wozniak’s magic square: [8, 11, 22, 1; 21, 2, 7, 12; 3, 24, 9, 6; 10, 5, 4, 23]
Want to see the full answer?
Check out a sample textbook solutionChapter 20 Solutions
Thinking Like an Engineer
- Q2: For the following figure, find the reactions of the system. The specific weight of the plate is 500 lb/ft³arrow_forwardQ1: For the following force system, find the moments with respect to axes x, y, and zarrow_forwardQ10) Body A weighs 600 lb contact with smooth surfaces at D and E. Determine the tension in the cord and the forces acting on C on member BD, also calculate the reaction at B and F. Cable 6' 3' wwwarrow_forward
- Help ارجو مساعدتي في حل هذا السؤالarrow_forwardQ3: Find the resultant of the force system.arrow_forwardQuestion 1 A three-blade propeller of a diameter of 2 m has an activity factor AF of 200 and its ratio of static thrust coefficient to static torque coefficient is 10. The propeller's integrated lift coefficient is 0.3.arrow_forward
- (L=6847 mm, q = 5331 N/mm, M = 1408549 N.mm, and El = 8.6 x 1014 N. mm²) X A ΕΙ B L Y Marrow_forwardCalculate the maximum shear stress Tmax at the selected element within the wall (Fig. Q3) if T = 26.7 KN.m, P = 23.6 MPa, t = 2.2 mm, R = 2 m. The following choices are provided in units of MPa and rounded to three decimal places. Select one: ○ 1.2681.818 O 2. 25745.455 O 3. 17163.636 O 4. 10727.273 ○ 5.5363.636arrow_forwardIf L-719.01 mm, = 7839.63 N/m³, the normal stress σ caused by self-weight at the location of the maximum normal stress in the bar can be calculated as (Please select the correct value of σ given in Pa and rounded to three decimal places.) Select one: ○ 1. 1409.193 2. 845.516 O 3. 11273.545 ○ 4.8455.159 ○ 5.4509.418 6. 2818.386 7.5636.772arrow_forward
- To calculate the rotation at Point B, a suitable virtual structure needs to be created. Which equation in the following choices most accurately represents the functional relationship between the bending moment, Mv2 ( Units: N.mm), of the virtual structure and the spatial coordinate x (Units: mm) if the applied unit virtual moment is clockwise? Select one: O 1. Mv2 1.000 O 2. Mv2=x+1.000 O 3. Mv2=x+0.000 4. Mv2 = -x-1.000 O 5. Mv2 -1.000 6. Mv2=-x+0.000arrow_forwardThe vertical deflection at Point B can be calculated as ( The following choices are provided in units of mm and rounded to three decimal places ; the downward deflection is negative and upward deflection is positive. ) Select one: 1. 1703.065 2. -1703.065 3. -2043.679 4.1362.452 5. -1362.452 6. 2043.679arrow_forwardThe second moments of area about z-axis, /z, and the second moments of area about y-axis, ly, can be calculated as Select one: O 1. I = Iz ○ 2. Ly ○ 3. ○ 4. ○ 5. = = Iz = *D' 64 I₁ = D, Iz Ly Ly = 32 *D' = = 3 Iz = *D' 32 = *D' O 6. Iy=D, Ly = D², Iz = 32 O 7. Ly = Iz D = 64 32arrow_forward
- Elements Of ElectromagneticsMechanical EngineeringISBN:9780190698614Author:Sadiku, Matthew N. O.Publisher:Oxford University PressMechanics of Materials (10th Edition)Mechanical EngineeringISBN:9780134319650Author:Russell C. HibbelerPublisher:PEARSONThermodynamics: An Engineering ApproachMechanical EngineeringISBN:9781259822674Author:Yunus A. Cengel Dr., Michael A. BolesPublisher:McGraw-Hill Education
- Control Systems EngineeringMechanical EngineeringISBN:9781118170519Author:Norman S. NisePublisher:WILEYMechanics of Materials (MindTap Course List)Mechanical EngineeringISBN:9781337093347Author:Barry J. Goodno, James M. GerePublisher:Cengage LearningEngineering Mechanics: StaticsMechanical EngineeringISBN:9781118807330Author:James L. Meriam, L. G. Kraige, J. N. BoltonPublisher:WILEY