private static void Part1() { Console.WriteLine("Part 1"); List <string> input = IO.InputRows; Sue giver = new Sue(true); Sue unknown; int i = 0; do { unknown = new Sue(false); input[i] = input[i].Substring(input[i].IndexOf(":") + 1).Replace(" ", String.Empty); string[] variables = input[i].Split(','); foreach (string variable in variables) { unknown.SetItemCount(variable.Split(':')[0], variable.Split(':')[1]); } i++; } while (!giver.Matches(unknown)); IO.Output(i); }
public bool Matches2(Sue other) { foreach (object key in items.Keys) { if (other.GetCountValue(key) != -1) { string keyString = (string)key; if (keyString == "cats" || keyString == "trees") { if (GetCountValue(key) >= other.GetCountValue(key)) { return(false); } } else if (keyString == "pomeranians" || keyString == "goldfish") { if (GetCountValue(key) <= other.GetCountValue(key)) { return(false); } } else if (GetCount(key) != other.GetCount(key)) { return(false); } } } return(true); }
static void Main(string[] args) { Part1(); //Part 2 List <string> input = IO.InputRows; Sue giver = new Sue(true); Sue unknown; int i = 0; do { unknown = new Sue(false); input[i] = input[i].Substring(input[i].IndexOf(":") + 1).Replace(" ", String.Empty); string[] variables = input[i].Split(','); foreach (string variable in variables) { unknown.SetItemCount(variable.Split(':')[0], variable.Split(':')[1]); } i++; } while (!giver.Matches2(unknown)); IO.Output(i, true); Console.ReadKey(); }
public bool Matches(Sue other) { foreach (object key in items.Keys) { if (GetCount(key) != other.GetCount(key) && other.GetCount(key) != "unknown") { return(false); } } return(true); }