Initial implementation of sort_nth_digit