Exemplo n.º 1
0
        public static bool IsRampNumber(long number)
        {
            var digits = DerpMath.DigitsArray(number);
            // Iterate only to the second last digit as we need to compare it to the next digit.
            int checkIndex = digits.Length - 1;

            for (int i = 0; i < checkIndex; i++)
            {
                byte currDigit = digits[i];
                byte nextDigit = digits[i + 1];
                if (currDigit > nextDigit)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        public static byte[] DigitsArray(long number)
        {
            int  length         = DerpMath.DigitCount(number);
            long positiveNumber = Math.Abs(number);

            var  digits          = new byte[length];
            long processedNumber = positiveNumber;
            int  digitIndex      = 0;

            for (int i = 0; i < length; i++)
            {
                digitIndex = (length - 1) - i;
                byte digit = (byte)(processedNumber % 10);
                digits[digitIndex] = digit;
                processedNumber   /= 10;
            }
            return(digits);
        }
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                PrintError("No number given.");
                return;
            }

            long numberRange;

            if (!long.TryParse(args[0], out numberRange))
            {
                PrintError("That's not a number or it's a too big number. :C");
                return;
            }

            long start;
            long stop;

            if (numberRange >= 0)
            {
                start = 0;
                stop  = numberRange;
            }
            else
            {
                start = numberRange + 1;
                stop  = 1;
            }

            int count = 0;

            for (long n = start; n < stop; n++)
            {
                if (DerpMath.IsRampNumberFaster(n))
                {
                    count++;
                    //Debug.WriteLine(rampNumber, "rampNumber");
                }
            }
            //Debug.WriteLine(count, "count");
            Console.WriteLine(count);
        }