There is the problem of trying to see if two unique strings are anagrams of each other. The first solution that I had considered would be to sort both strings and see if they were equal to each other.
I have been considering another solution and I would like to discuss if the same would be feasible.
The idea would be to assign a numerical value to each character and sum it up such that a unique set of characters would produce a unique value. As we are testing for anagrams, we do not mind if the checksum of “asdf” and “adsf” are the same — in fact, we require it to be that way. However the checksum of strings “aa” and “b” shouldn’t be equal.
I was considering assigning the first 52 prime numbers to alphabets “a” through “z” and then “A” through “Z”(assume we only have alphabets).
The above scheme would break if the sum of any two or more primes in the set of 52 primes could result in another prime existing in the set.
My doubts are :-
- Is there any numbering scheme that would satify my requirements?
- I’m unsure about the math involved ; is it possible to prove/is there any proof that suggests that the sum of two or more primes in the set of the first 52 primes has at least one value that exists in the same set?
Thanks.
Use multiplication instead of addition. Primes are “multiplicatively unique”, but not “additively unique”.