protected override String DoSolve(String[] input) { List <IIngredient> ingredients = new List <IIngredient>(); //get the input foreach (String line in input) { String ingredientName = StringOps.SubStringPre(line, ":"); int capacity = Convert.ToInt32(StringOps.SubStringPostAndPre(line, "capacity", ", durability").Trim()); int durability = Convert.ToInt32(StringOps.SubStringPostAndPre(line, "durability", ", flavor").Trim()); int flavor = Convert.ToInt32(StringOps.SubStringPostAndPre(line, "flavor", ", texture").Trim()); int texture = Convert.ToInt32(StringOps.SubStringPostAndPre(line, "texture", ", calories").Trim()); int calories = Convert.ToInt32(StringOps.SubStringPost(line, "calories").Trim()); ingredients.Add(Factory.CreateIngredient(ingredientName, capacity, durability, flavor, texture, calories)); } List <int[]> ingredientPermutations = Combinations.CombinationsThatSumTo(new int[ingredients.Count()], 100); int maxScore = 0; foreach (int[] ingredientPermutation in ingredientPermutations) { int cookieScore = Factory.CreateCookie(ingredients, ingredientPermutation).CalculateScore(); if (cookieScore >= maxScore) { maxScore = cookieScore; } } return($"The Best Cookie has a score of {maxScore}!"); }
private void ParseInput(String input) { Name = StringOps.SubStringPre(input, ":").Trim(); Range1Min = Convert.ToInt32(StringOps.SubStringPostAndPre(input, ":", "-").Trim()); Range1Max = Convert.ToInt32(StringOps.SubStringPost(StringOps.SubStringPre(input, " or ").Trim(), "-").Trim()); Range2Min = Convert.ToInt32(StringOps.SubStringPre(StringOps.SubStringPost(input, " or ").Trim(), "-").Trim()); Range2Max = Convert.ToInt32(StringOps.SubStringPost(StringOps.SubStringPost(input, " or ").Trim(), "-").Trim()); }