Answers.Body: <p>I noticed a simplification of @RosieF's solution:</p>
  
  <blockquote>
    <p>Label the squares with two-number labels as follows:</p>
  
  <pre>
  4,2 0,3 1,4 2,0 3,1
  1,0 2,1 3,2 4,3 0,4
  3,3 4,4 0,0 1,1 2,2
  0,1 1,2 2,3 3,4 4,0
  2,4 3,0 4,1 0,2 1,3
  </pre>
    
    <p>Then two knights may occupy two squares x,y
    and X,Y iff those squares' first numbers x and X are different and
    their second numbers y and Y are different.</p>
  </blockquote>
  
  <p>Since there are 5 knights and only 5 different numbers in each direction, that means that every x-value must be occupied by a knight, and each of the possible y-values must be assigned to one of those knights.  If we sort the knights' coordinates by their x-value, then list only the y-value, then we wind up with some permutation of the numbers from 0 to 4.  Every valid placement of the knights produces a permutation of the numbers 0-4, and every permutation of those numbers corresponds to a valid arrangement of the knights.</p>
  
  <p>The total number of valid arrangements of the knights is thus 5!, or 120.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-12T22:33:56.213Z
Answers.LastActivityDate: 2019-12-12T22:33:56.213Z
Answers.UserDisplayName: Brilliand
Answers.Body: <p>Label the squares with two-number labels as follows:</p>
  
  <pre>
  4,2 0,3 1,4 2,0 3,1
  1,0 2,1 3,2 4,3 0,4
  3,3 4,4 0,0 1,1 2,2
  0,1 1,2 2,3 3,4 4,0
  2,4 3,0 4,1 0,2 1,3
  </pre>
  
  <p>Then two knights may occupy two squares x,y and X,Y iff those squares' first numbers x and X are different and their second numbers y and Y are different.</p>
  
  <p>Regard these numbers as modulo 5. Then the two-times table is as follows:</p>
  
  <pre>
   y 0 1 2 3 4
  2y 0 2 4 1 3
  </pre>
  
  <p>So if y and Y are different, so also are 2y and 2Y.</p>
  
  <p>If we have a solution, then what happens if we move each knight from x,y to x,2y? The knights' x's were all different from each other, and each x remained the same, so they remain all different from each other. Their y's were all different from each other, and different y's are still different after they get doubled, so they remain all different from each other. So the result is a solution.</p>
  
  <p>What does this doubling of the y's correspond to on the board? Magnifying it by a factor of sqrt(2) linearly, and turning it 135 degrees clockwise. Having magnified a solution once, we may magnify a second time (two magnifications double the solution linearly and turn it through 90 degrees) and a third, but a fourth magnification results in the original again.</p>
  
  <p>We may start with this solution</p>
  
  <pre>
  . . . . .
  . . n . .
  . n n n .
  . . n . .
  . . . . .
  </pre>
  
  <p>and magnify it 0, 1, 2 or 3 times, yielding a total of 4 solutions. In each case, the rows can be be cyclically permuted in any of 5 ways, as can the columns, to yield 25 cyclic permutations of each of these 4 solutions, for a total of 100.</p>
  
  <p>In addition we have the following solution</p>
  
  <pre>
  . . . . .     
  . . . . .     
  n n n n n     
  . . . . .     
  . . . . .     
  </pre>
  
  <p>This, too, may be magnified 0, 1, 2 or 3 times, yielding a total of 4 solutions. Each of these 4 solutions has only 5 cyclic permutations, for a total of 20 cyclic permutations from these 4 solutions.</p>
  
  <p>This makes a grand total of 100 + 20 = 120.</p>
  
  <p>As Jörg P. has shown, there are no more.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-12T18:55:32.933Z
