Ejemplo n.º 1
0
        public OptimalResult Optimal(int x, ExchangeResult er)
        {
            OptimalResult result          = new OptimalResult();
            double        differ_x_module = x;
            double        differ_x        = x;
            int           i_optimal_row   = 0;
            double        An = 0;
            double        Bn = 0;

            for (int i = 0; i < er.Ways.GetLength(0); i++)
            {
                if (er.Remainder[i] == 0)
                {
                    double countA_in_row          = 0;
                    double count_all_money_in_row = 0;

                    for (int j = 0; j < er.Ways.GetLength(1); j++)
                    {
                        if (er.Ways[i, j] == er.a)
                        {
                            countA_in_row++;
                        }
                        if (er.Ways[i, j] != 0)
                        {
                            count_all_money_in_row++;
                        }
                    }

                    if (countA_in_row != 0 && count_all_money_in_row != 0 && (Math.Abs(x - (countA_in_row / count_all_money_in_row) * 100) <= differ_x_module))
                    {
                        differ_x_module = Math.Abs(x - (countA_in_row / count_all_money_in_row) * 100);
                        differ_x        = x - (countA_in_row / count_all_money_in_row) * 100;
                        i_optimal_row   = i;
                        An = countA_in_row;
                        Bn = count_all_money_in_row - countA_in_row;
                    }
                }
            }
            result.number_of_coins_A = An;
            result.number_of_coins_B = Bn;
            result.percent_An        = Math.Round((x - differ_x), 2);
            return(result);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter coin A");
            int a = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Enter coin B");
            int b = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Enter Summ");
            double summ = Convert.ToDouble(Console.ReadLine());

            Console.WriteLine("Enter percent A");
            int x = Convert.ToInt32(Console.ReadLine());

            ExchangeResult exchange = CoinsExchange.Calculation(a, b, summ);
            OptimalResult  optimal  = exchange.Optimal(x, exchange);

            Console.Write(optimal);
            Console.ReadKey();
        }
Ejemplo n.º 3
0
        public static ExchangeResult Calculation(int a, int b, double summ)
        {
            ExchangeResult er = new ExchangeResult();

            er.a = a;
            er.b = b;
            er.inversion_flag = Inversion(a, b);
            if (er.inversion_flag)
            {
                int c = er.a;
                er.a = er.b;
                er.b = c;
            }
            er.MaxCountMoney = CountMoney(summ, er.b);
            er.MaxCountCombs = CountCombs(summ, er.a);
            er.Ways          = AllCombs(er.MaxCountCombs, er.MaxCountMoney, summ, er.a, er.b);
            er.Remainder     = Remainder(er.Ways, summ);
            er.count_zero_R  = CountZero(er.Remainder);
            er.strategy      = Strategy(er.count_zero_R);

            return(er);
        }
Ejemplo n.º 4
0
        public OptimalResult Optimal(int x, ExchangeResult er)
        {
            OptimalResult or = er.strategy.Optimal(x, er);

            return(or);
        }