private static async Task <IEnumerable <Component> > _getLongestBridgeAsync(IEnumerable <Component> components, Bridge bridge)
        {
            var longestBridge = new List <Component>();
            var nextLists     = new List <Task <IEnumerable <Component> > >();

            foreach (var component in components)
            {
                var newBridge = new Bridge(bridge);
                if (newBridge.TryAddComponent(component))
                {
                    nextLists.Add(Task.Run(() => _getLongestBridge(components.Where(c => !c.Equals(component)).ToList(), newBridge)));
                }
            }
            foreach (var nextList in nextLists)
            {
                if ((await nextList).Count() > longestBridge.Count)
                {
                    longestBridge = (await nextList).ToList();
                }
                else if ((await nextList).Count() == longestBridge.Count &&
                         (await nextList).Sum(c => c.Strength) > longestBridge.Sum(c => c.Strength))
                {
                    longestBridge = (await nextList).ToList();
                }
            }
            longestBridge.Add(bridge.RemoveComponent());
            return(longestBridge);
        }
        private async Task <Bridge> GetLongestBridge(IEnumerable <Component> components)
        {
            IEnumerable <Component> longestBridge = new List <Component>();
            var nextLists = new List <Task <IEnumerable <Component> > >();

            foreach (var component in components)
            {
                var bridge = new Bridge();
                if (bridge.TryAddComponent(component))
                {
                    nextLists.Add(Task.Run(async() => await _getLongestBridgeAsync(components.Where(c => !c.Equals(component)), bridge)));
                }
            }

            foreach (var nextList in nextLists)
            {
                if ((await nextList).Count() > longestBridge.Count())
                {
                    longestBridge = await nextList;
                }
                else if ((await nextList).Count() == longestBridge.Count() &&
                         (await nextList).Sum(c => c.Strength) > longestBridge.Sum(c => c.Strength))
                {
                    longestBridge = await nextList;
                }
            }

            return(new Bridge(longestBridge.Reverse()));
        }
        private static IEnumerable <Component> _getStrongestBridge(IEnumerable <Component> components, Bridge bridge)
        {
            var strongestBridge = new List <Component>();

            foreach (var component in components)
            {
                if (bridge.TryAddComponent(component))
                {
                    var nextList = _getStrongestBridge(components.Where(c => !c.Equals(component)), bridge).ToList();
                    if (strongestBridge.Sum(c => c.Strength) < nextList.Sum(c => c.Strength))
                    {
                        strongestBridge = nextList;
                    }
                }
            }
            strongestBridge.Add(bridge.RemoveComponent());
            return(strongestBridge);
        }