# Counting number of occurence of digits in a number

Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 10-12-2012
laserlight
Quote:

Originally Posted by oogabooga
3. You could store all the counts in a single integer by interpreting each decimal position as a count. This limits the max count of any digit to 9. This could be increased by using another base.

Interesting idea, but what's the point? After all, a variant of this is to use the integer as a bitset, but without any special requirements to the contrary, I think that this whole "cannot use array" business is misguided.

I can understand requiring that the input number not be stored in an array as that teaches the learner how to break an integer into individual digits (as indicated by the operations listed), but beyond that it sounds like fluff to me, unless the teacher really intended for the whole process to be repeated for each digit (as grumpy seems to think is fine, and given that there are only ten digits, I suppose I can concede that it is).
• 10-12-2012
oogabooga
Quote:

Originally Posted by laserlight
Interesting idea, but what's the point? After all, a variant of this is to use the integer as a bitset, but without any special requirements to the contrary, I think that this whole "cannot use array" business is misguided.

I can understand requiring that the input number not be stored in an array as that teaches the learner how to break an integer into individual digits (as indicated by the operations listed), but beyond that it sounds like fluff to me, unless the teacher really intended for the whole process to be repeated for each digit (as grumpy seems to think is fine, and given that there are only ten digits, I suppose I can concede that it is).

Clearly the array of counts is the proper solution. Anything else is more work for both the programmer and the machine.

I think your take on the situation is accurate. The OP is most likely mistaken. But then again, there's no fathoming the depths of assignment stupidity. :)
Show 80 post(s) from this thread on one page
Page 2 of 2 First 12