public override long SolvePart2() { var locationOffsets = new Location2D[] { (1, 1), (3, 1), (5, 1), (7, 1), (1, 2) }; var slopes = new ValueCounterDictionary <Location2D>(locationOffsets, 0); for (int i = 0; i < grid.Height; i++) { foreach (var o in locationOffsets) { var location = o * i; if (location.Y >= grid.Height) { continue; } if (grid[location] == TreeGridCellType.Tree) { slopes.Add(o); } } } long product = 1; foreach (var s in slopes) { product *= s.Value; } return(product); }
/// <summary>Gets a <seealso cref="ValueCounterDictionary{TKey}"/> that contains the number of occurrences of each role in this list. This ignores the <seealso cref="RoleAlignment"/> slots.</summary> /// <returns>The <seealso cref="ValueCounterDictionary{TKey}"/> containing the number of occurrences of each role in this list.</returns> public ValueCounterDictionary <Type> GetRoleOccurrences() { var result = new ValueCounterDictionary <Type>(); FixedRoleSlots.ForEach(role => result.Add(role.GetType())); return(result); }
public void AddTest() { var d = new ValueCounterDictionary <char>(testDictionary); d.Add('a', 4); Assert.AreEqual(5, d['a']); }
public void EnumerableInitializationTest() { var d = new ValueCounterDictionary <char>("CHARACTER COUNTER TEST"); Assert.AreEqual(2, d[' ']); Assert.AreEqual(4, d['T']); Assert.AreEqual(11, d.Count); }
public void AdjustCountersTest() { var d = new ValueCounterDictionary <char>(testDictionary); d.Add('a', 4); d.AdjustCounters('a', 'b', 3); Assert.AreEqual(2, d['a']); Assert.AreEqual(4, d['b']); }
private int WorkSteps(int workerCount, out string stepString) { int totalTime = 0; var stepList = new List <char>(nodeDictionary.Count); var workerPool = new WorkerPool(workerCount); var available = new SortedSet <StepNetworkNode>(); var remainingRequirements = new ValueCounterDictionary <StepNetworkNode>(); foreach (var node in nodeDictionary.Values) { remainingRequirements[node] = node.PreviousNodes.Count; MarkAvailable(node); } while (remainingRequirements.Any() || available.Any()) { foreach (var assigned in workerPool.AssignWorkingNodes(available)) { available.Remove(assigned); } totalTime += workerPool.WorkForMinRemainingTime(out var finishedSteps); foreach (var finishedStep in finishedSteps) { stepList.Add(finishedStep.Value); foreach (var next in finishedStep.NextNodes) { remainingRequirements.Subtract(next); MarkAvailable(next); } } } stepString = new(stepList.ToArray()); return(totalTime); void MarkAvailable(StepNetworkNode node) { if (remainingRequirements[node] > 0) { return; } available.Add(node); remainingRequirements.Remove(node); } }
private bool ValidateRoleList(RoleCollection availableRoles, out ValueCounterDictionary <Type> remainingSlots) { remainingSlots = new(); // This exists to prevent impossible role lists like more than 6 Coven roles in a game (since all the Coven roles are unique) var remainingAlignmentSlots = new ValueCounterDictionary <Faction>(); foreach (var t in availableRoles) { var instance = RoleInstancePool.Instance[t]; remainingSlots.Add(t, instance.MaximumOccurrences); remainingAlignmentSlots.Add(instance.Faction, instance.MaximumOccurrences); } foreach (var slot in roleSlots) { if (slot is RoleAlignment alignment) { } else { var role = slot as Role; // This is probably the greatest usage of inline variable declarations via is alignment = role.FullAlignment; var type = role.GetType(); remainingSlots.Subtract(type); if (remainingSlots[type] < 0) { return(false); } } var faction = alignment.Faction; if (faction == Faction.Any) { continue; } remainingAlignmentSlots.Subtract(faction); if (remainingAlignmentSlots[faction] < 0) { return(false); } } return(true); }
private int SolveProblem(SumCalculationPredicate sumCalculationPredicate) { int sum = 0; var dictionary = new ValueCounterDictionary <char>(); foreach (var group in groups) { var people = group.GetLines(); foreach (var person in people) { foreach (var question in person) { dictionary.Add(question); } } sum += dictionary.Count(kvp => sumCalculationPredicate(kvp, people.Length)); dictionary.Clear(); } return(sum); }
protected CubeGrid3D(int size, T defaultValue, ValueCounterDictionary <T> valueCounters) : base(size, size, size, defaultValue, valueCounters) { }
public BoxID(string id) { ID = id; letters = new(ID); tupleLetters = letters.Values.ToHashSet(); }
private bool ValidateRoleList(GamePackTypes packTypes, out ValueCounterDictionary <Type> remainingSlots) { return(ValidateRoleList(new RoleCollection(RoleCollection.AllAvailableRolesCollection.GetAllStartableRoleTypesIntersection(packTypes)), out remainingSlots)); }
public PrintableGrid(int width, int height) { printableCharacters = GetPrintableCharacters(); ValueCounters = new ValueCounterDictionary <T>(Grid = new T[Width = width, Height = height]); }
protected Grid2D(int width, int height, T defaultValue, ValueCounterDictionary <T> valueCounters) : this(width, height, defaultValue, false) { ValueCounters = new(valueCounters); }
private int Part2Returner(ValueCounterDictionary <TileType> tileCounts, int score) => score;
private int Part1Returner(ValueCounterDictionary <TileType> tileCounts, int score) => tileCounts[TileType.Block];