예제 #1
0
 public async Task<IEnumerable<NumberChain>> SolveMany(NumberChainProblem problem)
 {
     var result = problem.Result;
     var numbers = problem.Numbers;
     if (numbers.Length < 2)
         throw new NotSupportedException("A minimum of two numbers required to operate on");
     var chains = GenerateChains(numbers);
     var solutions = chains.Where(x => x.Result == result && _validator.IsValid(x)).ToList();
     if (solutions == null || !solutions.Any())
         throw new NotSupportedException("No result possible");
     return await Task.FromResult(solutions);
 }
예제 #2
0
 public async Task<NumberChain> Solve(NumberChainProblem problem)
 {
     var result = problem.Result;
     var numbers = problem.Numbers;
     if (numbers.Length < 2)
         throw new NotSupportedException("A minimum of two numbers required to operate on");
     var chains = GenerateChains(numbers);
     var solution = chains.FirstOrDefault(x => x.Result == result && _validator.IsValid(x));
     if (solution == null)
         throw new NotSupportedException("No result possible");
     return await Task.FromResult(solution);
 }