View Single Post
Posts: 2,225 | Thanked: 3,822 times | Joined on Jun 2010 @ Florida
#13
Originally Posted by stlpaul View Post
You should become a teacher, you have a great way of suggesting solutions without flat-out telling the answer. This counting function sounds exactly like an exercise I did while learning programming.
Why thank you. Yeah, teaching is something I wouldn't mind doing, unfortunately here in the USA at least, teaching in the general education system means a rather low income and rather long work days (which in itself I'd not mind, but it would prevent me from being able to do other things in the world that I also consider important). And trying to get a long-term teaching job at a university/college typically entails having to publish academic work in journals regularly, as I understand it.

So for the time being I 'teach' like this, in passing, when someone seems like they could use it or are interested.

Originally Posted by stlpaul View Post
And be sure it can handle the number 0 (which still takes 1 character to print on-screen). It is an easy one to miss when you're focusing on testing bigger numbers.
You are absolutely right, I completely forgot to mention that. (I did not forget it in my code when I last wrote such a function up, though.)

Originally Posted by stlpaul View Post
Using standard library functions, depending on what you know about the input number type, a perhaps easier mathematical approach could be to use log10(i)+1 but it's still up to you to handle negatives, floats, etc..
Yeah, as per my big efficiency-zealot personal flaw, I didn't think of logarithms at all, due to the fact that they are typically computationally expensive, as I understand it. But that can indeed be much more intuitive and requiring less thoughts than my proposed methods.