コード例 #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        /// <exception cref="System.ArgumentOutOfRangeException">Something is wrong with the digits you specified.</exception>
        public Problem Generate()
        {
            Problem problem = new Problem();
            problem.Left = generateValue(LeftDigits, RightDigits);
            if (!Problem.IsUnary(Operation))
                problem.Right = generateValue(RightDigits, LeftDigits);
            problem.Operation = Operation;
            if (!Problem.IsUnary(Operation))
                applyConstraints(ref problem);

            switch (Operation)
            {
                case MathPractice.Operation.Addition:
                    if (problem.Left.ToString().Length < problem.Right.ToString().Length)
                        reverseOperands(ref problem);
                    break;
                case MathPractice.Operation.Subtraction:
                    if (problem.Left < problem.Right)
                        reverseOperands(ref problem);
                    break;
                case MathPractice.Operation.Multiplication:
                    if (problem.Left.ToString().Length < problem.Right.ToString().Length)
                        reverseOperands(ref problem);
                    break;
            }

            return problem;
        }
コード例 #2
0
ファイル: Session.cs プロジェクト: davidpet/cognitive
        /// <summary>
        /// 
        /// </summary>
        /// <exception cref="System.ArgumentOutOfRangeException">Bad digit specifications.</exception>
        public void PrintProblem()
        {
            currentProblem = Generator.Generate();

            string leftText = currentProblem.Left.ToString();
            string rightText = currentProblem.Right.ToString();
            char opText = getOperationText(currentProblem.Operation);

            Console.WriteLine("[#" + (TotalAnswers + 1).ToString() + "]");
            if (Generator.Operation == Operation.DayOfWeek) //todo: make this suck less
            {
                Console.Write("What is the day of the week for New Year's Day in the year " + currentProblem.Left.ToString() + "?  ");
            }
            else if (Problem.IsUnary(currentProblem.Operation))
            {
                Console.Write(leftText + opText + " = ");
            }
            else if (Vertical)
            {
                string answerPadding = getVerticalAnswerPadding(currentProblem);

                Console.WriteLine("------------------");
                Console.WriteLine("  " + answerPadding + leftText + "\t");
                Console.Write(opText + " ");
                for (int i = rightText.Length; i < leftText.Length; i++)
                    Console.Write(" ");
                Console.WriteLine(answerPadding + rightText + "\t");
                Console.WriteLine("------------------");
                Console.Write("  ");
            }
            else
                Console.Write(leftText + " " + opText + " " + rightText + " = ");
        }
コード例 #3
0
        private void applyConstraints(ref Problem problem)
        {
            if (Operation == MathPractice.Operation.DayOfWeek)
            {
                problem.Right = 0;
                problem.Left = (uint)(random.Next(2000, 2100));

                return;
            }

            if (this.Constraints.HasFlag(Constraints.LastDigitCycle))
            {
                applySequenceConstraint(ref problem.Left, ref problem.Right);
                return;
            }
            if (this.Constraints.HasFlag(Constraints.SecondNumberIsEleven))
                problem.Right = 11;
            if (this.Constraints.HasFlag(Constraints.BothNumbersAreSame))
                problem.Left = problem.Right;
            if (this.Constraints.HasFlag(Constraints.LastDigitsAddTo10))
            {
                uint rightDigit = problem.Right % 10;
                uint leftDigit = 10 - rightDigit;
                if (leftDigit == 10)
                {
                    problem.Right++;
                    leftDigit = 9;
                }

                problem.Left = (problem.Left / 10) * 10 + leftDigit;
            }
            if (this.Constraints.HasFlag(Constraints.FirstDigitIsSame))
            {
                StringBuilder leftText = new StringBuilder(problem.Left.ToString());
                string rightText = problem.Right.ToString();

                leftText[0] = rightText[0];
                problem.Left = uint.Parse(leftText.ToString());
            }
        }
コード例 #4
0
 private static void reverseOperands(ref Problem problem)
 {
     uint temp = problem.Left;
     problem.Left = problem.Right;
     problem.Right = temp;
 }
コード例 #5
0
ファイル: Session.cs プロジェクト: davidpet/cognitive
        private static string getVerticalAnswerPadding(Problem problem)
        {
            StringBuilder output = new StringBuilder();

            uint padding = 0;
            switch (problem.Operation)
            {
                case Operation.Addition:
                    padding = 1;
                    break;
                case Operation.Subtraction:
                    break;
                case Operation.Multiplication:
                   padding = (uint)problem.Right.ToString().Length;
                   break;
                case Operation.DayOfWeek:
                   break;
            }

            for (uint i = 0; i < padding; i++)
                output.Append(' ');

            return output.ToString();
        }