1

I need an algorithm that will map a string of length four to a four digit number. The problem is it has to maintain lexicographical order. It doesn't need to not have collisions, it's just that if S <= T, F(S) <= F(T). The only additional constraint is that it should be surjective: all numbers must be mapped to by some string.

Alex Beals
  • 1,965
  • 4
  • 18
  • 26

1 Answers1

1

Can't you just map letters to digits directly, grouping a few at a time to handle the fact that there are more letters than digits? {a, b, c} => 1, {d, e, f} => 2 etc.

MattPutnam
  • 2,927
  • 2
  • 17
  • 23