예제 #1
0
        private static ChangeOptionList SetUpInitialPossibleChangeOptions()
        {
            var changeObjectList = new ChangeOptionList();

            changeObjectList.AddChangeOption(0);
            return(changeObjectList);
        }
예제 #2
0
        private static void ConsiderPossibleChangeOptionsForCoin(int target, ChangeOptionList possibleChangeOptions, int coin)
        {
            for (int subTarget = coin; subTarget <= target; ++subTarget)
            {
                var changeOption = GetPossibleChangeOptionWhenCoinSubtractedFromSubTarget(possibleChangeOptions, coin, subTarget);

                if (ExistingChangeOptionShouldBeUpdated(possibleChangeOptions, subTarget, changeOption))
                {
                    UpdateChangeOption(possibleChangeOptions, subTarget, coin, changeOption);
                }
            }
        }
예제 #3
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);
            }
        }
예제 #4
0
        private static ChangeOption GetPossibleChangeOptionWhenCoinSubtractedFromSubTarget(ChangeOptionList possibleChangeOptions, int coin, int subtarget)
        {
            int targetAfterCoinStubtracted = subtarget - coin;

            return(possibleChangeOptions.GetChangeOption(targetAfterCoinStubtracted));
        }
예제 #5
0
 private static bool ExactChangeCanBeGiven(ChangeOptionList possibleChangeOptions, int target)
 {
     return(possibleChangeOptions.ChangeOptionExistsForTargetValue(target));
 }
예제 #6
0
 private static bool ExistingChangeOptionShouldBeUpdated(ChangeOptionList existingChangeOptions, int subtarget, ChangeOption newChangeOption)
 {
     return(newChangeOption != null &&
            (!existingChangeOptions.ChangeOptionExistsForTargetValue(subtarget) || NewChangeOptionIsShorter(existingChangeOptions.GetChangeOption(subtarget), newChangeOption)));
 }