Answers.LastActivityDate: 2019-12-14T05:48:32.880Z
Answers.LastEditDate: 2019-12-14T05:48:32.880Z
Answers.UserDisplayName: Rosie F
Answers.Body: <p>(EDIT: substantially revised because I hadn't thought carefully enough about Rosie F's labeling. The result is even cooler!)</p>
  <p>Thanks for all the great answers. I would like to add my own solution.</p>
  <p>It's key to label squares in the torus, as Rosie F and Brilliand did:</p>
  <pre>
  4,2 0,3 1,4 2,0 3,1
  1,0 2,1 3,2 4,3 0,4
  3,3 4,4 0,0 1,1 2,2
  0,1 1,2 2,3 3,4 4,0
  2,4 3,0 4,1 0,2 1,3
  </pre>
  <p>But we can do more than just label the squares: we can view the labeling as a map (transformation) from the torus to itself!</p>
  <p>Suppose we fix the centre cell 0,0 as an origin (and relabel 3 &amp; 4 to -2 &amp; -1 respectively). Let's track what happens to the straight lines under the labeling map. There are 6 straight lines each of 4 cells running through this origin. 6x4+1 = 25: check.</p>
  <p>The lines come in 3 pairs:</p>
  <ul>
  <li>vertical &amp; horizontal for rooks</li>
  <li>dexter &amp; sinister for bishops (terminology from heraldry: maybe related to the line through which a right-handed swordsman would commonly sweep his sword?)</li>
  <li>left-turn &amp; right-turn for knights (knight moves forward 2, then turns left or right)</li>
  </ul>
  <p>Labelings are completely determined by two values: e.g. where to place 1,0 &amp; 0,1, and we build up everything from there linearly. In particular, Rosie F started with:</p>
  <pre>
  1,0 -> -2,1 
  0,1 -> -2,-1
  </pre>
  <p>This maps both the rook lines to knight lines. Now adding/subtracting these gives:</p>
  <pre>
  1,1 -> 1,0
  1,-1 -> 0,2
  </pre>
  <p>So we are mapping bishop lines to rook lines. And adding another dose of &quot;rook&quot;:</p>
  <pre>
  2,1 -> -1,1
  1,2 -> -1,-1
  </pre>
  <p>And hence we are also mapping knight lines to bishop lines.</p>
  <p>Since R-&gt;N-&gt;B-&gt;R, we can view knights and bishops as just being rooks in other frames of reference. The number of ways to arrange 5 non-attacking rooks is obviously 5!, so the same must be true for 5 non-attacking knights - and <strong>also true for 5 non-attacking bishops</strong>!</p>
  <p>There are 480 possible labelings (known to their close friends as GL(2,5)). Each gives a frame of reference from which to view the antics of chess pieces. From some, e.g. bishop lines are fixed, while knights and rooks are swapped (e.g. 1,0-&gt;-2,-1 &amp; 0,1-&gt;1,-2). Others are much more alien, and pieces behave like chimerae (e.g. a combination of vertical rook and dexter bishop). It follows that even for these weird &quot;half-man-half-biscuit&quot; pieces, the number of ways that 5 can appear is exactly 120.</p>
  <p>EDIT: generalize to larger boards</p>
  <p>What happens if we generalize to different size boards? Let's say we have a pxp toroidal board, where p is an odd prime (in order to avoid division issues). Then through any point Z there are p+1 lines (with gradients 0,1,...,p-1 and infinity. Each line contains p points, including Z. Check: (p-1)(p+1) + 1 = p^2 ok</p>
  <p>Any non-singular 2x2 matrix will map the points A (1,0) &amp; B (0,1) to any two points C, D which are not collinear with O (0,0). But this defines a mapping from the lines including OA &amp; OB to the lines including OC &amp; OD, if we ignore the precise points mapped to.</p>
  <p>Doing some counting, there are (p^-1)(p^-2p) non-singular matrices and any pair of lines through the origin are mapped to any other pair of lines by (p-1)^2 matrices. There are thus (p-1)p line-to-line mappings, which is what you would expect.</p>
  <p>In larger boards, knights will not have a role, as they are &quot;local&quot; in action and can only access 8 squares. But nightriders are relevant to consider. Their lines are not as symmetric as rooks or bishops: a nightrider accesses twice as many lines, or twice as many squares. We would have to compare the left-nightrider and the right-nightrider with rook and bishop to have pieces of equivalent power.</p>
  <p>If p=7, then there are 8 lines through any point: rook, bishop and nightrider cover them all. If p=11, then we get 4 more lines due to a unit we can call camelrider. (If a knight's move is (2,1) then a camel's is (3,1).)</p>
  <p><a href="https://i.sstatic.net/LPSsu.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/LPSsu.png" alt="Examples for p=5,7,11" /></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-13T22:11:02.597Z
Answers.Text: The bishops have their own separate mapping, which is also dual to rooks and knights once you apply the appropriate mapping.
Answers.UserDisplayName: Brilliand
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-14T08:45:03.743Z
Answers.Text: @Brilliand: I'd done my own labeling 1,0->-2,-1 & 0,1->1,-2, which does fix the bishop lines. I only realized later that the choice of labels really does matter, and that Rosie F had done something very different. Hers is a better choice to work with because it shows the equivalence of R,N&B in a single map
Answers.UserDisplayName: Laska
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-13T04:28:47.330Z
Answers.LastActivityDate: 2020-07-17T06:15:56.740Z
Answers.LastEditDate: 2020-07-17T06:15:56.740Z
Answers.UserDisplayName: Laska
Answers.Body: <p>There are essentially six solutions that are rotationally and translationally unique.  Two of them yield five translations and five more rotated translations each, for a total of twenty:</p>
  
  <pre><code>NNNNN
  .....
  .....
  .....
  .....
  
  N....
  .N...
  ..N..
  ...N.
  ....N
  </code></pre>
  
  <p>The remaining four unique solutions can be translated to each of the 25 positions on the board, but are rotationally symmetric, giving a combination of 100 solutions:</p>
  
  <pre><code>..N..
  .....
  N.N.N
  .....
  ..N..
  
  .....
  ..N..
  .NNN.
  ..N..
  .....
  
  N...N
  .....
  ..N..
  .....
  N...N
  
  .....
  .N.N.
  ..N..
  .N.N.
  .....
  </code></pre>
  
  <p>This yields the total of 120 solutions found by @JörgP.'s program.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-12T19:59:44.877Z
Answers.Text: Its actually a C# program ;)
Answers.UserDisplayName: Jörg P.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-12T21:22:56.640Z
Answers.Text: @JörgP. Ah, Microsoft WeCantLegallyCallItJavaAnyMore.  Even worse then, as I primarily use a Mac and absolutely refuse to install Visual anything on my Windows machine.
Answers.UserDisplayName: Chromatix
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-12T23:03:12.130Z
Answers.Text: Your "third unique solution" doesn't exist as such; it's actually four other solutions that can each be translated to each of the 25 positions, but can't be rotated or reflected at all.  These four solutions are the four magnifications of the + sign that Rosie F described in her answer.
Answers.UserDisplayName: Brilliand
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-13T00:26:37.170Z
Answers.Text: I think I see it now, though her answer is hard to visualise as-is.  I'll edit mine.
Answers.UserDisplayName: Chromatix
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-13T14:34:22.127Z
Answers.Text: @Chromatix Just to set the record straight, C# is not a variant or descendant of Java, it's a completely separate language, with superficial similarities because it has similar aims and core concepts. Open source and cross-platform compilers for it are also available, as are online tools where you can paste code in and run it, such as https://tio.run/
Answers.UserDisplayName: IMSoP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-13T17:59:14.017Z
Answers.Text: @Chromatix I'm sorry, but I had to learn C# for work and so just used that. However I think translating that code to a C++ (or Java) program should be pretty straightforward. The C# "features" I used are basically only the Console.WriteLine calls ;) And I also want to add that I find C# much more compelling than Java up to now
Answers.UserDisplayName: Jörg P.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-13T22:25:50.410Z
Answers.Text: @Chromatix there are non-VS IDEs that support C#: Atom, Brackets, Sublime Text, Emacs, Vim [all via the OmniSharp plugin], or Jetbrains Rider if you prefer a more full featured IDE. Ye-olde text editor + .net core CLI is also an option.
Answers.UserDisplayName: asgallant
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-12T18:54:54.040Z
Answers.LastActivityDate: 2019-12-13T00:30:48.687Z
Answers.LastEditDate: 2019-12-13T00:30:48.687Z
Answers.UserDisplayName: Chromatix
Answers.Body: <p>More general answers:</p>
  <ol>
  <li><a href="http://oeis.org/A172532" rel="nofollow noreferrer">OEIS A172532</a>: Number of ways to place 5 nonattacking knights on an n X n toroidal board.</li>
  <li>my book <a href="http://www.kotesovec.cz/books/kotesovec_non_attacking_chess_pieces_2013_6ed.pdf" rel="nofollow noreferrer">Non-attacking chess pieces</a> (6ed, 2013), page 308, chapter &quot;k Knights on an n x n toroidal chessboard&quot;.</li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-15T04:14:30.750Z
