Distance-on-keyboard algorithm implementation for Ruby.