예제 #1
0
        public Wallet(Wallet oldWallet, Coin c)
        {
            P1 = oldWallet.P1;
            P2 = oldWallet.P2;
            P5 = oldWallet.P5;
            P10 = oldWallet.P10;
            P20 = oldWallet.P20;
            P50 = oldWallet.P50;
            P100 = oldWallet.P100;
            P200 = oldWallet.P200;

            AddCoin(c);
        }
예제 #2
0
파일: Problem31.cs 프로젝트: apalumbi/Euler
        public override string Solve()
        {
            var coin1 = new Coin { Value = 1, MaxUses = amountToFind / 1 };
            var coin2 = new Coin { Value = 2, MaxUses = amountToFind / 2 };
            var coin3 = new Coin { Value = 5, MaxUses = amountToFind / 5 };
            var coin4 = new Coin { Value = 10, MaxUses = amountToFind / 10 };
            var coin5 = new Coin { Value = 20, MaxUses = amountToFind / 20 };
            var coin6 = new Coin { Value = 50, MaxUses = amountToFind / 50 };
            var coin7 = new Coin { Value = 100, MaxUses = amountToFind / 100 };
            var coin8 = new Coin { Value = 200, MaxUses = amountToFind / 200 };
            var coins = new List<Coin> { coin1, coin2, coin3, coin4, coin5, coin6, coin7, coin8 };

            //var penny = new Coin { Value = 1, MaxUses = amountToFind / 1 };
            //var nickel = new Coin { Value = 5, MaxUses = amountToFind / 5 };
            //var dime = new Coin { Value = 10, MaxUses = amountToFind / 10 };
            //var quarter = new Coin { Value = 25, MaxUses = amountToFind / 25 };
            //var half = new Coin { Value = 50, MaxUses = amountToFind / 50 };
            //var coins = new List<Coin> { penny, nickel, dime, quarter, half };

            GetCombinations(0, 0, coins.OrderByDescending(c => c.Value).ToList());
            return totalCombinations.ToString();
        }
예제 #3
0
 public bool HasNoLowerCoinsThan(Coin c)
 {
     switch (c)
     {
         case Coin.P1:
             {
                 return true;
             }
         case Coin.P2:
             {
                 return (P1 == 0);
             }
         case Coin.P5:
             {
                 return (P1 == 0 && P2 == 0);
             }
         case Coin.P10:
             {
                 return (P1 == 0 && P2 == 0 && P5 == 0);
             }
         case Coin.P20:
             {
                 return (P1 == 0 && P2 == 0 && P5 == 0 && P10 == 0);
             }
         case Coin.P50:
             {
                 return (P1 == 0 && P2 == 0 && P5 == 0 && P10 == 0 && P20 == 0);
             }
         case Coin.P100:
             {
                 return (P1 == 0 && P2 == 0 && P5 == 0 && P10 == 0 && P20 == 0 && P50 == 0);
             }
         case Coin.P200:
             {
                 return (P1 == 0 && P2 == 0 && P5 == 0 && P10 == 0 && P20 == 0 && P50 == 0 && P100 == 0);
             }
         default:
             {
                 return false;//??
             }
     }
 }
예제 #4
0
 public void AddCoin(Coin c)
 {
     switch (c)
     {
         case Coin.P1:
             {
                 P1++;
                 return;
             }
         case Coin.P2:
             {
                 P2++;
                 return;
             }
         case Coin.P5:
             {
                 P5++;
                 return;
             }
         case Coin.P10:
             {
                 P10++;
                 return;
             }
         case Coin.P20:
             {
                 P20++;
                 return;
             }
         case Coin.P50:
             {
                 P50++;
                 return;
             }
         case Coin.P100:
             {
                 P100++;
                 return;
             }
         case Coin.P200:
             {
                 P200++;
                 return;
             }
         default:
             {
                 return;
             }
     }
 }