public override int?Accept(ISolver visitor)
        {
            List <int> results = new List <int>();
            bool       solved  = true;

            foreach (var problem in problems)
            {
                if (problem.Solved == false)
                {
                    problem.Accept(visitor);
                    if (problem.Solved == false)
                    {
                        solved = false;
                    }
                }
                else
                {
                    results.Add(problem.Result.Value);
                }
            }
            if (solved)
            {
                int value = resultsCombiner.CombineResults(results);
                TryMarkAsSolved(value);
                return(value);
            }
            return(null);
        }
Example #2
0
        public override void Accept(ISolver solver)
        {
            if (Solved)
            {
                return;
            }
            bool       anyUnsolved = false;
            List <int> results     = new List <int>();

            foreach (Problem p in problems)
            {
                p.Accept(solver);
                if (p.Solved)
                {
                    results.Add(p.Result.Value);
                }
                else
                {
                    anyUnsolved = true;
                }
            }

            if (!anyUnsolved)
            {
                TryMarkAsSolved(resultsCombiner.CombineResults(results));
            }
        }
Example #3
0
        public override void Accept(ISolver visitor)
        {
            foreach (var problem in problems)
            {
                if (problem.Solved)
                {
                    continue;
                }
                problem.Accept(visitor);
            }

            if (problems.Any(problem => problem.Solved == false))
            {
                return;
            }
            Console.WriteLine();
            TryMarkAsSolved(resultsCombiner.CombineResults(problems.Where(p => p.Result != null).Select(p => p.Result.Value).ToList()));
        }
Example #4
0
        public override void CanItSolveMe(ISolver solver)
        {
            foreach (Problem p in problems)
            {
                if (p.Solved)
                {
                    continue;
                }

                p.CanItSolveMe(solver);
                if (p.Solved)
                {
                    sumSolved++;
                    results.Add(p.Result.GetValueOrDefault());
                }
            }

            if (sumSolved == problems.Count())
            {
                TryMarkAsSolved(resultsCombiner.CombineResults(results));
            }
        }
Example #5
0
        public override void Accept(ISolver solver)
        {
            IEnumerable <int> results = new List <int>();

            foreach (Problem problem in problems)
            {
                if (!problem.Solved)
                {
                    problem.Accept(solver);
                    if (problem.Result != null)
                    {
                        results.Append((int)problem.Result);
                    }
                    if (problem.Solved)
                    {
                        Console.WriteLine($"Result of {problem.Name}: {problem.Result}");
                    }
                    else
                    {
                        Console.WriteLine($"{problem.Name} was not solved");
                    }
                    Console.WriteLine(string.Empty);
                }
            }
            bool solvedAll = true;

            foreach (Problem problem in problems)
            {
                if (problem.Solved == false)
                {
                    solvedAll = false;
                }
            }
            if (solvedAll)
            {
                TryMarkAsSolved(resultsCombiner.CombineResults(results));
            }
        }