public void CombinationsWork() { var combinations = new FastCombinations <int>(new int[] { 1, 2, 3, 4, 5 }, 2) .Select(x => x.ToArray()).ToList(); var seen = new HashSet <int[]>(); Assert.AreEqual(10, combinations.Count); foreach (var item in combinations) { Assert.AreEqual(2, item.Length); Assert.IsTrue(seen.Add(item.ToArray()), $"{item} was already seen"); } }
public override string Solve_1() { var window = new HashSet <long>(input.Take(25)); for (int i = 25; i < input.Length; i++) { var isSum = new FastCombinations <long>(window.ToList(), 2).Where(x => x.Sum() == input[i]).Any(); if (!isSum) { xmasNumber = input[i]; return(xmasNumber.ToString()); } _ = window.Remove(input[i - 25]); _ = window.Add(input[i]); } return("?"); }
public void CombinationsDoNotAllocate() { var combinations = new FastCombinations <int>(new int[] { 1, 2, 3, 4, 5 }, 2).ToList(); Assert.IsTrue(ReferenceEquals(combinations[0], combinations[1])); }