Exemplo n.º 1
0
        public string Compute(IList <string> numbers)
        {
            if (numbers.Count < 2)
            {
                throw new Exception("Need at least 2 numbers to multiply, found: " + numbers.Count);
            }

            StringMatrixTransformer smt = new StringMatrixTransformer();
            ILargeNumberComputer    a   = new LargeNumberAdder();
            ArithmeticUtils         au  = new ArithmeticUtils();

            string num = numbers[0];
            IList <IList <int> > matrix = smt.TransformStringListToReversedIntMatrix(numbers);

            for (int i = 1; i < numbers.Count; i++)
            {
                IList <int>          m   = matrix.ElementAt(i);
                ILargeNumberComputer lom = new LargeToOneNumberMultiplier();
                IList <string>       stageIntermediates = new List <string>();

                for (int j = 0; j < m.Count; j++)
                {
                    string prefix = "";
                    int    n      = m[j];
                    //add the 0 to handle decimal place of the multiplying number
                    for (int k = 0; k < j; k++)
                    {
                        prefix += "0";
                    }

                    stageIntermediates.Add(lom.Compute(new List <string>()
                    {
                        num, n.ToString()
                    }) + prefix);
                }
                num = a.Compute(stageIntermediates);
            }
            return(num);
        }