# THE Magic Hexagon

There are many magic squares, but there is just one non-trivial magic hexagon, as Dr. James Grime explained, which is the following:

  18 17  3
11  1  7 19
9  6  5  2 16
14  8  4 12
15 13 10


As it is done in Hexagony this is easiest written as just one line, by just reading it row by row:

18 17 3 11 1 7 19 9 6 5 2 16 14 8 4 12 15 13 10


Of course there are twelve such list representations of this magic hexagon in total, if you count rotations and reflections. For instance a clockwise 1/6 rotation of the above hexagon would result in

9 11 18 14 6 1 17 15 8 5 7 3 13 4 2 19 10 12 16


@Okx asked to list the remaining variants. The remaining lists are:

15 14 9 13 8 6 11 10 4 5 1 18 12 2 7 17 16 19 3
3 17 18 19 7 1 11 16 2 5 6 9 12 4 8 14 10 13 15
18 11 9 17 1 6 14 3 7 5 8 15 19 2 4 13 16 12 10
9 14 15 11 6 8 13 18 1 5 4 10 17 7 2 12 3 19 16


plus all the mentioned lists reversed.

### Challenge

Write a program that outputs the magic hexagon as a list. You can choose any of the 12 reflections/rotations of the hexagon.

• Can this be done in hexagony? If so, I will put a bounty to reward that answer. Jun 4, 2017 at 18:49
• @Mr.Xcoder Anything can be done in Hexagony. It probably just won't be very interesting, because I doubt that you'll be able to save bytes over just printing one of the lists literally. Jun 28, 2017 at 16:25

# Octave, 24 bytes

'IKRNFAQOHEGCMDBSJLP'-64


Try it online!

# Jelly, 11 bytes

“JɼQⱮȦ>Ȯ’Œ?


A niladic link returning the list of the given orientation reflected left-right.

Try it online!

### How?

Just the kind of thing for which I made Œ?

“JɼQⱮȦ>Ȯ’Œ? - Niladic link: no arguments
“JɼQⱮȦ>Ȯ’   - base 250 number, 18473955480703453
Œ? - shortest permutation of some set of natural numbers one through to some N
-   inclusive which would lie at that index in a list of all permutations of
-   those same natural numbers when sorted lexicographically.
-
-   - for example 7Œ?:
-   - since 7 is greater than 3! and less than 4!+1, it references four items
-   - the sorted order of permutations of 4 items is:
-   - [[1,2,3,4],[1,2,4,3],[1,3,2,4],[1,3,4,2],[1,4,2,3],[1,4,3,2],[2,1,3,4], ...]
-   - so 7Œ? yields [2,1,3,4]


# Pyth, 15 bytes

.PC"A¡öò\x06\x11Ý"S19


(Control characters replaced with \x06 and \x11 for your viewing convenience.)

Try it online

### How it works

   "A¡öò\x06\x11Ý"      magic string
C                     convert to number n using codepoints as base-256 digits
.P                S19   nth lexicographic permutation of [1, …, 19]


# 05AB1E, 14 bytes

Both solutions generate the list [3,17,18,19,7,1,11,16,2,5,6,9,12,4,8,14,10,13,15]

19Lœ•δn2м×„Á•è


Generates a list of all (sorted) permutations of the range [1...19] and indexes into that list with a base 255 compressed base 10 number.

Or 15 bytes runnable online

•áRвºñ*\$vn+•20в


Decompresses a base 255 string to a base 10 number and converts to a list of base 20 digits.

Try it online!

# SOGL, 15 bytes

³←@uΙΒQH√y׀“L«─


Explanation:

...“     push the number 4121998669867569415662783
L«   push 20
─  convert 4121998669867569415662783 from base 10 to a base 20 number aka base 10 array


# Jelly, 21 bytes

18473955480703453œ?19


I really want to compress that big number, but I'm not sure how.

Try it online!

• 18473955480703453 is 1 bytes shorter. Jun 4, 2017 at 10:40
• Correct me if I'm wrong, but wouldn't a list of code page indices be shorter? Jun 4, 2017 at 11:26
• RE compression: It's the same number I used in mine. All you have to do is convert the number to bijective base 250 using ḃ250 and index into the code page (which is now easier as there is a niladic atom for it, ØJ). Jun 4, 2017 at 11:42
• @NickClifford it would be 21 bytes too (19 indexes, an open quote and a close quote). Jun 4, 2017 at 11:48
• @JonathanAllan Ah, got it. Jun 4, 2017 at 11:49

# APL, 24 bytes

⎕A⍳'RQCKAGSIFEBPNHDLOMJ'


Try it online!

How?

⎕A                        ⍝ 'ABC...
⍳                       ⍝ indices of
'RQCKAGSIFEBPNHDLOMJ'  ⍝ ← this vector


# JavaScript (ES6), 49 bytes

[...'ih3b17j9652ge84cfda'].map(n=>parseInt(n,26))


console.log(
[...'ih3b17j9652ge84cfda'].map(n=>parseInt(n,26))
)

## Mathematica, 37 bytes

36^^md1o3apsqxqkfhq6~IntegerDigits~20


Explanation (that may be already obvious as Mathematica is not a codegolf language, but according to the OP requirement):

36  : Number base
^^  : Input a number in arbitrary base. See BaseForm documentation
md1o3apsqxqkfhq6 : the number in base 36
~IntegerDigits~20 : convert to base 20 as list of digits


Output:

{18,17,3,11,1,7,19,9,6,5,2,16,14,8,4,12,15,13,10}

• Note that kolmogorv-complexity actually is about data compression. Jun 4, 2017 at 10:49

# Japt, 27 bytes

Inspired by rahnema1's solution.

ikrnfaqogcmdbsjlp¬®c -96


Try it online