Esempio n. 1
0
        private static EquationInfo CreateInfoFromRegex(this EquationInfo equationInfo, List <string> groups, int singCoef)
        {
            const string SIGN       = "sign";
            const string COEFICIENT = "coeficient";
            const string DEGREE     = "degree";

            var pattern = $"(?<{SIGN}>[+-]?)(?<{COEFICIENT}>\\d*\\.?\\d*)\\*x\\^(?<{DEGREE}>\\d+)";

            groups.ForEach(str =>
            {
                var operandParse = Regex.Match(str, pattern, RegexOptions.IgnoreCase);

                var signStr       = operandParse?.Groups?[SIGN]?.Value ?? "+";
                var coeficientStr = operandParse.Groups[COEFICIENT].Value;
                var degreeStr     = operandParse.Groups[DEGREE].Value;

                var signCoeficient     = GetSignCoeficient(signStr);
                var degree             = int.Parse(degreeStr);
                var coeficient         = double.Parse(coeficientStr);
                var coeficientWithSign = coeficient * signCoeficient * singCoef;

                equationInfo.AddCoeficient(coeficientWithSign, degree);
            });

            return(equationInfo);
        }
        public static EquationInfo PrintReduceForm(this EquationInfo equationInfo)
        {
            var colection = equationInfo
                            .ToCollection();

            ConsolePrinter.Info($"Reduced Form: {PrintFirst(colection)}{PrintOther(colection)} = 0{Environment.NewLine}");

            return(equationInfo);
        }
        private static IReadOnlyCollection <CoeficientInfo> ToCollection(this EquationInfo equationInfo)
        {
            var colection = new List <CoeficientInfo>();

            var degrees = equationInfo
                          .GetDegreeCollection()
                          .ToList();

            degrees
            .ForEach(x => colection.TryAdd(equationInfo.GetCoeficientInfoByDegree(x)));

            return(colection);
        }
Esempio n. 4
0
 public static EquationInfo ParseLeftPart(this EquationInfo equationInfo, List <string> groups)
 => CreateInfoFromRegex(equationInfo, groups, 1);