public void Run(string[] args) { IReader reader; if (args.Length > 0) { reader = new FileReader(args[0]); } else { reader = new ConsoleReader(); } var size = int.Parse(reader.ReadLine()); var input = reader.ReadLine(); BitArray bitArray = new BitArray(size); int filledLength = input.Length; for (int i = 0; i < input.Length; i++) { bitArray[i] = input[i] == '1' ? true : false; } while (filledLength < size) { filledLength = Generate(bitArray, filledLength); } // Print(bitArray); // WriteLine($" [{filledLength}]"); var checksum = bitArray; var checksumLength = bitArray.Length; checksumLength = CalculateChecksum(checksum, checksumLength); while (checksumLength % 2 == 0) { checksumLength = CalculateChecksum(checksum, checksumLength); } Print(checksum, checksumLength); }
public void Run(string[] args) { IReader reader; if (args.Length > 0) { reader = new FileReader(args[0]); } else { reader = new ConsoleReader(); } Dictionary <string, int> propertiesToLookFor = new Dictionary <string, int>() { { "children", 3 }, { "cats", 7 }, { "samoyeds", 2 }, { "pomeranians", 3 }, { "akitas", 0 }, { "vizslas", 0 }, { "goldfish", 5 }, { "trees", 3 }, { "cars", 2 }, { "perfumes", 1 } }; int auntCounter = 1; while (!reader.EndOfStream) { var input = reader.ReadLine(); if (string.IsNullOrEmpty(input)) { break; } var propertiesStartIndex = input.IndexOf(':') + 2; input = input.Substring(propertiesStartIndex, input.Length - propertiesStartIndex); var properties = input.Split(','); bool isThisAunt = true; //WriteLine($"[Aunt #{auntCounter}] "); foreach (var p in properties) { var pp = p.Split(':'); var propertyName = pp[0].Trim(); var propertyValue = int.Parse(pp[1]); //WriteLine($" {propertyName}: {propertyValue}"); if (propertyName == "cats" || propertyName == "trees") { if (propertiesToLookFor[propertyName] >= propertyValue) { isThisAunt = false; break; } } else if (propertyName == "pomeranians" || propertyName == "goldfish") { if (propertiesToLookFor[propertyName] <= propertyValue) { isThisAunt = false; break; } } else if (propertiesToLookFor[propertyName] != propertyValue) { isThisAunt = false; break; } } if (isThisAunt) { WriteLine($"Gift is from aunt {auntCounter}"); } auntCounter++; } }