示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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();
        }
示例#4
0
        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);
        }