May I suggest a different approach? Sorry I don't have time to code this. Instead of pre-allocating a key in the hash for each digit, why not create a key for each digit that is found? The number of digits used is then
I'm not sure if you expect each digit to be different, but if not then you could increment the value to get a count.
Hope this helps, and apologies if I misunderstood.