0% found this document useful (0 votes)
32 views1 page

Magic Squares

The document defines different types of magic squares: - A semimagic square is a 2D array where the sums of each row and column are equal. - A magic square also has equal sums along the two main diagonals. - An associative magic square additionally has pairs of numbers symmetrically opposite the center summing to N^2 + 1. The document describes extending an ARM assembly program to determine if a 2D array meets the criteria for these different types of magic squares, returning values from 0 to 3.

Uploaded by

CSstudent
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views1 page

Magic Squares

The document defines different types of magic squares: - A semimagic square is a 2D array where the sums of each row and column are equal. - A magic square also has equal sums along the two main diagonals. - An associative magic square additionally has pairs of numbers symmetrically opposite the center summing to N^2 + 1. The document describes extending an ARM assembly program to determine if a 2D array meets the criteria for these different types of magic squares, returning values from 0 to 3.

Uploaded by

CSstudent
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

A semimagic square is an N × N 2D array containing each of the positive integers

1, 2, 3, ... , N^2 arranged so the sum of the elements in each row and each column is equal. The

following is an example of an N × N magic square where the rows and columns all sum to 15.

267

915

483

(a) Design and write an ARM Assembly Language program to determine whether a square 2D
array of word-size values is a semimagic square, according to the definition above. (In other
words, the array must contain the positive integers 1, 2, 3, ... , N^2 and the sum of each row
and column must be equal.) The magic square is stored in RAM at the address in R1. The
number of rows/columns in the array is in R2. Your program should store the result in R0 as
follows: • 0 if the 2D array is not a semimagic square or • 1 if the 2D array is a semimagic
square.
(b) Extend your program from part (a) to determine whether the 2D array is a magic square. In
addition to satisfying the properties of a semimagic square, the sum of the elements in each
of the two major diagonals of a magic square must be equal. The following is an example of
an N × N magic square where the rows, columns and major diagonals all sum to 15.
816
357
492
Your program should now return: • 0 if the 2D array is not a semimagic square, • 1 if the 2D
array is a semimagic square that is not also magic, • 2 if the 2D array is a magic square.

Further extend your program from part (b) to determine whether the 2D array is an associative
magic square. An associative magic square is a magic square (according to the definition in parts (a)
and (b) above) in which pairs of numbers that are symmetrically opposite the centre of the square
sum to N^2 + 1.

The following is an example of an associative magic square:

17 24 1 8 15

23 5 7 14 16

4 6 13 20 22

10 12 19 21 3

11 18 25 2 9

Your program should now return:

• 0 if the 2D array is not a semimagic square,

• 1 if the 2D array is a semimagic square that is not also magic,

• 2 if the 2D array is a magic square,

• 3 if the 2D array is an associative magic square.

You might also like