Пример #1
0
        private static string GetDay1Part2(IEnumerable <int> expenseReport)
        {
            var result = string.Empty;

            foreach (var combination in EnumerableCombinations.GetCombinations(expenseReport.ToArray(), 3))
            {
                if (combination[0] + combination[1] + combination[2] != 2020)
                {
                    continue;
                }
                result = $"Part 2 Product of combinations = {combination[0] * combination[1] * combination[2]}";
                break;
            }

            return(result);
        }
Пример #2
0
 private static bool IsSumPresent(long[] arrayToCheck, long currentIndexValue, int numberOfElementsToSum) =>
 EnumerableCombinations.GetCombinations(arrayToCheck, numberOfElementsToSum).Any(combination => combination.Sum() == currentIndexValue);