6 kyu

Odd Magic Square

182 of 276Abelard_Snazz

Description:

Your task is to create a magic square for any positive odd integer N. The magic square contains the integers from 1 to N * N, arranged in an NxN matrix, such that the columns, rows and both main diagonals add up to the same number.

Note: use have to use the Siamese method for this task.

Examples:

n = 3
result = [
  [8, 1, 6],
  [3, 5, 7],
  [4, 9, 2]
]


n = 5
result = [
  [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]
]
Puzzles
Arrays
Mathematics

Similar Kata:

Stats:

CreatedApr 11, 2016
PublishedApr 11, 2016
Warriors Trained683
Total Skips42
Total Code Submissions768
Total Times Completed276
Python Completions182
Go Completions17
Rust Completions32
JavaScript Completions67
Total Stars23
% of votes with a positive feedback rating94% of 97
Total "Very Satisfied" Votes85
Total "Somewhat Satisfied" Votes12
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
  • ZozoFouchtra Avatar
  • smile67 Avatar
  • FArekkusu Avatar
  • bidouille Avatar
  • akar-0 Avatar
Ad