Here's my answer:
- satisfies all five requirements
- does not require reversing the list (which, BTW, is technically another loop in the answer The Outlaw supplied).
- Also uses Math functions as the original requirements stated.
static List<int> digits(int value)
int sign = Math.Sign(value);
value *= sign;
int digits = (int)Math.Truncate(Math.Log10(value)) + 1;
List<int> list = new List<int>(digits);
for (int i = digits - 1; i >= 0; --i)
int nextValue = value / 10;
list[i] = value - nextValue * 10;
value = nextValue;
list *= sign;
Once again, you've missed the point. The tip isn't as much about the code as it it is about being able to look at a problem from several perspectives. Did you even READ the last section of the tip?
Yes, JSOP, I did? And how is my example not thinking outside the box or from different perspectives?. Did you even READ my example?