Hacker News new | ask | show | jobs
by aquateen 2980 days ago
I don't see how the sum would be unique to a particular combination of letters.
4 comments

Works if you assign prime numbers to each letter and multiply instead. So a=2, b=3, etc.
To get decent anagram lengths and complexity, implement the numbers as a dict of repetitions of primes, and implement the multiplication by summing the repetitions. ;-)
In which case you can just compare the dicts without performing the multiplication (which happens to be the costliest part for arbitrary-precision integers).
Exactly.
I briefly mused about just summing the ASCII codes for each letter in the strings. But quickly discarded the idea for this reason :)
“ad” = “bc”

You’re right.

What if a=1, b=10, c=100 - etc? Assuming the strings were English words...