Example #1
0
        public static Result LargestProductInSeries(Problem arguments)
        {
            string sequence = arguments.Sequence;
            int    digits = Convert.ToInt32(arguments.LongNumber);
            string segment = string.Empty, digit = string.Empty;
            int    start   = 0;
            long   product = long.MinValue;

            while (start + digits < sequence.Length)
            {
                segment = sequence.Substring(start, digits);
                start++;
                long p = UtilityMath.GetProduct(segment);

                if (p > product)
                {
                    product = p;
                    digit   = segment;
                }
            }

            var m = string.Format("the adjacent digits [{0}] in the 1000-digit number that have the greatest product which is {1}.", string.Join("x", digit.ToArray()), product);
            var r = new Result(arguments.Id, m);

            return(r);
        }