{"id":1369,"date":"2021-05-27T11:44:18","date_gmt":"2021-05-27T06:14:18","guid":{"rendered":"https:\/\/soulofmathematics.com\/?p=1369"},"modified":"2021-05-27T11:44:19","modified_gmt":"2021-05-27T06:14:19","slug":"the-knights-tour","status":"publish","type":"post","link":"https:\/\/soulofmathematics.com\/index.php\/the-knights-tour\/","title":{"rendered":"The Knight&#8217;s Tour"},"content":{"rendered":"\n<p>The\u00a0<strong>knight&#8217;s tour problem<\/strong>\u00a0is the\u00a0mathematical problem\u00a0of finding a knight&#8217;s tour, and probably making knight the most interesting piece on the chess board. The knight visits every square exactly once, if the knight ends on a square that is one knight&#8217;s move from the beginning square (so that it could tour the board again immediately, following the same path), the tour is closed; otherwise, it is open.<\/p>\n\n\n\n<p>The knight&#8217;s tour problem is an instance of the more general\u00a0Hamiltonian path problem\u00a0in\u00a0graph theory. The problem of finding a closed knight&#8217;s tour is similarly an instance of the\u00a0Hamiltonian cycle problem. Unlike the general Hamiltonian path problem, the knight&#8217;s tour problem can be solved in\u00a0linear time.<\/p>\n\n\n\n<h3 class=\"has-text-align-center wp-block-heading\"> Hamiltonian Path Problem <\/h3>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2021\/05\/Hamiltonian-removebg-preview.png?resize=337%2C237&#038;ssl=1\" alt=\"\" class=\"wp-image-2573\" width=\"337\" height=\"237\" srcset=\"https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2021\/05\/Hamiltonian-removebg-preview.png?w=595&amp;ssl=1 595w, https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2021\/05\/Hamiltonian-removebg-preview.png?resize=300%2C211&amp;ssl=1 300w\" sizes=\"(max-width: 337px) 100vw, 337px\" \/><\/figure><\/div>\n\n\n\n<p>In Graph Theory, a graph is usually defined to be a collection of nodes or vertices and the set of edges which define which nodes are connected with each other. So we use a well known notation of representing a graph G = (V,E) where\u00a0<em>V = { v<sub>1<\/sub>, v<sub>2<\/sub>, v<sub>3<\/sub>, &#8230; , v<sub>n<\/sub> }<\/em>\u00a0and E = {(i, j)|i \u2208 V and j \u2208 V and i and j is connected}.<\/p>\n\n\n\n<p>Hamiltonian Path is defined to be a single path that visits every node in the given graph, or a permutation of nodes in such a way that for every adjacent node in the permutation there is an edge defined in the graph. Notice that it does not make much sense in repeating the same paths. In order to avoid this repetition, we permute with <sub>|V|<\/sub>C<sub>2<\/sub> combinations of starting and ending vertices.<\/p>\n\n\n\n<p>Simple way of solving the Hamiltonian Path problem would be to permutate all possible paths and see if edges exist on all the adjacent nodes in the permutation. If the graph is a complete graph, then naturally all generated permutations would quality as a Hamiltonian path.<\/p>\n\n\n\n<p class=\"has-text-align-left\">For example. let us find a Hamiltonian path in graph G = (V,E) where V = {1,2,3,4} and E = {(1,2),(2,3),(3,4)}. Just by inspection, we can easily see that the Hamiltonian path exists in permutation 1234. The given algorithm will first generate the following permutations based on the combinations:<br>1342 1432 1243 1423 1234 1324 2143 2413 2134 2314 3124 3214<\/p>\n\n\n\n<p>The number that has to be generated is  (<sub>|V|<\/sub>C<sub>2<\/sub> ) (|V| &#8211; 2)!<\/p>\n\n\n\n<h3 class=\"has-text-align-center wp-block-heading\">Existence<\/h3>\n\n\n\n<div class=\"wp-block-image wp-duotone-000000-7f7f7f-1\"><figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"521\" height=\"521\" src=\"https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2021\/05\/26.png?resize=521%2C521&#038;ssl=1\" alt=\"\" class=\"wp-image-2583\" srcset=\"https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2021\/05\/26.png?w=521&amp;ssl=1 521w, https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2021\/05\/26.png?resize=300%2C300&amp;ssl=1 300w, https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2021\/05\/26.png?resize=150%2C150&amp;ssl=1 150w, https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2021\/05\/26.png?resize=75%2C75&amp;ssl=1 75w\" sizes=\"(max-width: 521px) 100vw, 521px\" \/><\/figure><\/div>\n\n\n\n<p>Schwenk\u00a0proved that for any\u00a0<em>m<\/em>\u00a0\u00d7\u00a0<em>n<\/em>\u00a0board with\u00a0<em>m<\/em>\u00a0\u2264\u00a0<em>n<\/em>, a closed knight&#8217;s tour is always possible\u00a0<em>unless<\/em>\u00a0one or more of these three conditions are met:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><em>m<\/em>&nbsp;and&nbsp;<em>n<\/em>&nbsp;are both odd<\/li><li><em>m<\/em>&nbsp;= 1, 2, or 4<\/li><li><em>m<\/em>&nbsp;= 3 and&nbsp;<em>n<\/em>&nbsp;= 4, 6, or 8.<\/li><\/ol>\n\n\n\n<p>Cull\u00a0and Conrad\u00a0proved that on any rectangular board whose smaller dimension is at least 5, there is a (possibly open) knight&#8217;s tour.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-regular\"><table><tbody><tr><th><em>n<\/em><\/th><th class=\"has-text-align-center\" data-align=\"center\">Number of directed tours (open and closed)<br>on an&nbsp;<em>n<\/em>&nbsp;\u00d7&nbsp;<em>n<\/em>&nbsp;board<br>(sequence&nbsp;<a href=\"https:\/\/oeis.org\/A165134\">A165134<\/a>&nbsp;in the&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/On-Line_Encyclopedia_of_Integer_Sequences\">OEIS<\/a>)<\/th><\/tr><tr><td>1<\/td><td class=\"has-text-align-center\" data-align=\"center\">1<\/td><\/tr><tr><td>2<\/td><td class=\"has-text-align-center\" data-align=\"center\">0<\/td><\/tr><tr><td>3<\/td><td class=\"has-text-align-center\" data-align=\"center\">0<\/td><\/tr><tr><td>4<\/td><td class=\"has-text-align-center\" data-align=\"center\">0<\/td><\/tr><tr><td>5<\/td><td class=\"has-text-align-center\" data-align=\"center\">1,728<\/td><\/tr><tr><td>6<\/td><td class=\"has-text-align-center\" data-align=\"center\">6,637,920<\/td><\/tr><tr><td>7<\/td><td class=\"has-text-align-center\" data-align=\"center\">165,575,218,320<\/td><\/tr><tr><td>8<\/td><td class=\"has-text-align-center\" data-align=\"center\">19,591,828,170,979,904<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"has-text-align-center wp-block-heading\">Neural network solutions<\/h3>\n\n\n\n<p>The neural network is designed such that each legal knight\u2019s move on the chessboard is represented by a neuron. Therefore, the network basically takes the shape of the&nbsp;<em>knight\u2019s graph<\/em>&nbsp;over an&nbsp;n\u00d7n&nbsp;chess board. (A knight\u2019s graph is simply the set of all knight moves on the board)<\/p>\n\n\n\n<p>Each neuron can be either \u201cactive\u201d or \u201cinactive\u201d (output of 1 or 0). If a neuron is active, it is considered part of the solution to the knight\u2019s tour. Once the network is started, each active neuron is configured so that it reaches a \u201cstable\u201d state if and only if it has exactly two neighboring neurons that are also active (otherwise, the state of the neuron changes). When the entire network is stable, a solution is obtained. The complete transition rules are as follows:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2021\/05\/Screenshot-659.png?resize=424%2C193&#038;ssl=1\" alt=\"\" class=\"wp-image-2580\" width=\"424\" height=\"193\" srcset=\"https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2021\/05\/Screenshot-659.png?resize=1024%2C468&amp;ssl=1 1024w, https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2021\/05\/Screenshot-659.png?resize=300%2C137&amp;ssl=1 300w, https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2021\/05\/Screenshot-659.png?resize=768%2C351&amp;ssl=1 768w, https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2021\/05\/Screenshot-659.png?resize=1536%2C701&amp;ssl=1 1536w, https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2021\/05\/Screenshot-659.png?resize=1140%2C521&amp;ssl=1 1140w, https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2021\/05\/Screenshot-659.png?w=1719&amp;ssl=1 1719w\" sizes=\"(max-width: 424px) 100vw, 424px\" \/><\/figure><\/div>\n\n\n\n<p>where\u00a0t\u00a0represents time (incrementing in discrete intervals),\u00a0U(N<sub>i,j<\/sub>)\u00a0is the state of the neuron connecting square\u00a0i\u00a0to square\u00a0j,\u00a0V(N<sub>i,j<\/sub>)\u00a0is the output of the neuron from\u00a0i\u00a0to\u00a0j, and\u00a0G(N<sub>i,j<\/sub>)\u00a0is the set of \u201cneighbors\u201d of the neuron (all neurons that share a vertex with\u00a0N<sub>i,j<\/sub>).<\/p>\n\n\n\n<h3 class=\"has-text-align-center wp-block-heading\">Code For Knight&#8217;s Tour<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\n\n\/\/ Java program for Knight Tour problem\nclass KnightTour {\nstatic int N = 8;\n\n\/* A utility function to check if i,j are\nvalid indexes for N*N chessboard *\/\nstatic boolean isSafe(int x, int y, int sol&#91;]&#91;])\n{\n    return (x >= 0 &amp;&amp; x &lt; N &amp;&amp; y >= 0 &amp;&amp; y &lt; N\n            &amp;&amp; sol&#91;x]&#91;y] == -1);\n}\n\n\/* A utility function to print solution\nmatrix sol&#91;N]&#91;N] *\/\nstatic void printSolution(int sol&#91;]&#91;])\n{\n    for (int x = 0; x &lt; N; x++) {\n        for (int y = 0; y &lt; N; y++)\n            System.out.print(sol&#91;x]&#91;y] + \" \");\n        System.out.println();\n    }\n}\n\n\/* This function solves the Knight Tour problem\nusing Backtracking. This function mainly\nuses solveKTUtil() to solve the problem. It\nreturns false if no complete tour is possible,\notherwise return true and prints the tour.\nPlease note that there may be more than one\nsolutions, this function prints one of the\nfeasible solutions. *\/\nstatic boolean solveKT()\n{\n    int sol&#91;]&#91;] = new int&#91;8]&#91;8];\n\n    \/* Initialization of solution matrix *\/\n    for (int x = 0; x &lt; N; x++)\n        for (int y = 0; y &lt; N; y++)\n            sol&#91;x]&#91;y] = -1;\n\n    \/* xMove&#91;] and yMove&#91;] define next move of Knight.\n    xMove&#91;] is for next value of x coordinate\n    yMove&#91;] is for next value of y coordinate *\/\n    int xMove&#91;] = { 2, 1, -1, -2, -2, -1, 1, 2 };\n    int yMove&#91;] = { 1, 2, 2, 1, -1, -2, -2, -1 };\n\n    \/\/ Since the Knight is initially at the first block\n    sol&#91;0]&#91;0] = 0;\n\n    \/* Start from 0,0 and explore all tours using\n    solveKTUtil() *\/\n    if (!solveKTUtil(0, 0, 1, sol, xMove, yMove)) {\n        System.out.println(\"Solution does not exist\");\n        return false;\n    }\n    else\n        printSolution(sol);\n\n    return true;\n}\n\n\/* A recursive utility function to solve Knight\nTour problem *\/\nstatic boolean solveKTUtil(int x, int y, int movei,\n                        int sol&#91;]&#91;], int xMove&#91;],\n                        int yMove&#91;])\n{\n    int k, next_x, next_y;\n    if (movei == N * N)\n        return true;\n\n    \/* Try all next moves from the current coordinate\n        x, y *\/\n    for (k = 0; k &lt; 8; k++) {\n        next_x = x + xMove&#91;k];\n        next_y = y + yMove&#91;k];\n        if (isSafe(next_x, next_y, sol)) {\n            sol&#91;next_x]&#91;next_y] = movei;\n            if (solveKTUtil(next_x, next_y, movei + 1,\n                            sol, xMove, yMove))\n                return true;\n            else\n                sol&#91;next_x]&#91;next_y]\n                    = -1; \/\/ backtracking\n        }\n    }\n\n    return false;\n}\n\n\/* Driver Code *\/\npublic static void main(String args&#91;])\n{\n    \/\/ Function Call\n    solveKT();\n}\n}<\/code><\/pre>\n\n\n\n<p><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The\u00a0knight&#8217;s tour problem\u00a0is the\u00a0mathematical problem\u00a0of finding a knight&#8217;s tour, and probably making knight the most interesting piece on the chess board. The knight visits every square exactly once, if the knight ends on a square that is one knight&#8217;s move from the beginning square (so that it could tour the board again immediately, following the same path), the tour is closed; otherwise, it is open. The knight&#8217;s tour problem is an instance of the more general\u00a0Hamiltonian path problem\u00a0in\u00a0graph theory. The problem of finding a closed knight&#8217;s tour is similarly an instance of the\u00a0Hamiltonian cycle problem. Unlike the general Hamiltonian path problem, the knight&#8217;s tour problem can be solved in\u00a0linear time. Hamiltonian Path Problem In Graph Theory, a graph is usually defined to be a collection of nodes or vertices and the set of edges which define which nodes are connected with each other. So we use a well known notation of representing a graph G = (V,E) where\u00a0V = { v1, v2, v3, &#8230; , vn }\u00a0and E = {(i, j)|i \u2208 V and j \u2208 V and i and j is connected}. Hamiltonian Path is defined to be a single path that visits every node in the given graph, or a permutation of nodes in such a way that for every adjacent node in the permutation there is an edge defined in the graph. Notice that it does not make much sense in repeating the same paths. In order to avoid this repetition, we permute with |V|C2 combinations of starting and ending vertices. Simple way of solving the Hamiltonian Path problem would be to permutate all possible paths and see if edges exist on all the adjacent nodes in the permutation. If the graph is a complete graph, then naturally all generated permutations would quality as a Hamiltonian path. For example. let us find a Hamiltonian path in graph G = (V,E) where V = {1,2,3,4} and E = {(1,2),(2,3),(3,4)}. Just by inspection, we can easily see that the Hamiltonian path exists in permutation 1234. The given algorithm will first generate the following permutations based on the combinations:1342 1432 1243 1423 1234 1324 2143 2413 2134 2314 3124 3214 The number that has to be generated is (|V|C2 ) (|V| &#8211; 2)! Existence Schwenk\u00a0proved that for any\u00a0m\u00a0\u00d7\u00a0n\u00a0board with\u00a0m\u00a0\u2264\u00a0n, a closed knight&#8217;s tour is always possible\u00a0unless\u00a0one or more of these three conditions are met: m&nbsp;and&nbsp;n&nbsp;are both odd m&nbsp;= 1, 2, or 4 m&nbsp;= 3 and&nbsp;n&nbsp;= 4, 6, or 8. Cull\u00a0and Conrad\u00a0proved that on any rectangular board whose smaller dimension is at least 5, there is a (possibly open) knight&#8217;s tour. n Number of directed tours (open and closed)on an&nbsp;n&nbsp;\u00d7&nbsp;n&nbsp;board(sequence&nbsp;A165134&nbsp;in the&nbsp;OEIS) 1 1 2 0 3 0 4 0 5 1,728 6 6,637,920 7 165,575,218,320 8 19,591,828,170,979,904 Neural network solutions The neural network is designed such that each legal knight\u2019s move on the chessboard is represented by a neuron. Therefore, the network basically takes the shape of the&nbsp;knight\u2019s graph&nbsp;over an&nbsp;n\u00d7n&nbsp;chess board. (A knight\u2019s graph is simply the set of all knight moves on the board) Each neuron can be either \u201cactive\u201d or \u201cinactive\u201d (output of 1 or 0). If a neuron is active, it is considered part of the solution to the knight\u2019s tour. Once the network is started, each active neuron is configured so that it reaches a \u201cstable\u201d state if and only if it has exactly two neighboring neurons that are also active (otherwise, the state of the neuron changes). When the entire network is stable, a solution is obtained. The complete transition rules are as follows: where\u00a0t\u00a0represents time (incrementing in discrete intervals),\u00a0U(Ni,j)\u00a0is the state of the neuron connecting square\u00a0i\u00a0to square\u00a0j,\u00a0V(Ni,j)\u00a0is the output of the neuron from\u00a0i\u00a0to\u00a0j, and\u00a0G(Ni,j)\u00a0is the set of \u201cneighbors\u201d of the neuron (all neurons that share a vertex with\u00a0Ni,j). Code For Knight&#8217;s Tour<\/p>\n","protected":false},"author":1,"featured_media":1371,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1369","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sneak-peeks"],"featured_image_src":"https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2020\/09\/ILAIsmB.gif?fit=335%2C334&ssl=1","blog_images":{"medium":"https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2020\/09\/ILAIsmB.gif?fit=300%2C300&ssl=1","large":"https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2020\/09\/ILAIsmB.gif?fit=335%2C334&ssl=1"},"ams_acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>The Knight&#039;s Tour - SOUL OF MATHEMATICS<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/soulofmathematics.com\/index.php\/the-knights-tour\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The Knight&#039;s Tour - SOUL OF MATHEMATICS\" \/>\n<meta property=\"og:description\" content=\"The\u00a0knight&#8217;s tour problem\u00a0is the\u00a0mathematical problem\u00a0of finding a knight&#8217;s tour, and probably making knight the most interesting piece on the chess board. The knight visits every square exactly once, if the knight ends on a square that is one knight&#8217;s move from the beginning square (so that it could tour the board again immediately, following the same path), the tour is closed; otherwise, it is open. The knight&#8217;s tour problem is an instance of the more general\u00a0Hamiltonian path problem\u00a0in\u00a0graph theory. The problem of finding a closed knight&#8217;s tour is similarly an instance of the\u00a0Hamiltonian cycle problem. Unlike the general Hamiltonian path problem, the knight&#8217;s tour problem can be solved in\u00a0linear time. Hamiltonian Path Problem In Graph Theory, a graph is usually defined to be a collection of nodes or vertices and the set of edges which define which nodes are connected with each other. So we use a well known notation of representing a graph G = (V,E) where\u00a0V = { v1, v2, v3, &#8230; , vn }\u00a0and E = {(i, j)|i \u2208 V and j \u2208 V and i and j is connected}. Hamiltonian Path is defined to be a single path that visits every node in the given graph, or a permutation of nodes in such a way that for every adjacent node in the permutation there is an edge defined in the graph. Notice that it does not make much sense in repeating the same paths. In order to avoid this repetition, we permute with |V|C2 combinations of starting and ending vertices. Simple way of solving the Hamiltonian Path problem would be to permutate all possible paths and see if edges exist on all the adjacent nodes in the permutation. If the graph is a complete graph, then naturally all generated permutations would quality as a Hamiltonian path. For example. let us find a Hamiltonian path in graph G = (V,E) where V = {1,2,3,4} and E = {(1,2),(2,3),(3,4)}. Just by inspection, we can easily see that the Hamiltonian path exists in permutation 1234. The given algorithm will first generate the following permutations based on the combinations:1342 1432 1243 1423 1234 1324 2143 2413 2134 2314 3124 3214 The number that has to be generated is (|V|C2 ) (|V| &#8211; 2)! Existence Schwenk\u00a0proved that for any\u00a0m\u00a0\u00d7\u00a0n\u00a0board with\u00a0m\u00a0\u2264\u00a0n, a closed knight&#8217;s tour is always possible\u00a0unless\u00a0one or more of these three conditions are met: m&nbsp;and&nbsp;n&nbsp;are both odd m&nbsp;= 1, 2, or 4 m&nbsp;= 3 and&nbsp;n&nbsp;= 4, 6, or 8. Cull\u00a0and Conrad\u00a0proved that on any rectangular board whose smaller dimension is at least 5, there is a (possibly open) knight&#8217;s tour. n Number of directed tours (open and closed)on an&nbsp;n&nbsp;\u00d7&nbsp;n&nbsp;board(sequence&nbsp;A165134&nbsp;in the&nbsp;OEIS) 1 1 2 0 3 0 4 0 5 1,728 6 6,637,920 7 165,575,218,320 8 19,591,828,170,979,904 Neural network solutions The neural network is designed such that each legal knight\u2019s move on the chessboard is represented by a neuron. Therefore, the network basically takes the shape of the&nbsp;knight\u2019s graph&nbsp;over an&nbsp;n\u00d7n&nbsp;chess board. (A knight\u2019s graph is simply the set of all knight moves on the board) Each neuron can be either \u201cactive\u201d or \u201cinactive\u201d (output of 1 or 0). If a neuron is active, it is considered part of the solution to the knight\u2019s tour. Once the network is started, each active neuron is configured so that it reaches a \u201cstable\u201d state if and only if it has exactly two neighboring neurons that are also active (otherwise, the state of the neuron changes). When the entire network is stable, a solution is obtained. The complete transition rules are as follows: where\u00a0t\u00a0represents time (incrementing in discrete intervals),\u00a0U(Ni,j)\u00a0is the state of the neuron connecting square\u00a0i\u00a0to square\u00a0j,\u00a0V(Ni,j)\u00a0is the output of the neuron from\u00a0i\u00a0to\u00a0j, and\u00a0G(Ni,j)\u00a0is the set of \u201cneighbors\u201d of the neuron (all neurons that share a vertex with\u00a0Ni,j). Code For Knight&#8217;s Tour\" \/>\n<meta property=\"og:url\" content=\"https:\/\/soulofmathematics.com\/index.php\/the-knights-tour\/\" \/>\n<meta property=\"og:site_name\" content=\"SOUL OF MATHEMATICS\" \/>\n<meta property=\"article:published_time\" content=\"2021-05-27T06:14:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-27T06:14:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2020\/09\/ILAIsmB.gif?fit=335%2C334&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"335\" \/>\n\t<meta property=\"og:image:height\" content=\"334\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/gif\" \/>\n<meta name=\"author\" content=\"Rajarshi Dey\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rajarshi Dey\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/soulofmathematics.com\/index.php\/the-knights-tour\/\",\"url\":\"https:\/\/soulofmathematics.com\/index.php\/the-knights-tour\/\",\"name\":\"The Knight's Tour - SOUL OF MATHEMATICS\",\"isPartOf\":{\"@id\":\"https:\/\/soulofmathematics.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/soulofmathematics.com\/index.php\/the-knights-tour\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/soulofmathematics.com\/index.php\/the-knights-tour\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2020\/09\/ILAIsmB.gif?fit=335%2C334&ssl=1\",\"datePublished\":\"2021-05-27T06:14:18+00:00\",\"dateModified\":\"2021-05-27T06:14:19+00:00\",\"author\":{\"@id\":\"https:\/\/soulofmathematics.com\/#\/schema\/person\/c61ee309ed66bc94ba7a27f6129b945c\"},\"breadcrumb\":{\"@id\":\"https:\/\/soulofmathematics.com\/index.php\/the-knights-tour\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/soulofmathematics.com\/index.php\/the-knights-tour\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/soulofmathematics.com\/index.php\/the-knights-tour\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2020\/09\/ILAIsmB.gif?fit=335%2C334&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2020\/09\/ILAIsmB.gif?fit=335%2C334&ssl=1\",\"width\":335,\"height\":334,\"caption\":\"Knight's tour\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/soulofmathematics.com\/index.php\/the-knights-tour\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/soulofmathematics.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The Knight&#8217;s Tour\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/soulofmathematics.com\/#website\",\"url\":\"https:\/\/soulofmathematics.com\/\",\"name\":\"SOUL OF MATHEMATICS\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/soulofmathematics.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/soulofmathematics.com\/#\/schema\/person\/c61ee309ed66bc94ba7a27f6129b945c\",\"name\":\"Rajarshi Dey\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/soulofmathematics.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/14acfcec71e13078f5b322bb6adfd1f6579c091317d0e0077c2311511263a8b0?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/14acfcec71e13078f5b322bb6adfd1f6579c091317d0e0077c2311511263a8b0?s=96&d=mm&r=g\",\"caption\":\"Rajarshi Dey\"},\"sameAs\":[\"http:\/\/soulofmathematics.com\"],\"url\":\"https:\/\/soulofmathematics.com\/index.php\/author\/rajarshidey1729gmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"The Knight's Tour - SOUL OF MATHEMATICS","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/soulofmathematics.com\/index.php\/the-knights-tour\/","og_locale":"en_US","og_type":"article","og_title":"The Knight's Tour - SOUL OF MATHEMATICS","og_description":"The\u00a0knight&#8217;s tour problem\u00a0is the\u00a0mathematical problem\u00a0of finding a knight&#8217;s tour, and probably making knight the most interesting piece on the chess board. The knight visits every square exactly once, if the knight ends on a square that is one knight&#8217;s move from the beginning square (so that it could tour the board again immediately, following the same path), the tour is closed; otherwise, it is open. The knight&#8217;s tour problem is an instance of the more general\u00a0Hamiltonian path problem\u00a0in\u00a0graph theory. The problem of finding a closed knight&#8217;s tour is similarly an instance of the\u00a0Hamiltonian cycle problem. Unlike the general Hamiltonian path problem, the knight&#8217;s tour problem can be solved in\u00a0linear time. Hamiltonian Path Problem In Graph Theory, a graph is usually defined to be a collection of nodes or vertices and the set of edges which define which nodes are connected with each other. So we use a well known notation of representing a graph G = (V,E) where\u00a0V = { v1, v2, v3, &#8230; , vn }\u00a0and E = {(i, j)|i \u2208 V and j \u2208 V and i and j is connected}. Hamiltonian Path is defined to be a single path that visits every node in the given graph, or a permutation of nodes in such a way that for every adjacent node in the permutation there is an edge defined in the graph. Notice that it does not make much sense in repeating the same paths. In order to avoid this repetition, we permute with |V|C2 combinations of starting and ending vertices. Simple way of solving the Hamiltonian Path problem would be to permutate all possible paths and see if edges exist on all the adjacent nodes in the permutation. If the graph is a complete graph, then naturally all generated permutations would quality as a Hamiltonian path. For example. let us find a Hamiltonian path in graph G = (V,E) where V = {1,2,3,4} and E = {(1,2),(2,3),(3,4)}. Just by inspection, we can easily see that the Hamiltonian path exists in permutation 1234. The given algorithm will first generate the following permutations based on the combinations:1342 1432 1243 1423 1234 1324 2143 2413 2134 2314 3124 3214 The number that has to be generated is (|V|C2 ) (|V| &#8211; 2)! Existence Schwenk\u00a0proved that for any\u00a0m\u00a0\u00d7\u00a0n\u00a0board with\u00a0m\u00a0\u2264\u00a0n, a closed knight&#8217;s tour is always possible\u00a0unless\u00a0one or more of these three conditions are met: m&nbsp;and&nbsp;n&nbsp;are both odd m&nbsp;= 1, 2, or 4 m&nbsp;= 3 and&nbsp;n&nbsp;= 4, 6, or 8. Cull\u00a0and Conrad\u00a0proved that on any rectangular board whose smaller dimension is at least 5, there is a (possibly open) knight&#8217;s tour. n Number of directed tours (open and closed)on an&nbsp;n&nbsp;\u00d7&nbsp;n&nbsp;board(sequence&nbsp;A165134&nbsp;in the&nbsp;OEIS) 1 1 2 0 3 0 4 0 5 1,728 6 6,637,920 7 165,575,218,320 8 19,591,828,170,979,904 Neural network solutions The neural network is designed such that each legal knight\u2019s move on the chessboard is represented by a neuron. Therefore, the network basically takes the shape of the&nbsp;knight\u2019s graph&nbsp;over an&nbsp;n\u00d7n&nbsp;chess board. (A knight\u2019s graph is simply the set of all knight moves on the board) Each neuron can be either \u201cactive\u201d or \u201cinactive\u201d (output of 1 or 0). If a neuron is active, it is considered part of the solution to the knight\u2019s tour. Once the network is started, each active neuron is configured so that it reaches a \u201cstable\u201d state if and only if it has exactly two neighboring neurons that are also active (otherwise, the state of the neuron changes). When the entire network is stable, a solution is obtained. The complete transition rules are as follows: where\u00a0t\u00a0represents time (incrementing in discrete intervals),\u00a0U(Ni,j)\u00a0is the state of the neuron connecting square\u00a0i\u00a0to square\u00a0j,\u00a0V(Ni,j)\u00a0is the output of the neuron from\u00a0i\u00a0to\u00a0j, and\u00a0G(Ni,j)\u00a0is the set of \u201cneighbors\u201d of the neuron (all neurons that share a vertex with\u00a0Ni,j). Code For Knight&#8217;s Tour","og_url":"https:\/\/soulofmathematics.com\/index.php\/the-knights-tour\/","og_site_name":"SOUL OF MATHEMATICS","article_published_time":"2021-05-27T06:14:18+00:00","article_modified_time":"2021-05-27T06:14:19+00:00","og_image":[{"width":335,"height":334,"url":"https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2020\/09\/ILAIsmB.gif?fit=335%2C334&ssl=1","type":"image\/gif"}],"author":"Rajarshi Dey","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rajarshi Dey","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/soulofmathematics.com\/index.php\/the-knights-tour\/","url":"https:\/\/soulofmathematics.com\/index.php\/the-knights-tour\/","name":"The Knight's Tour - SOUL OF MATHEMATICS","isPartOf":{"@id":"https:\/\/soulofmathematics.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/soulofmathematics.com\/index.php\/the-knights-tour\/#primaryimage"},"image":{"@id":"https:\/\/soulofmathematics.com\/index.php\/the-knights-tour\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2020\/09\/ILAIsmB.gif?fit=335%2C334&ssl=1","datePublished":"2021-05-27T06:14:18+00:00","dateModified":"2021-05-27T06:14:19+00:00","author":{"@id":"https:\/\/soulofmathematics.com\/#\/schema\/person\/c61ee309ed66bc94ba7a27f6129b945c"},"breadcrumb":{"@id":"https:\/\/soulofmathematics.com\/index.php\/the-knights-tour\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/soulofmathematics.com\/index.php\/the-knights-tour\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/soulofmathematics.com\/index.php\/the-knights-tour\/#primaryimage","url":"https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2020\/09\/ILAIsmB.gif?fit=335%2C334&ssl=1","contentUrl":"https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2020\/09\/ILAIsmB.gif?fit=335%2C334&ssl=1","width":335,"height":334,"caption":"Knight's tour"},{"@type":"BreadcrumbList","@id":"https:\/\/soulofmathematics.com\/index.php\/the-knights-tour\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/soulofmathematics.com\/"},{"@type":"ListItem","position":2,"name":"The Knight&#8217;s Tour"}]},{"@type":"WebSite","@id":"https:\/\/soulofmathematics.com\/#website","url":"https:\/\/soulofmathematics.com\/","name":"SOUL OF MATHEMATICS","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/soulofmathematics.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/soulofmathematics.com\/#\/schema\/person\/c61ee309ed66bc94ba7a27f6129b945c","name":"Rajarshi Dey","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/soulofmathematics.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/14acfcec71e13078f5b322bb6adfd1f6579c091317d0e0077c2311511263a8b0?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/14acfcec71e13078f5b322bb6adfd1f6579c091317d0e0077c2311511263a8b0?s=96&d=mm&r=g","caption":"Rajarshi Dey"},"sameAs":["http:\/\/soulofmathematics.com"],"url":"https:\/\/soulofmathematics.com\/index.php\/author\/rajarshidey1729gmail-com\/"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/soulofmathematics.com\/wp-content\/uploads\/2020\/09\/ILAIsmB.gif?fit=335%2C334&ssl=1","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcfs4y-m5","_links":{"self":[{"href":"https:\/\/soulofmathematics.com\/index.php\/wp-json\/wp\/v2\/posts\/1369","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/soulofmathematics.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/soulofmathematics.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/soulofmathematics.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/soulofmathematics.com\/index.php\/wp-json\/wp\/v2\/comments?post=1369"}],"version-history":[{"count":13,"href":"https:\/\/soulofmathematics.com\/index.php\/wp-json\/wp\/v2\/posts\/1369\/revisions"}],"predecessor-version":[{"id":2586,"href":"https:\/\/soulofmathematics.com\/index.php\/wp-json\/wp\/v2\/posts\/1369\/revisions\/2586"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/soulofmathematics.com\/index.php\/wp-json\/wp\/v2\/media\/1371"}],"wp:attachment":[{"href":"https:\/\/soulofmathematics.com\/index.php\/wp-json\/wp\/v2\/media?parent=1369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/soulofmathematics.com\/index.php\/wp-json\/wp\/v2\/categories?post=1369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/soulofmathematics.com\/index.php\/wp-json\/wp\/v2\/tags?post=1369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}