public void TestGetInputData()
        {
            List <int> numbers = ExpepenseReport.GetInputData(PuzzleFilePath);

            Assert.IsNotNull(numbers);
            Assert.Contains(1918, numbers);
        }
        public void TestFindSumNotInSum()
        {
            int desiredSum = 20;
            var input      = new List <int>()
            {
                1, 2, 3, 4
            };

            List <int> numbers = ExpepenseReport.FindSum(input, desiredSum);

            Assert.AreEqual(numbers.Count(), 0);
        }
        public void TestFindTrippleSumAnwser()
        {
            int desiredSum = 2020;

            // Find the answer to day 1 challange 2
            var        input   = ExpepenseReport.GetInputData(PuzzleFilePath);
            List <int> numbers = ExpepenseReport.FindTrippleSum(input, desiredSum);

            Assert.AreEqual(numbers.Sum(), desiredSum);
            int answer = numbers.Aggregate((x, y) => x * y);

            Console.Write(answer);
        }
        public void TestFindSum()
        {
            int desiredSum = 5;
            var input      = new List <int>()
            {
                1, 2, 3, 4
            };

            List <int> numbers = ExpepenseReport.FindSum(input, desiredSum);

            Assert.AreEqual(numbers.Count(), 2);
            Assert.AreEqual(numbers.Sum(), desiredSum);
            Assert.Contains(numbers[0], input);
            Assert.Contains(numbers[1], input);
        }
Ejemplo n.º 5
0
        public static List <int> FindTrippleSum(List <int> numbers, int desiredSum)
        {
            var sum = new List <int>();

            foreach (int num1 in numbers)
            {
                sum = ExpepenseReport.FindSum(numbers, desiredSum - num1);
                if (num1 + sum.Sum() == desiredSum)
                {
                    sum.Add(num1);
                    return(sum);
                }
            }

            return(new List <int>());
        }