Exemple #1
0
        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);
        }
Exemple #3
0
 private static bool NewChangeOptionIsShorter(ChangeOption existingChangeOption, ChangeOption changeOption)
 {
     return(existingChangeOption.ChangeCoins.Count > changeOption.ChangeCoins.Count + 1);
 }
Exemple #4
0
        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);
            }
        }
Exemple #5
0
 private static bool ExistingChangeOptionShouldBeUpdated(ChangeOptionList existingChangeOptions, int subtarget, ChangeOption newChangeOption)
 {
     return(newChangeOption != null &&
            (!existingChangeOptions.ChangeOptionExistsForTargetValue(subtarget) || NewChangeOptionIsShorter(existingChangeOptions.GetChangeOption(subtarget), newChangeOption)));
 }