If everything is a digit, you can use an array instead of a hash to store the counts. In some quick tests, that uses about a third as much memory. But even using a hash, storing all possible 5-digit patterns only takes about 9MB, so no matter how you do it the 2nd approach is very tempting.
Using numbers instead of strings also lets you switch to the next number with multiply, modulus, and addition operators, which may be faster than manipulating strings.
In reply to Re: Most common substring
by sgifford
in thread Most common substring
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |