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