Ok, so I was stamping out a recent (quite simple) assignment for a class. The assignment required the separation of each place value in an integer. Since the information came into the program as a string, I stamped out a simple solution using some easy loops and handy methods available in the String class (of the .Net 2.0 class libraries). However, a quick skim over the rubric included 5% for correctly using div and mod to parse out the integer values. I immediately flipped back into my program, then froze for a second..
then another…
then 2 more…
I was completely blanking. I know its a simple task, its just I have become so accustomed to the incredible abundance and availability of a dozen methods for every little task that I blanked for a good minute, just stonewalled. I knew I had written this code before, everyone has done it at least once in some ‘Intro to Programming Theory’ class, and the concept was easy enough, but it just wouldn’t come. Cursing the professor for such a trivial demand, I went and got a cup of coffee.
Upon returning I realized how stupid and petty I was being. While I do often rely on cool class libraries and the methods they provide, I really just have to stop being so self-righteous and realize how likely it was that much of the class would be completely stuck on such a task. We spend so much time today learning about existing technologies and API’s that we forget the core of programming: Problem Solving.
I quickly slapped together the following C# method:
static int[] toIntArray(string input)
{
int i = 0;
int digit;
List<int> ints = new List<int>();
for (int numdigits = input.Length; numdigits > 0; numdigits–)
{digit = Convert.ToInt32(input) / (int)Math.Pow(10.0, (double)(numdigits - 1));
digit = digit % 10;
ints.Add(digit);
i++;
}
return ints.ToArray();
}
In retrospect, its quite simple, I just hope that this was my ‘moment of realization’ and I don’t get so inundated again as to the point where I can’t do the simple stuff on my own anymore.

October 29th, 2007 at 11:27 pm
I have to admit, that method was a little confusing to figure out. It’s kind of a weird way to have you solve the problem (using div and mod) but I guess the point was to learn how those two operators work. One thing I noticed was that i is never used for anything meaningful. Other than that, great job. I’m happy to see more Neumont students blogging.
October 30th, 2007 at 10:56 am
It was confusing to me as well. Part of my confusion came from calling “Convert.ToInt32(input)” in each iteration of the loop when not actually changing the string.
That’s a pet peeve of mine.
If the result of calling the (marginally expensive) parse function never changes, just call it once before the loop.
Anyway, I know what you mean about forgetting basic algorithms. It took me way longer to read that than it should have.