Answers.Text: Hi Vaclav: welcome and thanks for the link. I gave an overall link to your website here https://chess.stackexchange.com/questions/27259/has-anyone-attempted-to-characterize-chess-mathematically/27275#27275. Simon Norton's interest was in group theory, and 5x5 board is a very interesting special case
Answers.UserDisplayName: Laska
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-15T04:23:41.067Z
Answers.Text: Btw Vaclav: I sent you an email in May, subject "Chess Math Problem", which I still hope might interest you. I have resent now: pls check your spam folder
Answers.UserDisplayName: Laska
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-15T06:27:56.227Z
Answers.Text: I have not received any such e-mail in May or now, not in spam. My e-mail address is kotesovec2(at)gmail.com, please send again.
Answers.UserDisplayName: Vaclav Kotesovec
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-15T07:13:37.643Z
Answers.Text: OK thanks, I was using an incorrect email address, Vaclav. Have resent. This is a problem in Standard Young Tableaux
Answers.UserDisplayName: Laska
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-14T15:09:54.173Z
Answers.LastActivityDate: 2020-07-14T15:09:54.173Z
Answers.UserDisplayName: Vaclav Kotesovec
Answers.Body: <p>Here is an answer in simple terms without coding. 120 because assuming there is one way to configure the pieces and the board is torodial and there are 25 squares 5 of which that are occupied by knights leaving 20 left. then the knights can occupy all remaining squares since the board is essentially infinite due to the torodial nature. plus they can occupy the four other squares that knights are currently on by rotating with other knights thus giving each knight 24 other squares to occupy  5*24=120 i believe this works.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-14T16:42:58.080Z
Answers.Text: Hi welcome to chess.stackexchange! I’m not sure I follow your argument. Suppose we have rooks rather than knights. Suppose we have a successful arrangement as you propose as Ra1b2c3d4e5. Then any other square e.g. a2 is attacked by two rooks. Can’t just put Ra1 there, because the other rook attacks it. Certainly can shift Rb2 to b1 simultaneously, but then the arithmetic is different from what you wrote. Sorry if I’ve misunderstood. Thanks so much
Answers.UserDisplayName: Laska
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-16T20:58:19.450Z
Answers.Text: Adding together all the different ways each individual piece can be positioned is not the way to go about this.  Generally, those values need to be multiplied, not added (to get the number of possible positions).
Answers.UserDisplayName: Brilliand
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-17T07:39:57.810Z
Answers.Text: If you look at the above solutions every square on the board is covered in one of the solutions so each knight can occupy every square on the board and since there are five knights each knight can a total of four other positions relative to other knights so 25 positions times four additional. The four other knights rotating to other positions thus giving each knight four configurations for each square it can occupy  equals 125. Its correct. not eloquent but correct
Answers.UserDisplayName: XCATHADOR
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-18T04:38:52.443Z
Answers.Text: @XCATHADOR You just produced the result 125, though.  That's not right.  (And in general, this question doesn't treat the same position with two knights swapped as a different position.)
Answers.UserDisplayName: Brilliand
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-14T11:52:47.330Z
Answers.LastActivityDate: 2019-12-14T11:52:47.330Z
Answers.UserDisplayName: XCATHADOR
Answers.Body: <p>This is my answer :)</p>
  
  <p>Spoiler alert: Answer is in a comment in the last line of the code block</p>
  
  <pre><code>using System;
  
  namespace Toroidal5Knights
  {
      class Program
      {
          static int solution = 0;
          static bool[,] board = new bool[5, 5];
  
          static int[] dx = { -1, 1, 2, 2, 1, -1, -2, -2 };
          static int[] dy = { -2, -2, -1, 1, 2, 2, 1, -1 };
  
          static int Wrap(int position)
          {
              if (position &gt;= 5) return position - 5;
              if (position &lt; 0) return position + 5;
              return position;
          }
          static bool PlacePossible(int posX, int posY)
          {
              for (int i = 0; i &lt; dx.Length; ++i)
              {
                  if (board[Wrap(posX + dx[i]), Wrap(posY + dy[i])]) return false;
              }
              return true;
          }
          static void SolveFiveKnights(int posX, int posY)
          {
              if (posY &gt;= 5)
              {
                  if (IsSolution())
                  {
                      PrintSolution();
                      solution++;
                  }
                  return;
              }
              if (posX &gt;= 5)
              {
                  SolveFiveKnights(0, posY + 1);
                  return;
              }
  
              if (PlacePossible(posX, posY))
              {
                  board[posX, posY] = true;
                  SolveFiveKnights(posX + 1, posY);
                  board[posX, posY] = false;
              }
              SolveFiveKnights(posX + 1, posY);
              return;
          }
          static bool IsSolution()
          {
              int count = 0;
              for (int i = 0; i &lt; 5; ++i)
              {
                  for (int j = 0; j &lt; 5; ++j)
                  {
                      if (board[i, j]) count++;
                  }
              }
              return count == 5;
          }
          static void PrintSolution()
          {
              Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
              for (int i = 0; i &lt; 5; ++i)
              { 
                  for (int j = 0; j &lt; 5; ++j)
                  {
                      if (board[i, j])
                      {
                          Console.Write(1);
                      }
                      else
                      {
                          Console.Write(0);
                      }
                  }
                  Console.WriteLine();
              }
              Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
          }
          static void Main(string[] args)
          {
              SolveFiveKnights(0, 0);
              Console.WriteLine(solution);
          }
      }
  }
  // So the number of solutions is 120.
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-12T15:14:01.983Z
Answers.Text: Welcome to chess.stackexchange! So what number pops up when you run your program?
Answers.UserDisplayName: Laska
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-12T15:17:20.593Z
Answers.Text: Thanks! I edited my code so you can scroll down to see the answer the program computes. I did it in this way so other people can avoid spoilers
Answers.UserDisplayName: Jörg P.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-12T15:51:47.907Z
Answers.Text: Your program doesn't seem to eliminate duplicates that are translations (in toroidal space) of another solution.  That means the answer it prints *should* be a multiple of 25, but it is not.  Therefore I suspect a bug.
Answers.UserDisplayName: Chromatix
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-12T16:06:36.867Z
Answers.Text: Sorry I was asleep. My apologies. Your answer is totally correct. Well done! Have you an explanation for why this number appears?
Answers.UserDisplayName: Laska
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-12T17:51:35.383Z
Answers.Text: It needn't be a multiple of 25, because of solutions which have only 5 distinct cyclic perms (e.g. a1, b2, c3, d4, e5).
Answers.UserDisplayName: Rosie F
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-12T18:07:19.780Z
Answers.Text: @RosieF That is a good point.  I hadn't realised that was in the solution set.
Answers.UserDisplayName: Chromatix
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-13T16:46:56.593Z
Answers.Text: Instead of the `dx` and `dy` arrays, couldn't you have done something along the lines of `Math.Abs(posX) + Math.Abs(posY) == 3 && Math.Max(posX, posY) == 2` ? The only possible int values here are 2 and 1 with any sign, in any order. Saves you a bit of looping :) Also, `if (position >= 5) return position - 5;` can be changed to `position = position % 5;` (it inherently also works for negative numbers, you always end up with a positive int between 0 and 4 (inclusive)). Sorry, the code reviewer in me couldn't help but help :)
Answers.UserDisplayName: Flater
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-13T17:44:59.550Z
Answers.Text: I don't exactly get how you mean the replacement of dx and dy. How exactly would you implement the PlacePossible check without them and especially with less iterations than the number of possible moves? For the second suggestion I would disagree, because I think in the way I wrote it it is clearer (at least to me) what is happening and performance should not be a concern in this particular use case (and I am also not sure if replacing an if with a modulo operation would actually result in a performance gain anyway)
Answers.UserDisplayName: Jörg P.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-12T15:11:32.217Z
Answers.LastActivityDate: 2019-12-12T15:16:08.673Z
Answers.LastEditDate: 2019-12-12T15:16:08.673Z
Answers.UserDisplayName: Jörg P.
Body: <p>The celebrated British mathematician and lover of public transport, Simon Norton, passed in 2019. He was the subject of a wonderful <a href="https://www.theguardian.com/books/2011/aug/24/genius-in-my-basement-review" rel="nofollow noreferrer">biography</a>. He was not a particular fan of chess, but here is a tiny gem due to him.</p>
  <ul>
  <li>How many ways are there to arrange 5 knights on a 5x5 toroidal chessboard so that <a href="http://mathworld.wolfram.com/KnightsProblem.html" rel="nofollow noreferrer">none of them attack one another</a>?</li>
  </ul>
  <p><em>“Toroidal” means the board has no edges. You can leave on the left and just appear in the board on the right. You can leave at the top and just appear at the bottom. And vice versa.</em></p>
  <hr />
  <p><strong>EDIT:</strong> Jörg P. has totally nailed it, so he gets the green tick. But his solution doesn't give any insight as to <em>why</em> the number is what it is. So I guess that's a bonus question:</p>
  <ul>
  <li><strong>Bonus question:</strong> why do you get this number <a href="https://chess.stackexchange.com/a/27308/3594">(120)</a>?</li>
  </ul>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-12-12T15:49:23.880Z
