Last active
December 27, 2015 19:19
-
-
Save goyalankit/7375769 to your computer and use it in GitHub Desktop.
isomorphic mapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#y procedure calculates the frequency of each character in the string | |
y = Proc.new{|x| x.chars.group_by{|i| i}.values.collect{|i| i.count}} | |
z = Proc.new{|m,n| y.call(m) == y.call(n)} | |
z.call("foo", "app") | |
#the one liner, less readable..:) well technically two to make it general | |
y = Proc.new{|m,n| m.chars.group_by{|i| i}.values.collect{|i| i.count} == n.chars.group_by{|i| i}.values.collect{|i| i.count} } | |
y.call("foo", "app") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment