Example #1
0
        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);
        }
Example #2
0
        /// <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']);
        }
Example #6
0
            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);
                }
            }
Example #7
0
        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);
        }
Example #8
0
        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);
        }
Example #9
0
 protected CubeGrid3D(int size, T defaultValue, ValueCounterDictionary <T> valueCounters)
     : base(size, size, size, defaultValue, valueCounters)
 {
 }
Example #10
0
 public BoxID(string id)
 {
     ID           = id;
     letters      = new(ID);
     tupleLetters = letters.Values.ToHashSet();
 }
Example #11
0
 private bool ValidateRoleList(GamePackTypes packTypes, out ValueCounterDictionary <Type> remainingSlots)
 {
     return(ValidateRoleList(new RoleCollection(RoleCollection.AllAvailableRolesCollection.GetAllStartableRoleTypesIntersection(packTypes)), out remainingSlots));
 }
Example #12
0
 public PrintableGrid(int width, int height)
 {
     printableCharacters = GetPrintableCharacters();
     ValueCounters       = new ValueCounterDictionary <T>(Grid = new T[Width = width, Height = height]);
 }
Example #13
0
 protected Grid2D(int width, int height, T defaultValue, ValueCounterDictionary <T> valueCounters)
     : this(width, height, defaultValue, false)
 {
     ValueCounters = new(valueCounters);
 }
Example #14
0
 private int Part2Returner(ValueCounterDictionary <TileType> tileCounts, int score) => score;
Example #15
0
 private int Part1Returner(ValueCounterDictionary <TileType> tileCounts, int score) => tileCounts[TileType.Block];