Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MathsBombe_Q7
- {
- enum NODES
- { // locations
- AS, B, L, M, PQ, R
- }
- class Node
- {
- public Node(NODES n)
- {
- name = n;
- }
- public NODES name;
- public List<NODES> links;
- }
- class Path
- {
- public Path(NODES i, NODES o)
- {
- inNode = i;
- outNode = o;
- }
- public NODES inNode, outNode;
- }
- class Program
- {
- public const uint TOTAL_PATHS = 14;
- public static Dictionary<NODES, Node> locations = new Dictionary<NODES, Node>();
- private static void Init()
- {
- foreach (NODES n in Enum.GetValues(typeof(NODES)))
- {
- locations.Add(n, new Node(n));
- }
- locations[NODES.AS].links = new List<NODES>() {
- NODES.R
- };
- locations[NODES.B].links = new List<NODES>() {
- NODES.L, NODES.R
- };
- locations[NODES.L].links = new List<NODES>() {
- NODES.B, NODES.R, NODES.PQ, NODES.M
- };
- locations[NODES.M].links = new List<NODES>() {
- NODES.L
- };
- // ===============
- locations[NODES.PQ].links = new List<NODES>() {
- NODES.L
- };
- // ===============
- locations[NODES.R].links = new List<NODES>() {
- NODES.AS, NODES.B, NODES.L
- };
- }
- private static bool UsedAllPaths(Stack<NODES> routeStack)
- {
- List<NODES> route = routeStack.ToList();
- List<Path> usedPaths = new List<Path>();
- for (int r = 0; r < route.Count - 1; r++)
- {
- if (!usedPaths.Contains(new Path(route[r], route[r + 1])))
- {
- usedPaths.Add(new Path(route[r], route[r + 1]));
- }
- }
- return usedPaths.Count == TOTAL_PATHS;
- }
- static void Main(string[] args)
- {
- Init();
- uint routeCount = 0;
- Stack<NODES> route = new Stack<NODES>();
- Stack<int> outIndex = new Stack<int>();
- route.Push(NODES.AS);
- outIndex.Push(0);
- do
- {
- if(UsedAllPaths(route))
- {
- int currentOutIndex = outIndex.Pop();
- outIndex.Push(currentOutIndex + 1);
- routeCount++;
- if (outIndex.First() == locations[route.First()].links.Count)
- {
- outIndex.Pop();
- route.Pop();
- for(int n = route.Count - 1; n >= 0; n--)
- {
- Console.Write(route.ToList()[n]);
- }
- Console.WriteLine();
- }
- }
- route.Push(locations[route.First()].links[outIndex.First()]);
- } while (route.Count > 0);
- Console.WriteLine("==================\n" + routeCount);
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement