Пример #1
0
        static void Main(string[] args)
        {
            var  addressSpace = new AddressSpace();
            Mask mask         = null;

            var input = File.ReadAllLines("./input.txt");

            foreach (var line in input)
            {
                var value = line.Split(" ").Last();
                if (line.StartsWith("mask"))
                {
                    mask = new Mask(value);
                }
                else
                {
                    var index    = Convert.ToInt32(Regex.Match(line, "\\[(\\d+)\\]").Groups[1].Value);
                    var intValue = new Base36Integer(Convert.ToInt64(value));

                    // Part 1
                    //addressSpace.CommitValueToMemory(index, mask.MaskValue(intValue));

                    // Part 2
                    var indexes = mask.MaskValueFloating(new Base36Integer(index));
                    addressSpace.CommitValueToMemory(indexes, intValue);
                }
            }

            Part1And2(addressSpace);

            Console.ReadLine();
        }
Пример #2
0
 public void CommitValueToMemory(int index, Base36Integer value)
 {
     if (_committedIndexes.ContainsKey(index))
     {
         _addressSpace[_committedIndexes[index]] = value.DecimalValue;
     }
     else
     {
         _addressSpace.Add(value.DecimalValue);
         _committedIndexes.Add(index, _addressSpace.Count() - 1);
     }
 }
Пример #3
0
        public Base36Integer MaskValue(Base36Integer value)
        {
            var maskedValue = value.BinaryValue.ToCharArray();

            for (var i = 0; i < maskedValue.Length; i++)
            {
                if (_bitmask[i] != 'X')
                {
                    maskedValue[i] = _bitmask[i];
                }
            }

            return(new Base36Integer(String.Join("", maskedValue)));
        }
Пример #4
0
 public void CommitValueToMemory(List <Base36Integer> indexes, Base36Integer value)
 {
     foreach (var index in indexes)
     {
         if (_committedIndexes.ContainsKey(index.DecimalValue))
         {
             _addressSpace[_committedIndexes[index.DecimalValue]] = value.DecimalValue;
         }
         else
         {
             _addressSpace.Add(value.DecimalValue);
             _committedIndexes.Add(index.DecimalValue, _addressSpace.Count() - 1);
         }
     }
 }
Пример #5
0
        public List <Base36Integer> MaskValueFloating(Base36Integer value)
        {
            var result = new List <Base36Integer>();

            var maskedValue = value.BinaryValue.ToCharArray();

            for (var i = 0; i < maskedValue.Length; i++)
            {
                if (_bitmask[i] != '0')
                {
                    maskedValue[i] = _bitmask[i];
                }
            }

            return(RecursiveMethod(String.Join("", maskedValue)));
        }