private static ulong DoPart1(string[] input) { ulong result = 0; Mask_Part1 mask = new Mask_Part1(); Dictionary <ulong, ulong> values = new Dictionary <ulong, ulong>(); foreach (String instruction in input) { Match m = MaskRegex.Match(instruction); if (m.Success) { String newMask = m.Groups[1].Value; mask.Update(newMask); } else { m = MemRegex.Match(instruction); Debug.Assert(m.Success); ulong address = ulong.Parse(m.Groups[1].Value); ulong rawValue = ulong.Parse(m.Groups[2].Value); ulong actualValue = mask.Apply(rawValue); values[address] = actualValue; } } foreach (KeyValuePair <ulong, ulong> kvp in values) { result += kvp.Value; } return(result); }