Comments.Text: This is what I though of so far. Because the board is toroidal, each knight will be attacking exactly 8 squares. All together then, 5 knights will be attacking 40 squares. Since there's only 25 squares altogether and 5 of those are occupied by the knights, it means that there are only 20 squares that can be attacked on each configuration. Other observation: knights on the edge attack the same colors as the color of their square, other knights attack squares of a different color. I don't know how to proceed from here further.
Comments.UserDisplayName: gstukelj
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-12-12T15:52:34.347Z
Comments.Text: Each empty square is attacked by an average of 2 knights, I agree. I don’t think the colour of squares is so helpful here
Comments.UserDisplayName: Laska
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-12-13T14:22:29.040Z
Comments.Text: Off topic but TIL that the Ultima world was toroidal
Comments.UserDisplayName: JollyJoker
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-12-13T22:39:05.037Z
Comments.Text: @gst, Like you said, each knight attacks eight squares, but you can place the knights such that each unoccupied square is attacked by _two_ of them. So you actually only need twenty unoccupied squares to accommodate the five knights.
Comments.UserDisplayName: Solomon Slow
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-07-15T07:20:03.050Z
Comments.Text: Yes bof focusing on the lines in this way seems to be absolutely the key. Can also distinguish between "left knight" & "rightknight", "dexter bishop" & "sinister bishop" just as one can distinguish between row and file. Can then imagine chimeric pieces such as "left-knight+dexter bishop". All these 15 units-types are equivalent under transformations of the board!
Comments.UserDisplayName: Laska
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-07-16T05:04:41.170Z
Comments.Text: OK, so the point of this puzzle is that the rook's graph, the bishop's graph, and the knight's graph on the 5x5 toroidal board are isomorphic, and there are 5! ways to place 5 nonattacking knights for the same reason that there are 5! ways to place 5 nonattacking rooks. How nice. Is this happenstance, or does it have some deep mathematical significance?
Comments.UserDisplayName: bof
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-07-16T05:13:10.947Z
Comments.Text: Each empty square is attacked by **exactly** two knights. That's obvious if you think of the knights as rooks (!) but it's easy to see from the start that 3 nonattacking knights can't all attack the same square. If you consider 8 knights all attacking one square, then they are in two groups of mutually attacking knights, so your nonattacking knights can only include one from each group.
Comments.UserDisplayName: bof
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-07-16T08:53:46.103Z
Comments.Text: If the knights are all the same color, then they may protect each other but they can't attack each other, so the answer is C(25,5)=53130. Why are they always called "nonattacking" pieces in these sorts of puzzles? Are we supposed to imagine knights of 5 different colors?
Comments.UserDisplayName: bof
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-07-16T09:22:57.573Z
Comments.Text: Strictly in FIDE Laws, pieces attack squares or opposing pieces. As you say, usage though for these puzzles (e.g. https://stackoverflow.com/questions/15219216/8-non-attacking-queens-algorithm-with-recursion#15226936) is looser. If you have a more felicitous phrasing, without making the wording clunky or confusing, I'm happy to change
Comments.UserDisplayName: Laska
Tags: <problems><chess-variants><mathematics><knights>
Title: Arrange 5 non-attacking knights on a 5x5 toroidal board
ThreadText: # Arrange 5 non-attacking knights on a 5x5 toroidal board
  
  (Asked by: username_0 on 2019-12-12)
  
  The celebrated British mathematician and lover of public transport, Simon Norton, passed in 2019. He was the subject of a wonderful [biography](https://www.theguardian.com/books/2011/aug/24/genius-in-my-basement-review). He was not a particular fan of chess, but here is a tiny gem due to him.
  
  * How many ways are there to arrange 5 knights on a 5x5 toroidal chessboard so that [none of them attack one another](http://mathworld.wolfram.com/KnightsProblem.html)?
  
  *“Toroidal” means the board has no edges. You can leave on the left and just appear in the board on the right. You can leave at the top and just appear at the bottom. And vice versa.*
  
  ---
  
  **EDIT:** username_8 P. has totally nailed it, so he gets the green tick. But his solution doesn't give any insight as to *why* the number is what it is. So I guess that's a bonus question:
  
  * **Bonus question:** why do you get this number [(120)](https://chess.stackexchange.com/a/27308/3594)?
  
  **Tags:** problems, chess-variants, mathematics, knights
  
  > **Comments:**
  > **username_1**: This is what I though of so far. Because the board is toroidal, each knight will be attacking exactly 8 squares. All together then, 5 knights will be attacking 40 squares. Since there's only 25 squares altogether and 5 of those are occupied by the knights, it means that there are only 20 squares that can be attacked on each configuration. Other observation: knights on the edge attack the same colors as the color of their square, other knights attack squares of a different color. I don't know how to proceed from here further.  
  > **username_0**: Each empty square is attacked by an average of 2 knights, I agree. I don’t think the colour of squares is so helpful here  
  > **username_2**: Off topic but TIL that the Ultima world was toroidal  
  > **username_3**: @gst, Like you said, each knight attacks eight squares, but you can place the knights such that each unoccupied square is attacked by _two_ of them. So you actually only need twenty unoccupied squares to accommodate the five knights.  
  > **username_0**: Yes bof focusing on the lines in this way seems to be absolutely the key. Can also distinguish between "left knight" & "rightknight", "dexter bishop" & "sinister bishop" just as one can distinguish between row and file. Can then imagine chimeric pieces such as "left-knight+dexter bishop". All these 15 units-types are equivalent under transformations of the board!  
  > **username_4**: OK, so the point of this puzzle is that the rook's graph, the bishop's graph, and the knight's graph on the 5x5 toroidal board are isomorphic, and there are 5! ways to place 5 nonattacking knights for the same reason that there are 5! ways to place 5 nonattacking rooks. How nice. Is this happenstance, or does it have some deep mathematical significance?  
  > **username_4**: Each empty square is attacked by **exactly** two knights. That's obvious if you think of the knights as rooks (!) but it's easy to see from the start that 3 nonattacking knights can't all attack the same square. If you consider 8 knights all attacking one square, then they are in two groups of mutually attacking knights, so your nonattacking knights can only include one from each group.  
  > **username_4**: If the knights are all the same color, then they may protect each other but they can't attack each other, so the answer is C(25,5)=53130. Why are they always called "nonattacking" pieces in these sorts of puzzles? Are we supposed to imagine knights of 5 different colors?  
  > **username_0**: Strictly in FIDE Laws, pieces attack squares or opposing pieces. As you say, usage though for these puzzles (e.g. https://stackoverflow.com/questions/15219216/8-non-attacking-queens-algorithm-with-recursion#15226936) is looser. If you have a more felicitous phrasing, without making the wording clunky or confusing, I'm happy to change  
  
  ---
  
  ## 7 answers
  
  ### Answer by username_8 on 2019-12-12. Score: 9 | Accepted answer
  
  This is my answer :)
  
  Spoiler alert: Answer is in a comment in the last line of the code block
  
  ```
  using System;
  
  namespace Toroidal5Knights
  {
      class Program
      {
          static int solution = 0;
          static bool[,] board = new bool[5, 5];
  
          static int[] dx = { -1, 1, 2, 2, 1, -1, -2, -2 };
          static int[] dy = { -2, -2, -1, 1, 2, 2, 1, -1 };
  
          static int Wrap(int position)
          {
              if (position >= 5) return position - 5;
              if (position < 0) return position + 5;
              return position;
          }
          static bool PlacePossible(int posX, int posY)
          {
              for (int i = 0; i < dx.Length; ++i)
              {
                  if (board[Wrap(posX + dx[i]), Wrap(posY + dy[i])]) return false;
              }
              return true;
          }
          static void SolveFiveKnights(int posX, int posY)
          {
              if (posY >= 5)
              {
                  if (IsSolution())
                  {
                      PrintSolution();
                      solution++;
                  }
                  return;
              }
              if (posX >= 5)
              {
                  SolveFiveKnights(0, posY + 1);
                  return;
              }
  
              if (PlacePossible(posX, posY))
              {
                  board[posX, posY] = true;
                  SolveFiveKnights(posX + 1, posY);
                  board[posX, posY] = false;
              }
              SolveFiveKnights(posX + 1, posY);
              return;
          }
          static bool IsSolution()
          {
              int count = 0;
              for (int i = 0; i < 5; ++i)
              {
                  for (int j = 0; j < 5; ++j)
                  {
                      if (board[i, j]) count++;
                  }
              }
              return count == 5;
          }
          static void PrintSolution()
          {
              Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
              for (int i = 0; i < 5; ++i)
              { 
                  for (int j = 0; j < 5; ++j)
                  {
                      if (board[i, j])
                      {
                          Console.Write(1);
                      }
                      else
                      {
                          Console.Write(0);
                      }
                  }
                  Console.WriteLine();
              }
              Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
          }
          static void Main(string[] args)
          {
              SolveFiveKnights(0, 0);
              Console.WriteLine(solution);
          }
      }
  }
  // So the number of solutions is 120.
  
  ```
  
  > **Comments:**
  > **username_0**: Welcome to chess.stackexchange! So what number pops up when you run your program?  
  > **username_8**: Thanks! I edited my code so you can scroll down to see the answer the program computes. I did it in this way so other people can avoid spoilers  
  > **username_7**: Your program doesn't seem to eliminate duplicates that are translations (in toroidal space) of another solution.  That means the answer it prints *should* be a multiple of 25, but it is not.  Therefore I suspect a bug.  
  > **username_0**: Sorry I was asleep. My apologies. Your answer is totally correct. Well done! Have you an explanation for why this number appears?  
  > **username_6**: It needn't be a multiple of 25, because of solutions which have only 5 distinct cyclic perms (e.g. a1, b2, c3, d4, e5).  
  > **username_7**: @username_6 That is a good point.  I hadn't realised that was in the solution set.  
  > **username_13**: Instead of the `dx` and `dy` arrays, couldn't you have done something along the lines of `Math.Abs(posX) + Math.Abs(posY) == 3 && Math.Max(posX, posY) == 2` ? The only possible int values here are 2 and 1 with any sign, in any order. Saves you a bit of looping :) Also, `if (position >= 5) return position - 5;` can be changed to `position = position % 5;` (it inherently also works for negative numbers, you always end up with a positive int between 0 and 4 (inclusive)). Sorry, the code reviewer in me couldn't help but help :)  
  > **username_8**: I don't exactly get how you mean the replacement of dx and dy. How exactly would you implement the PlacePossible check without them and especially with less iterations than the number of possible moves? For the second suggestion I would disagree, because I think in the way I wrote it it is clearer (at least to me) what is happening and performance should not be a concern in this particular use case (and I am also not sure if replacing an if with a modulo operation would actually result in a performance gain anyway)  
  
  ---
  
  ### Answer by username_5 on 2019-12-12. Score: 13
  
  I noticed a simplification of @username_6's solution:
  
  > Label the squares with two-number labels as follows:
  >
  > ```
  >
  > 4,2 0,3 1,4 2,0 3,1
  > 1,0 2,1 3,2 4,3 0,4
  > 3,3 4,4 0,0 1,1 2,2
  > 0,1 1,2 2,3 3,4 4,0
  > 2,4 3,0 4,1 0,2 1,3
  >
  > ```
  >
  > Then two knights may occupy two squares x,y
  > and X,Y iff those squares' first numbers x and X are different and
  > their second numbers y and Y are different.
  
  Since there are 5 knights and only 5 different numbers in each direction, that means that every x-value must be occupied by a knight, and each of the possible y-values must be assigned to one of those knights. If we sort the knights' coordinates by their x-value, then list only the y-value, then we wind up with some permutation of the numbers from 0 to 4. Every valid placement of the knights produces a permutation of the numbers 0-4, and every permutation of those numbers corresponds to a valid arrangement of the knights.
  
  The total number of valid arrangements of the knights is thus 5!, or 120.
  
  
  ---
  
  ### Answer by username_6 on 2019-12-12. Score: 9
  
  Label the squares with two-number labels as follows:
  
  ```
  
  4,2 0,3 1,4 2,0 3,1
  1,0 2,1 3,2 4,3 0,4
  3,3 4,4 0,0 1,1 2,2
  0,1 1,2 2,3 3,4 4,0
  2,4 3,0 4,1 0,2 1,3
  
  ```
  
  Then two knights may occupy two squares x,y and X,Y iff those squares' first numbers x and X are different and their second numbers y and Y are different.
  
  Regard these numbers as modulo 5. Then the two-times table is as follows:
  
  ```
  
   y 0 1 2 3 4
  2y 0 2 4 1 3
  
  ```
  
  So if y and Y are different, so also are 2y and 2Y.
  
  If we have a solution, then what happens if we move each knight from x,y to x,2y? The knights' x's were all different from each other, and each x remained the same, so they remain all different from each other. Their y's were all different from each other, and different y's are still different after they get doubled, so they remain all different from each other. So the result is a solution.
  
  What does this doubling of the y's correspond to on the board? Magnifying it by a factor of sqrt(2) linearly, and turning it 135 degrees clockwise. Having magnified a solution once, we may magnify a second time (two magnifications double the solution linearly and turn it through 90 degrees) and a third, but a fourth magnification results in the original again.
  
  We may start with this solution
  
  ```
  
  . . . . .
  . . n . .
  . n n n .
  . . n . .
  . . . . .
  
  ```
  
  and magnify it 0, 1, 2 or 3 times, yielding a total of 4 solutions. In each case, the rows can be be cyclically permuted in any of 5 ways, as can the columns, to yield 25 cyclic permutations of each of these 4 solutions, for a total of 100.
  
  In addition we have the following solution
  
  ```
  
  . . . . .     
  . . . . .     
  n n n n n     
  . . . . .     
  . . . . .     
  
  ```
  
  This, too, may be magnified 0, 1, 2 or 3 times, yielding a total of 4 solutions. Each of these 4 solutions has only 5 cyclic permutations, for a total of 20 cyclic permutations from these 4 solutions.
  
  This makes a grand total of 100 + 20 = 120.
  
  As username_8 P. has shown, there are no more.
  
  
  ---
  
  ### Answer by username_0 on 2019-12-13. Score: 7
  
  (EDIT: substantially revised because I hadn't thought carefully enough about username_6 F's labeling. The result is even cooler!)
  
  Thanks for all the great answers. I would like to add my own solution.
  
  It's key to label squares in the torus, as username_6 F and username_5 did:
  
  ```
  
  4,2 0,3 1,4 2,0 3,1
  1,0 2,1 3,2 4,3 0,4
  3,3 4,4 0,0 1,1 2,2
  0,1 1,2 2,3 3,4 4,0
  2,4 3,0 4,1 0,2 1,3
  
  ```
  
  But we can do more than just label the squares: we can view the labeling as a map (transformation) from the torus to itself!
  
  Suppose we fix the centre cell 0,0 as an origin (and relabel 3 & 4 to -2 & -1 respectively). Let's track what happens to the straight lines under the labeling map. There are 6 straight lines each of 4 cells running through this origin. 6x4+1 = 25: check.
  
  The lines come in 3 pairs:
  
  * vertical & horizontal for rooks
  * dexter & sinister for bishops (terminology from heraldry: maybe related to the line through which a right-handed swordsman would commonly sweep his sword?)
  * left-turn & right-turn for knights (knight moves forward 2, then turns left or right)
  
  Labelings are completely determined by two values: e.g. where to place 1,0 & 0,1, and we build up everything from there linearly. In particular, username_6 F started with:
  
  ```
  
  1,0 -> -2,1 
  0,1 -> -2,-1
  
  ```
  
  This maps both the rook lines to knight lines. Now adding/subtracting these gives:
  
  ```
  
  1,1 -> 1,0
  1,-1 -> 0,2
  
  ```
  
  So we are mapping bishop lines to rook lines. And adding another dose of "rook":
  
  ```
  
  2,1 -> -1,1
  1,2 -> -1,-1
  
  ```
  
  And hence we are also mapping knight lines to bishop lines.
  
  Since R->N->B->R, we can view knights and bishops as just being rooks in other frames of reference. The number of ways to arrange 5 non-attacking rooks is obviously 5!, so the same must be true for 5 non-attacking knights - and **also true for 5 non-attacking bishops**!
  
  There are 480 possible labelings (known to their close friends as GL(2,5)). Each gives a frame of reference from which to view the antics of chess pieces. From some, e.g. bishop lines are fixed, while knights and rooks are swapped (e.g. 1,0->-2,-1 & 0,1->1,-2). Others are much more alien, and pieces behave like chimerae (e.g. a combination of vertical rook and dexter bishop). It follows that even for these weird "half-man-half-biscuit" pieces, the number of ways that 5 can appear is exactly 120.
  
  EDIT: generalize to larger boards
  
  What happens if we generalize to different size boards? Let's say we have a pxp toroidal board, where p is an odd prime (in order to avoid division issues). Then through any point Z there are p+1 lines (with gradients 0,1,...,p-1 and infinity. Each line contains p points, including Z. Check: (p-1)(p+1) + 1 = p^2 ok
  
  Any non-singular 2x2 matrix will map the points A (1,0) & B (0,1) to any two points C, D which are not collinear with O (0,0). But this defines a mapping from the lines including OA & OB to the lines including OC & OD, if we ignore the precise points mapped to.
  
  Doing some counting, there are (p^-1)(p^-2p) non-singular matrices and any pair of lines through the origin are mapped to any other pair of lines by (p-1)^2 matrices. There are thus (p-1)p line-to-line mappings, which is what you would expect.
  
  In larger boards, knights will not have a role, as they are "local" in action and can only access 8 squares. But nightriders are relevant to consider. Their lines are not as symmetric as rooks or bishops: a nightrider accesses twice as many lines, or twice as many squares. We would have to compare the left-nightrider and the right-nightrider with rook and bishop to have pieces of equivalent power.
  
  If p=7, then there are 8 lines through any point: rook, bishop and nightrider cover them all. If p=11, then we get 4 more lines due to a unit we can call camelrider. (If a knight's move is (2,1) then a camel's is (3,1).)
  
  [![Examples for p=5,7,11](https://i.sstatic.net/LPSsu.png)](https://i.sstatic.net/LPSsu.png)
  
  > **Comments:**
  > **username_5**: The bishops have their own separate mapping, which is also dual to rooks and knights once you apply the appropriate mapping.  
  > **username_0**: @username_5: I'd done my own labeling 1,0->-2,-1 & 0,1->1,-2, which does fix the bishop lines. I only realized later that the choice of labels really does matter, and that username_6 F had done something very different. Hers is a better choice to work with because it shows the equivalence of R,N&B in a single map  
  
  ---
  
  ### Answer by username_7 on 2019-12-12. Score: 7
  
  There are essentially six solutions that are rotationally and translationally unique. Two of them yield five translations and five more rotated translations each, for a total of twenty:
  
  ```
  NNNNN
  .....
  .....
  .....
  .....
  
  N....
  .N...
  ..N..
  ...N.
  ....N
  
  ```
  
  The remaining four unique solutions can be translated to each of the 25 positions on the board, but are rotationally symmetric, giving a combination of 100 solutions:
  
  ```
  ..N..
  .....
  N.N.N
  .....
  ..N..
  
  .....
  ..N..
  .NNN.
  ..N..
  .....
  
  N...N
  .....
  ..N..
  .....
  N...N
  
  .....
  .N.N.
  ..N..
  .N.N.
  .....
  
  ```
  
  This yields the total of 120 solutions found by @JörgP.'s program.
  
  > **Comments:**
  > **username_8**: Its actually a C# program ;)  
  > **username_7**: @JörgP. Ah, Microsoft WeCantLegallyCallItJavaAnyMore.  Even worse then, as I primarily use a Mac and absolutely refuse to install Visual anything on my Windows machine.  
  > **username_5**: Your "third unique solution" doesn't exist as such; it's actually four other solutions that can each be translated to each of the 25 positions, but can't be rotated or reflected at all.  These four solutions are the four magnifications of the + sign that username_6 F described in her answer.  
  > **username_7**: I think I see it now, though her answer is hard to visualise as-is.  I'll edit mine.  
  > **username_9**: @username_7 Just to set the record straight, C# is not a variant or descendant of Java, it's a completely separate language, with superficial similarities because it has similar aims and core concepts. Open source and cross-platform compilers for it are also available, as are online tools where you can paste code in and run it, such as https://tio.run/  
  > **username_8**: @username_7 I'm sorry, but I had to learn C# for work and so just used that. However I think translating that code to a C++ (or Java) program should be pretty straightforward. The C# "features" I used are basically only the Console.WriteLine calls ;) And I also want to add that I find C# much more compelling than Java up to now  
  > **username_10**: @username_7 there are non-VS IDEs that support C#: Atom, Brackets, Sublime Text, Emacs, Vim [all via the OmniSharp plugin], or Jetbrains Rider if you prefer a more full featured IDE. Ye-olde text editor + .net core CLI is also an option.  
  
  ---
  
  ### Answer by username_11 on 2020-07-14. Score: 3
  
  More general answers:
  
  1. [OEIS A172532](http://oeis.org/A172532): Number of ways to place 5 nonattacking knights on an n X n toroidal board.
  2. my book [Non-attacking chess pieces](http://www.username_11.cz/books/kotesovec_non_attacking_chess_pieces_2013_6ed.pdf) (6ed, 2013), page 308, chapter "k Knights on an n x n toroidal chessboard".
  
  > **Comments:**
  > **username_0**: Hi username_11: welcome and thanks for the link. I gave an overall link to your website here https://chess.stackexchange.com/questions/27259/has-anyone-attempted-to-characterize-chess-mathematically/27275#27275. Simon Norton's interest was in group theory, and 5x5 board is a very interesting special case  
  > **username_0**: Btw username_11: I sent you an email in May, subject "Chess Math Problem", which I still hope might interest you. I have resent now: pls check your spam folder  
  > **username_11**: I have not received any such e-mail in May or now, not in spam. My e-mail address is kotesovec2(at)gmail.com, please send again.  
  > **username_0**: OK thanks, I was using an incorrect email address, username_11. Have resent. This is a problem in Standard Young Tableaux  
  
  ---
  
  ### Answer by username_12 on 2019-12-14. Score: 1
  
  Here is an answer in simple terms without coding. 120 because assuming there is one way to configure the pieces and the board is torodial and there are 25 squares 5 of which that are occupied by knights leaving 20 left. then the knights can occupy all remaining squares since the board is essentially infinite due to the torodial nature. plus they can occupy the four other squares that knights are currently on by rotating with other knights thus giving each knight 24 other squares to occupy 5\*24=120 i believe this works.
  
  > **Comments:**
  > **username_0**: Hi welcome to chess.stackexchange! I’m not sure I follow your argument. Suppose we have rooks rather than knights. Suppose we have a successful arrangement as you propose as Ra1b2c3d4e5. Then any other square e.g. a2 is attacked by two rooks. Can’t just put Ra1 there, because the other rook attacks it. Certainly can shift Rb2 to b1 simultaneously, but then the arithmetic is different from what you wrote. Sorry if I’ve misunderstood. Thanks so much  
  > **username_5**: Adding together all the different ways each individual piece can be positioned is not the way to go about this.  Generally, those values need to be multiplied, not added (to get the number of possible positions).  
  > **username_12**: If you look at the above solutions every square on the board is covered in one of the solutions so each knight can occupy every square on the board and since there are five knights each knight can a total of four other positions relative to other knights so 25 positions times four additional. The four other knights rotating to other positions thus giving each knight four configurations for each square it can occupy  equals 125. Its correct. not eloquent but correct  
  > **username_5**: @username_12 You just produced the result 125, though.  That's not right.  (And in general, this question doesn't treat the same position with two knights swapped as a different position.)  
  
  ---
  
  