user
A magic square is an   **N×N**  square matrix whose numbers consist of consecutive numbers arranged so that the sum of each row and column,   *and*   both diagonals are equal to the same sum   (which is called the *magic number* or *magic constant*).

A magic square of doubly even order has a size that is a multiple of four   (e.g.     **4**, **8**, **12**).

This means that the subsquares also have an even size, which plays a role in the construction.

|  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- |
| **1** | **2** | **62** | **61** | **60** | **59** | **7** | **8** |
| **9** | **10** | **54** | **53** | **52** | **51** | **15** | **16** |
| **48** | **47** | **19** | **20** | **21** | **22** | **42** | **41** |
| **40** | **39** | **27** | **28** | **29** | **30** | **34** | **33** |
| **32** | **31** | **35** | **36** | **37** | **38** | **26** | **25** |
| **24** | **23** | **43** | **44** | **45** | **46** | **18** | **17** |
| **49** | **50** | **14** | **13** | **12** | **11** | **55** | **56** |
| **57** | **58** | **6** | **5** | **4** | **3** | **63** | **64** |

Task

Create a magic square of   **8 × 8**.

Related tasks

* Magic squares of odd order
* Magic squares of singly even order

See also

* Doubly Even Magic Squares (1728.org)
assistant
(formerly Perl 6)

See Magic squares/Raku for a general magic square generator.

Output:

With a parameter of 8:

```
 1  2 62 61 60 59  7  8
 9 10 54 53 52 51 15 16
48 47 19 20 21 22 42 41
40 39 27 28 29 30 34 33
32 31 35 36 37 38 26 25
24 23 43 44 45 46 18 17
49 50 14 13 12 11 55 56
57 58  6  5  4  3 63 64

The magic number is 260
```

With a parameter of 12:

```
  1   2   3 141 140 139 138 137 136  10  11  12
 13  14  15 129 128 127 126 125 124  22  23  24
 25  26  27 117 116 115 114 113 112  34  35  36
108 107 106  40  41  42  43  44  45  99  98  97
 96  95  94  52  53  54  55  56  57  87  86  85
 84  83  82  64  65  66  67  68  69  75  74  73
 72  71  70  76  77  78  79  80  81  63  62  61
 60  59  58  88  89  90  91  92  93  51  50  49
 48  47  46 100 101 102 103 104 105  39  38  37
109 110 111  33  32  31  30  29  28 118 119 120
121 122 123  21  20  19  18  17  16 130 131 132
133 134 135   9   8   7   6   5   4 142 143 144

The magic number is 870
```