18
\$\begingroup\$

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.

Please add a few words on how your solution works.

asked Jun 4, 2017 at 9:59
\$\endgroup\$
2
  • 2
    \$\begingroup\$ Can this be done in hexagony? If so, I will put a bounty to reward that answer. \$\endgroup\$ Commented Jun 4, 2017 at 18:49
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ Commented Jun 28, 2017 at 16:25

10 Answers 10

9
\$\begingroup\$

Octave, 24 bytes

'IKRNFAQOHEGCMDBSJLP'-64

Try it online!

answered Jun 4, 2017 at 10:19
\$\endgroup\$
5
\$\begingroup\$

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]
answered Jun 4, 2017 at 11:31
\$\endgroup\$
4
\$\begingroup\$

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]
answered Jun 4, 2017 at 11:26
\$\endgroup\$
4
\$\begingroup\$

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œ•δn×ばつ„Á•è

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вoñ*$vn+•20в

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

Try it online!

answered Jun 4, 2017 at 10:32
\$\endgroup\$
0
3
\$\begingroup\$

SOGL, 15 bytes

3←@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 
answered Jun 4, 2017 at 10:30
\$\endgroup\$
3
\$\begingroup\$

Jelly, 21 bytes

18473955480703453œ?19

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

Try it online!

answered Jun 4, 2017 at 10:29
\$\endgroup\$
5
  • \$\begingroup\$ 18473955480703453 is 1 bytes shorter. \$\endgroup\$ Commented Jun 4, 2017 at 10:40
  • \$\begingroup\$ Correct me if I'm wrong, but wouldn't a list of code page indices be shorter? \$\endgroup\$ Commented Jun 4, 2017 at 11:26
  • \$\begingroup\$ 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). \$\endgroup\$ Commented Jun 4, 2017 at 11:42
  • \$\begingroup\$ @NickClifford it would be 21 bytes too (19 indexes, an open quote and a close quote). \$\endgroup\$ Commented Jun 4, 2017 at 11:48
  • \$\begingroup\$ @JonathanAllan Ah, got it. \$\endgroup\$ Commented Jun 4, 2017 at 11:49
2
\$\begingroup\$

APL, 24 bytes

⎕A⍳'RQCKAGSIFEBPNHDLOMJ'

Try it online!

How?

⎕A ⍝ 'ABC...
 ⍳ ⍝ indices of
 'RQCKAGSIFEBPNHDLOMJ' ⍝ ← this vector
answered Jun 4, 2017 at 12:51
\$\endgroup\$
1
\$\begingroup\$

JavaScript (ES6), 49 bytes

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

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

answered Jun 4, 2017 at 23:22
\$\endgroup\$
0
\$\begingroup\$

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}
answered Jun 4, 2017 at 10:45
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Note that kolmogorv-complexity actually is about data compression. \$\endgroup\$ Commented Jun 4, 2017 at 10:49
0
\$\begingroup\$

Japt, 27 bytes

Inspired by rahnema1's solution.

`ikrnfaqogcmdbsjlp`¨c -96

Try it online

answered Jun 4, 2017 at 14:17
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.