예제 #1
0
        public void TestPermute(IEnumerable <int> input, int expectedCount)
        {
//            IEnumerable<int> input = new List<int>() {1,2,3};
            List <int> numbersList            = input.ToList();
            IEnumerable <IList <int> > output = Helper.Permute(numbersList, numbersList.Count);

            Assert.True(output.Count() == expectedCount);
        }
        private IEnumerable <NumbersSolution> GetSolutions(int target, IEnumerable <int> numbers)
        {
            List <INode>               nodes             = new List <INode>();
            CollectionsHelper          collectionsHelper = new CollectionsHelper();
            List <int>                 numbersList       = numbers.ToList();
            IEnumerable <IList <int> > permutations      = collectionsHelper.Permute(numbersList, numbersList.Count);

            foreach (IEnumerable <int> permutation in permutations)
            {
                nodes.AddRange(GetNodes(permutation.ToList()));
            }

            IEnumerable <NumbersSolution> solutions = nodes.Select(n => new NumbersSolution(target, n)).OrderBy(solution => solution.Closeness);

            return(solutions);
        }