Пример #1
0
        public override void Solve()
        {
            var maxMemory = inputData.Select(w => w.MemoryIndex).Max();
            var memory    = new ulong[maxMemory + 1];

            foreach (var memeoryData in inputData)
            {
                var numberAfterMask = NumberToCharConverterDay14.ApplyMaskToNumber(memeoryData.Number, memeoryData.Mask);
                memory[memeoryData.MemoryIndex] = NumberToCharConverterDay14.ConvertCharArrayToNumber(numberAfterMask);
            }
            solution = memory.Aggregate((a, c) => a + c);
        }
Пример #2
0
        public override void Solve()
        {
            var memory = new Dictionary <ulong, ulong>();

            foreach (var memoryData in inputData)
            {
                var unstableAddress     = NumberToCharConverterDay14.ApplyMaskToNumber((ulong)memoryData.MemoryIndex, memoryData.Mask);
                var memoryToApplyNumber = NumberToCharConverterDay14.CreateNumbersFromInstableAddress(unstableAddress);

                foreach (var mem in memoryToApplyNumber)
                {
                    if (memory.ContainsKey(mem))
                    {
                        memory[mem] = memoryData.Number;
                    }
                    else
                    {
                        memory.Add(mem, memoryData.Number);
                    }
                }
            }
            solution = memory.Values.Aggregate((a, c) => a + c);
        }