http://wpt3ch.com/wp-content/uploads/2016/06/knight-on-the-rim-is-grim-codegolf-stackexchange-com.png

Mathematica, 44 40 bytes



I've currently got three solutions at the same byte count:

2[3,4,6,8][[Tr@⌊3.2-.8Abs[#-4.5]⌋]]&
Tr@⌈.85(4-Abs[#-4.5])⌉/.5->6,6->8&
⌊Tr@⌈.85(4-Abs[#-4.5])⌉^1.1608⌋&


All of those are unnamed functions that take pair of coordinates like 3, 4, which are 1-based.

I tried coming up with a somewhat explicit formula. The general pattern on the entire board looks like this:

enter image description here

The actual values of those colours (from lightest to darkest) are 2, 3, 4, 6, 8. That is:

2 3 4 4 4 4 3 2
3 4 6 6 6 6 4 3
4 6 8 8 8 8 6 4
4 6 8 8 8 8 6 4
4 6 8 8 8 8 6 4
4 6 8 8 8 8 6 4
3 4 6 6 6 6 4 3
2 3 4 4 4 4 3 2


We first exploit the symmetry by shifting the origin to the centre, taking the absolute value and subtracting the result from 4. This gives us coordinates 0.5 to 3.5 increasing from each corner. In order to make the centre coordinates the same we need to map 0.5 and 1.5 to different values and 2.5 and 3.5 to the same value. This is easily done by multiplying by 0.8 (gives0.4, 1.2, 2., 2.8) and flooring the result. So now we've got 0, 1, 2, 2 as distances from the centre. If we add up the coordinates in each cell, we get this table:

0 1 2 2 2 2 1 0
1 2 3 3 3 3 2 1
2 3 4 4 4 4 3 2
2 3 4 4 4 4 3 2
2 3 4 4 4 4 3 2
2 3 4 4 4 4 3 2
1 2 3 3 3 3 2 1
0 1 2 2 2 2 1 0


This has unique values for all the different possible results, so we simply use it as an index into 2[3,4,6,8].

In the second version we use ceiling instead floor. This way, 2, 3 and 4 are already correct, but we get 5 and 6 instead of 6 and 8, so we correct those manually with a substitution rule.

Finally, in the third version, we extend 5 and 6 upwards to 6 and 8 by means of exponentiation, followed by another floor operation.

Post a Comment

NulleDB

{picture#https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibliLNtbQTegNo8PunvOjCPuoaor8cydCc4HKNblXVL6etyQz3PvRt5qaJe70W44lnHjXGyglEwd8ghltu23bR_FC13vtwRATe4IbFVt-MaIQbZf2L6jv2rxvItmQQ1fQ5iJKEfbVaFAE/s1600/tien-tran-e1391086611796.png} Hello guys, I'm Judith White, a freelance web designer and Web Devloper, Iam Her To Help You. {facebook#https://www.facebook.com/nulledb/} {twitter#https://twitter.com/crackmywifi} {google#https://plus.google.com/u/0/113339369699471770120} {pinterest#https://www.pinterest.com/crackmywifi/} {youtube#YOUR_SOCIAL_PROFILE_URL}
Powered by Blogger.