6 kyu

Double Even Magic Square

Description:

A Magic Square contains the integers 1 to n2, arranged in an n by n array such that the columns, rows and both main diagonals add up to the same number.
For doubly even positive integers (multiples of 4) the following method can be used to create a magic square.
Fill an array with the numbers 1 to n2 in succession. Then, for each 4 by 4 subarray, replace the entries on the blue and red diagonals by n2+1-aij.
So, in the following example, a11 (row 1, column 1) was initially 1 and is replaced by 82+1-1 = 64

n=8

642 3 61606 7 57
9 55541213515016
1747462021434224
4026273736303133
3234352928383925
4123224445191848
4915145253111056
8 58595 4 62631

The function even_magic() should return a 2D array as follows:-
Example:
n=4: Output: [[16,2,3,13],[5,11,10,8],[9,7,6,12],[4,14,15,1]]

162 3 13
5 11108
9 7 6 12
4 14151

Only doubly even numbers will be passed to the function in the tests.

See mathworld.wolfram.com for further details.

Fundamentals
Puzzles
Arrays
Mathematics

Similar Kata:

Stats:

CreatedApr 13, 2016
PublishedApr 14, 2016
Warriors Trained509
Total Skips123
Total Code Submissions523
Total Times Completed116
Python Completions116
Total Stars8
% of votes with a positive feedback rating96% of 42
Total "Very Satisfied" Votes39
Total "Somewhat Satisfied" Votes3
Total "Not Satisfied" Votes0
Total Rank Assessments10
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • Abelard_Snazz Avatar
  • Blind4Basics Avatar
Ad