public static List <long> GetInputData(string filePath) { var inputData = new List <long>(); string[] inputDataRaw = InputDataHandler.ReadFileAsArray(filePath); foreach (var s in inputDataRaw) { inputData.Add(long.Parse(s)); } return(inputData); }
public static List <int> GetInputData(string filePath) { var numbers = new List <int>(); // Specify folder since it can be run from elsewhere, e.g. unittest string[] stringNumbers = InputDataHandler.ReadFileAsArray(filePath); foreach (string s in stringNumbers) { numbers.Add(Convert.ToInt32(s)); } return(numbers); }
public static List <PasswordPolicy> GetInputData(string filePath) { var policies = new List <PasswordPolicy>(); // Specify folder since it can be run from elsewhere, e.g. unittest string[] policyPasswordList = InputDataHandler.ReadFileAsArray(filePath); foreach (string unparsed in policyPasswordList) { string[] policyAndPassword = unparsed.Split(new string[] { ": " }, StringSplitOptions.None); policies.Add(new PasswordPolicy(policyAndPassword[0], policyAndPassword[1])); } return(policies); }
public static bool ValidatePassportRegex(Dictionary <string, string> parsedPassport) { bool passportIsValid = true; // Obtain the passport rules // TODO: This sghould only be new once. Maybe make into an instance variable? string[] rawPassportTemplateRegex = InputDataHandler.ReadFileAsArray(FilePathPassportRulesRegex, string.Empty); Dictionary <string, string> passportTemplateRegex = PassportValidator.ParseRawPassport(rawPassportTemplateRegex[0]); // Compare value for a kay with the allowed Regex expression // Loop over all template keys in case of an incomplete passport being supplied as argument foreach (KeyValuePair <string, string> currentFieldTemplate in passportTemplateRegex) { // Don't care about cid, skip to checking next field // TODO: Refactor to create all passport keys when reading the passport if (currentFieldTemplate.Key == "cid") { continue; } string value = string.Empty; if (parsedPassport.TryGetValue(currentFieldTemplate.Key, out value)) { if (!Regex.IsMatch(value, currentFieldTemplate.Value)) { passportIsValid = false; // Console.WriteLine("Passport invalidated by: " + currentFieldTemplate.Key + ":" + value); } } else { // If a passport doesn't include the template key it is atomatically invalid // TODO: Handle cid // TODO: Refactor the simple invalidator to use this method? passportIsValid = false; } } return(passportIsValid); }
public char[,] GetInputDataMap(string filePath) { // Specify folder since it can be run from elsewhere, e.g. unittest string[] stringMap = InputDataHandler.ReadFileAsArray(filePath); int rows = stringMap.Length; int columns = stringMap[0].Length; char[,] map = new char[rows, columns]; this.ColIdxMax = columns; this.RowIdxMax = rows; for (int row = 0; row < rows; row++) { for (int col = 0; col < columns; col++) { map[row, col] = stringMap[row][col]; } } return(map); }
public static string[] GetInputData(string filePath) { string[] groupAnswers = InputDataHandler.ReadFileAsArray(filePath); return(groupAnswers); }
// private static Dictionary<string, string> passportRules = new Dictionary<string, string> { // { "byr", "" }, {"iyr" }, {"eyr" }, {"hgt" }, {"hcl" }, {"ecl" }, {"pid" }, {"cid" } }; public static string[] GetInputData(string filePath) { string[] rawPassports = InputDataHandler.ReadFileAsArray(filePath, "\r\n\r\n"); return(rawPassports); }