private static IEnumerable <int> CreateNewCoinList(int coin, ChangeOption existingChangeOption) { List <int> newCoinList = new List <int>(); newCoinList.AddRange(existingChangeOption.ChangeCoins); newCoinList.Add(coin); return(newCoinList); }
public void AddChangeOption(int targetValue, IEnumerable <int> changeCoins) { var newChangeOption = new ChangeOption(targetValue); foreach (var changeCoin in changeCoins) { newChangeOption.AddChangeCoin(changeCoin); } changeOptionDictionary.Add(targetValue, newChangeOption); }
private static bool NewChangeOptionIsShorter(ChangeOption existingChangeOption, ChangeOption changeOption) { return(existingChangeOption.ChangeCoins.Count > changeOption.ChangeCoins.Count + 1); }
private static void UpdateChangeOption(ChangeOptionList possibleChangeOptions, int targetValue, int coin, ChangeOption existingChangeOption) { var newCoinList = CreateNewCoinList(coin, existingChangeOption); if (!possibleChangeOptions.ChangeOptionExistsForTargetValue(targetValue)) { possibleChangeOptions.AddChangeOption(targetValue, newCoinList); } else { possibleChangeOptions.GetChangeOption(targetValue).SetChangeCoins(newCoinList); } }
private static bool ExistingChangeOptionShouldBeUpdated(ChangeOptionList existingChangeOptions, int subtarget, ChangeOption newChangeOption) { return(newChangeOption != null && (!existingChangeOptions.ChangeOptionExistsForTargetValue(subtarget) || NewChangeOptionIsShorter(existingChangeOptions.GetChangeOption(subtarget), newChangeOption))); }