Cleaner implementation of digit prefix calculation