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
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
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:
Created | Apr 13, 2016 |
Published | Apr 14, 2016 |
Warriors Trained | 509 |
Total Skips | 123 |
Total Code Submissions | 523 |
Total Times Completed | 116 |
Python Completions | 116 |
Total Stars | 8 |
% of votes with a positive feedback rating | 96% of 42 |
Total "Very Satisfied" Votes | 39 |
Total "Somewhat Satisfied" Votes | 3 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 10 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |