public void Add_OutOfOrder() { var range = new MultiRange(); range.Add(23); range.Add(42); range.Add(10); Assert.Equal(3, range.Count); Assert.Equal(new[] { R(10), R(23), R(42) }, range.GetRanges()); Assert.True(range.Contains(10)); Assert.True(range.Contains(23)); Assert.True(range.Contains(42)); Assert.False(range.Contains(22)); Assert.False(range.Contains(24)); }
public void Default() { var range = new MultiRange(); Assert.Equal(0, range.Count); Assert.Equal(new Range[0], range.GetRanges()); Assert.False(range.Contains(42)); }
public void Add() { var range = new MultiRange(); range.Add(42); Assert.Equal(1, range.Count); Assert.Equal(new[] { R(42) }, range.GetRanges()); Assert.True(range.Contains(42)); }
public void Copy_Empty() { var range = new MultiRange(); var copy = new MultiRange(range); Assert.Equal(0, copy.Count); Assert.Equal(new Range[0], copy.GetRanges()); Assert.False(copy.Contains(42)); }
public void Add_End() { var range = new MultiRange { 11 }; range.Add(12); Assert.Equal(2, range.Count); Assert.Equal(new[] { R(11, 13) }, range.GetRanges()); Assert.True(range.Contains(12)); }
public void Add_Begin() { var range = new MultiRange { 11 }; range.Add(10); Assert.Equal(2, range.Count); Assert.Equal(new[] { R(10, 12) }, range.GetRanges()); Assert.True(range.Contains(10)); }
public static ulong Solve(string[] input) { (List <MultiRange> rules, Ticket yourTicket, List <Ticket> nearbyTickets) = Part1.Solution.ParseInput(input); List <Ticket> filteredTickets = nearbyTickets.Where(t => !t.IsError(rules)).ToList(); filteredTickets.Add(yourTicket); bool[,] whichRulesWorkInWhichIndex = new bool[rules.Count, rules.Count]; for (int i = 0; i < rules.Count; ++i) { for (int j = 0; j < rules.Count; ++j) { whichRulesWorkInWhichIndex[i, j] = filteredTickets.All(t => rules[i].IsInRange(t.Numbers[j])); } } MultiRange[] orderedRules = new MultiRange[rules.Count]; while (orderedRules.Any(rule => rule == null)) { for (int i = 0; i < rules.Count; ++i) { if (!orderedRules.Contains(rules[i])) { for (int j = 0; j < rules.Count; ++j) { if (orderedRules[j] == null && whichRulesWorkInWhichIndex[i, j] && !Enumerable.Range(0, rules.Count).Where(k => k != j).Any(k => whichRulesWorkInWhichIndex[i, k] && orderedRules[k] == null)) { orderedRules[j] = rules[i]; } } } } } ulong product = 1; for (int i = 0; i < rules.Count; ++i) { if (orderedRules[i].Field.StartsWith("departure")) { product *= (ulong)yourTicket.Numbers[i]; } } return(product); }
private bool IsSelected(int rowIndex) { return selectedIndices.Contains(rowIndex); }