Exemplo n.º 1
0
        private static Tree CreateTree(Tree tree, int currentNumber, int maxNumber)
        {
            int currentElement = currentNumber;

            if (currentElement > maxNumber)
            {
                return tree;
            }

            Tree currentChild = new Tree(currentElement * 2);
            if (currentElement * 2 <= maxNumber)
            {
                var currentTree = CreateTree(currentChild, currentElement * 2, maxNumber);
                tree.Root.AddChildren(currentTree);
            }

            currentChild = new Tree(currentElement + 2);
            if (currentElement + 2 <= maxNumber )
            {
                var currentTree = CreateTree(currentChild, currentElement + 2, maxNumber);
                tree.Root.AddChildren(currentTree);
            }

            currentChild = new Tree(currentElement + 1);
            if (currentElement + 1 <= maxNumber)
            {
                var currentTree = CreateTree(currentChild, currentElement + 1, maxNumber);
                tree.Root.AddChildren(currentTree);   
            }

            return tree;
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {            
            Tree root = new Tree(N);
            var treeOfSteps = CreateTree(root, N, M);

            DFS(treeOfSteps.Root);

            var minPaths = GetMinLengthPaths();

            PrintPaths(minPaths);
        }