예제 #1
0
        private async Task <IEquation> Scramble(IEquation equation)
        {
            var pyRestApiHelper = new PyRestApiHandler();

            for (int i = 0; i < equation.Equation.Length - 1; i++)
            {
                if (equation.Equation[i].Equals('*') && equation.Equation[i + 1].Equals('*'))
                {
                    if (((int)(char.GetNumericValue(equation.Equation[i + 2])) > maxVar))
                    {
                        maxVar = (int)(char.GetNumericValue(equation.Equation[i + 2]));
                    }
                }
            }

            var equals = equation.Equation.Split("=");
            var a      = equals[0].Split(")/(");

            a[0] = a[0] + ")";
            a[1] = "(" + a[1];
            var jsonExpression = await pyRestApiHelper.ScrambleExpression(a[0], maxVar);

            a[0]           = jsonExpression.Expression;
            jsonExpression = await pyRestApiHelper.ScrambleExpression(a[1], maxVar);

            a[1] = jsonExpression.Expression;
            equation.Equation = "dydx * (" + a[1].Split("==")[0] + ")" + ")" + "=" + a[0].Split("==")[0] + ")";
            return(equation);
        }
예제 #2
0
        public async Task <IEquation> SolveAndScramble(IEquation equation)
        {
            maxVar = 0;
            var pyRestApiHelper = new PyRestApiHandler();
            var jsonEquation    = MapDtoToJson(equation);

            if (equation.Type == 1)
            {
                var solvedJsonEquation = await pyRestApiHelper.SolveEquation(jsonEquation);

                var resultEquation = MapJsonToDto(solvedJsonEquation, equation.Type);

                return(resultEquation);
            }
            else if (equation.Type == 2)
            {
                var solvedJsonEquation = await pyRestApiHelper.SolveEquation(jsonEquation);

                var resultEquation = MapJsonToDto(solvedJsonEquation, equation.Type);

                //fix scramble
                //equation = Scramble(equation);

                return(equation);
            }
            else
            {
                throw new NotImplementedException($"equationType {equation.Type} is not supported for mapping");
            }
        }