Example #1
0
        public static int CoinCounting(int n)
        {
            var coinCount = new CoinCount(n);
            var i         = 1;

            while (Step(coinCount))
            {
                i++;
            }

            return(i);
        }
Example #2
0
        public static bool Step(CoinCount coinCount)
        {
            var coin = 2;

            while (coin <= coinCount.Total)
            {
                if (coinCount.CanBuild(coin))
                {
                    coinCount.Build(coin);
                    return(true);
                }

                coinCount.Break(coin);
                coin = CoinCount.Coins.OrderBy(x => x).FirstOrDefault(x => x > coin);
                if (coin == 0)
                {
                    break;
                }
            }

            return(false);
        }