private void FindOptimalCookie(params Ingredient[] ingredients) { Cookie maxCookie = new Cookie(); for (int i = 0; i <= 100; i++) { for (int j = 0; j <= 100 - i; j++) { for (int k = 0; k <= 100 - i - j; k++) { var cookie = new Cookie(); cookie.AddIngredient(ingredients[0], i); cookie.AddIngredient(ingredients[1], j); cookie.AddIngredient(ingredients[2], k); int l = 100 - i - j - k; if (l > 0) { cookie.AddIngredient(ingredients[3], l); } //WriteLine(i + ", " + j + ", " + l); long score = cookie.CalculateScore(); if (score > maxCookie.CalculateScore()) { maxCookie = cookie; } } } } WriteLine(maxCookie.GetRecipe()); WriteLine("Score: " + maxCookie.CalculateScore().ToString("### ### ### ###")); }
private Cookie FindOptimalCookie(params Ingredient[] ingredients) { Cookie maxCookie = new Cookie(); for (int i = 0; i <= 100; i++) { for (int j = 0; j <= 100 - i; j++) { for (int k = 0; k <= 100 - i - j; k++) { var cookie = new Cookie(); cookie.AddIngredient(ingredients[0], i); cookie.AddIngredient(ingredients[1], j); cookie.AddIngredient(ingredients[2], k); int l = 100 - i - j - k; if (l > 0) { cookie.AddIngredient(ingredients[3], l); } //WriteLine(i + ", " + j + ", " + l); long score = cookie.CalculateScore(); if (cookie.Calories == 500 && score > maxCookie.CalculateScore()) { maxCookie = cookie; } } } } return(maxCookie); }
private void TestCookie(long b, long c) { var cookie = new Cookie(); cookie.AddIngredient(_butterscotch, b); cookie.AddIngredient(_cinnamon, c); WriteLine(cookie.GetRecipe()); WriteLine("Score: " + cookie.CalculateScore().ToString("### ### ### ###")); }