First Summer 2008


Homework Five: Magic squares.
Due date
Tuesday May 27, 11:59pm

Late policy
E-mail the solutions as a text file to Adrian by the due date.

Late submissions will be accepted for full credit if:

Work policy
Working in groups is encouraged but please turn in your own version of the assignment.

Also, please make sure you

with the Computer Science Department's Statement on Academic Integrity before turning in your assignment.

Task
Implement the following procedure to construct magic n-by-n squares;
  • it works only if n is odd.
  • Place a 1 in the middle of the bottom row.
  • After k has been placed in the (i, j) square, place k+1 into the square to the right and down, wrapping around the borders.
  • However,
    1. if the square to the right and down has already been filled, or
    2. if you are in the lower right corner,
    then you must move to the square straight up instead.

Here's the 5-by-5 square that you get if you follow this method:

 11  18   25    2    9 
 10  12   19   21    3 
  4   6   13   20   22 
 23   5    7   14   16 
 17  24    1    8   15 
Check that the square above is magic.

Have your program also check that the square it generated is indeed magic.

Grading
Feedback by e-mail should reach you in 12 hours from the time of your submission.

If feedback doesn't come contact Adrian by e-mail or phone and report it.

Grades will be posted within 24 hours of your submission on your individual blog.