Increment each digit in a number to form a new number Today I've found /r/dailyprogrammer and I've solved an easy challenge. I'm new to coding and I'm not sure if this is good way to solve this kind of problems. Could you, please, give me some hints? How to make my code more clear and readable? Thanks!


  Challange description:
  
  A number is input in computer then a new no should get printed by
  adding one to each of its digit. If you encounter a 9, insert a 10
  (don't carry over, just shift things around).
  
  For example, 998 becomes 10109.
  
  Bonus
  
  This challenge is trivial to do if you map it to a string to iterate
  over the input, operate, and then cast it back. Instead, try doing it
  without casting it as a string at any point, keep it numeric (int,
  float if you need it) only.


private static int Challange(int number)
        {
            int digits = (int)Math.Log10(number); //this is number of digits -1 
            int result = 0;
            for (int i=0; i &lt;= digits; i++)
            {
                int tens = (int)(Math.Pow(10, digits - i));
                int currentDigit = ((number / tens) % 10);

                if (currentDigit == 9) result *= 10;
                result += (currentDigit + 1) * tens;
            }
            return result;
        }
It works, but it's a bit tricky to follow the logic and work out why. If you work from the other end then you can avoid the Log and Pow and shifting the partial result, and I find that easier to read.



Challange is not a descriptive name. What does the method do? IncrementDigits might be a better name, for example.