예제 #1
0
 private static List<Ingredient> ParseIngredients(string[] lines)
 {
     var regex = new Regex(@"^(\w+): .+ (\-?\d+), .+ (\-?\d+), .+ (\-?\d+), .+ (\-?\d+), .+ (\-?\d+)");
     var ingredients = new List<Ingredient>();
     foreach (var line in lines)
     {
         var match = regex.Match(line);
         var groups = match.Groups;
         var name = groups[1].Value;
         var capacity = int.Parse(groups[2].Value);
         var durability = int.Parse(groups[3].Value);
         var flavor = int.Parse(groups[4].Value);
         var texture = int.Parse(groups[5].Value);
         var calories = int.Parse(groups[6].Value);
         var ingredient = new Ingredient(name, capacity, durability, flavor, texture, calories);
         ingredients.Add(ingredient);
     }
     return ingredients;
 }
예제 #2
0
 public void RemoveIngredient(Ingredient ingredient)
 {
     _composition.Remove(ingredient);
 }
예제 #3
0
 public void AddIngredientDose(Ingredient ingredient, int teaspoonsCount)
 {
     _composition.Add(ingredient, teaspoonsCount);
 }
예제 #4
0
파일: Program.cs 프로젝트: Zeydel/AoC15
        static void Main(string[] args)
        {
            string path = @"..\..\input.txt";

            string[] inputArray = System.IO.File.ReadAllLines(path);

            Dictionary <string, Ingredient> ingredients = new Dictionary <string, Ingredient>();

            for (int i = 0; i < inputArray.Length; i++)
            {
                string   normalized  = Regex.Replace(inputArray[i], "[^a-zA-Z0-9- ]", "");
                string[] splitString = normalized.Split(' ');

                string name       = splitString[0];
                int    capacity   = int.Parse(splitString[2]);
                int    durability = int.Parse(splitString[4]);
                int    flavor     = int.Parse(splitString[6]);
                int    texture    = int.Parse(splitString[8]);
                int    calories   = int.Parse(splitString[10]);

                Ingredient newIngredient = new Ingredient
                {
                    Name       = name,
                    Capacity   = capacity,
                    Durability = durability,
                    Flavor     = flavor,
                    Texture    = texture,
                    Calories   = calories
                };

                ingredients.Add(name, newIngredient);
            }

            long bestValue = 0;
            long bestValueWith500Calories = 0;

            //Counter for sprinkles
            for (int i = 1; i <= 97; i++)
            {
                //Counter for peanutButter
                for (int j = 1; j + i <= 98; j++)
                {
                    //Counter for frosting
                    for (int k = 1; k + i + j <= 99; k++)
                    {
                        int l = 100 - k - j - i;

                        long value = CalculateCookieValue(i, j, k, l, ingredients);
                        if (value > bestValue)
                        {
                            bestValue = value;
                            //Console.WriteLine(bestValue);
                        }

                        if (CalculateCalories(i, j, k, l, ingredients) == 500)
                        {
                            if (value > bestValueWith500Calories)
                            {
                                bestValueWith500Calories = value;
                            }
                        }
                    }
                }
            }

            Console.WriteLine("Best cookie: " + bestValue);
            Console.WriteLine("Best cookie with 500 calories: " + bestValueWith500Calories);
            Console.ReadKey();
        }