Skip to content

Instantly share code, notes, and snippets.

@goyalankit
Last active December 27, 2015 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goyalankit/7375769 to your computer and use it in GitHub Desktop.
Save goyalankit/7375769 to your computer and use it in GitHub Desktop.
isomorphic mapping
#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