Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class Program
- {
- private const int LineCount = 16;
- private const int NodeCount = 9;
- private static int[][] nodeToNode = new int[NodeCount][];
- private static int[][] nodeVisiting = new int[NodeCount][];
- private static bool[] visited = new bool[LineCount];
- public static void Main()
- {
- InitLines();
- FindSolution();
- }
- private static void FindSolution()
- {
- for (int i = 0; i < NodeCount; i++)
- {
- TryFindSolution(i, 0);
- }
- Console.WriteLine("No solution.");
- }
- private static void TryFindSolution(int at, int n)
- {
- if (n == LineCount)
- {
- Console.WriteLine("Success!");
- }
- var arr = nodeToNode[at];
- for (int i = 0; i < arr.Length; i++)
- {
- int n2 = arr[i];
- int visiting = nodeVisiting[at][i];
- if (!visited[visiting])
- {
- visited[visiting] = true;
- TryFindSolution(n2, n + 1);
- visited[visiting] = false;
- }
- }
- }
- private static void InitLines()
- {
- nodeVisiting[0] = new[] { 0, 2 };
- nodeToNode[0] = new[] { 1, 3 };
- nodeVisiting[1] = new[] { 0, 1, 3, 4, 5 };
- nodeToNode[1] = new[] { 0, 2, 3, 4, 5 };
- nodeVisiting[2] = new[] { 1, 6 };
- nodeToNode[2] = new[] { 1, 5 };
- nodeVisiting[3] = new[] { 2, 3, 7, 9, 10 };
- nodeToNode[3] = new[] { 0, 1, 4, 6, 7 };
- nodeVisiting[4] = new[] { 4, 7, 8, 11 };
- nodeToNode[4] = new[] { 1, 3, 5, 7 };
- nodeVisiting[5] = new[] { 5, 6, 8, 12, 13 };
- nodeToNode[5] = new[] { 1, 2, 4, 7, 8 };
- nodeVisiting[6] = new[] { 9, 14 };
- nodeToNode[6] = new[] { 3, 7 };
- nodeVisiting[7] = new[] { 10, 11, 12, 14, 15 };
- nodeToNode[7] = new[] { 3, 4, 5, 6, 8 };
- nodeVisiting[8] = new[] { 13, 15 };
- nodeToNode[8] = new[] { 5, 7 };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment