public void Solver2(string example)
        {
            var content = example.ReadFromFile();
            var solver  = new Solver2();
            var input   = Input.Parse(content);
            var output  = solver.Solve(input);

            Console.WriteLine($"Total Score: {output.GetScore(input):N0}");
            example.WriteToFile(output.GetOutputFormat());
            Assert.Pass();
        }
Beispiel #2
0
        public ActionResult <SolveResult> Solve(int target, List <int> chosenNums)
        {
            if (chosenNums.Count == 0 || chosenNums.Count > 8)
            {
                return(BadRequest("Must provide between 1 and 8 numbers"));
            }

            var solver = new Solver2(target, chosenNums);

            return(solver.Solve());
        }
Beispiel #3
0
        public void CanFindExactSolutions(int target, List <int> availableNums)
        {
            // Assemble
            var solver = new Solver2(target, availableNums);

            // Act
            var result = solver.Solve();

            // Assert
            Assert.Equal(0, result.ClosestDiff);
            Assert.NotEmpty(result.Solutions);
        }
Beispiel #4
0
        public void WorksWhenSolutionIsAlreadyInAvailableNumbers()
        {
            // Assemble
            var availableNums = new List <int> {
                1, 2, 3, 4, 5, 100
            };
            var solver = new Solver2(100, availableNums);

            // Act
            var result = solver.Solve();

            // Assert
            Assert.Equal(0, result.ClosestDiff);
            Assert.NotEmpty(result.Solutions);
        }
Beispiel #5
0
        public void CanFindClosestSolutions()
        {
            // Assemble
            var availableNums = new List <int> {
                2, 3, 4, 5, 8, 10
            };
            var solver = new Solver2(933, availableNums);

            // Act
            var result = solver.Solve();

            // Assert
            Assert.Equal(1, result.ClosestDiff);
            Assert.Equal(2, result.Solutions.Count);
        }
Beispiel #6
0
        public void DoesntMissSimplerSolutions()
        {
            // Assemble
            var availableNums = new List <int> {
                1, 2, 3, 4, 5, 6
            };
            var solver = new Solver2(8, availableNums);

            // Act
            var result = solver.Solve();

            // Assert
            Assert.Equal(0, result.ClosestDiff);
            Assert.Contains("4 × 2 = 8", result.Solutions);
            Assert.Contains("5 + 3 = 8", result.Solutions);
        }