How do you define custom hash for strings in ruby? -
i hash strings in ruby characters in each string without order, example want anagrams have same hash value.
is possible?
how about:
require 'digest' string = "mysupersamplestring" sorted = string.chars.sort.join p sorted # => => "msssaeegilmnpprrtuy" digest::md5.hexdigest(sorted) # => "ef86bea3ade82ae7bf0409952bc83fd7"
chars
"splits" string letterssort
sorts letters arrayjoin
joins array of letters 1 string
hope helps!
Comments
Post a Comment