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
- A, B, L, M, P, Q, R, S
- }
- class Node
- {
- public Node(NODES n)
- {
- name = n;
- }
- public NODES name;
- public List<NODES> ins;
- public List<NODES> outs;
- }
- 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.A].outs = new List<NODES>() {
- NODES.S
- };
- locations[NODES.A].ins = new List<NODES>() {
- NODES.R
- };
- // ===============
- locations[NODES.B].outs = new List<NODES>() {
- NODES.L, NODES.R
- };
- locations[NODES.B].ins = new List<NODES>() {
- NODES.L, NODES.R
- };
- // ===============
- locations[NODES.L].outs = new List<NODES>() {
- NODES.B, NODES.M, NODES.R, NODES.P
- };
- locations[NODES.L].ins = new List<NODES>() {
- NODES.B, NODES.R, NODES.Q, NODES.M
- };
- // ===============
- locations[NODES.M].outs = new List<NODES>() {
- NODES.L
- };
- locations[NODES.M].ins = new List<NODES>() {
- NODES.L
- };
- // ===============
- locations[NODES.P].outs = new List<NODES>() {
- NODES.Q
- };
- locations[NODES.P].ins = new List<NODES>() {
- NODES.L
- };
- // ===============
- locations[NODES.Q].outs = new List<NODES>() {
- NODES.L
- };
- locations[NODES.Q].ins = new List<NODES>() {
- NODES.P
- };
- // ===============
- locations[NODES.R].outs = new List<NODES>() {
- NODES.A, NODES.B, NODES.L
- };
- locations[NODES.R].ins = new List<NODES>() {
- NODES.S, NODES.B, NODES.L
- };
- // ===============
- locations[NODES.S].outs = new List<NODES>() {
- NODES.R
- };
- locations[NODES.S].ins = new List<NODES>() {
- NODES.A
- };
- }
- 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.A);
- outIndex.Push(0);
- do
- {
- if(UsedAllPaths(route))
- {
- int currentOutIndex = outIndex.Pop();
- outIndex.Push(currentOutIndex + 1);
- routeCount++;
- if (outIndex.Last() == locations[route.Last()].outs.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.Last()].outs[outIndex.Last()]);
- } while (route.Count > 0);
- Console.WriteLine("==================\n" + routeCount);
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement