Skip to content

Instantly share code, notes, and snippets.

@sathish316
Created January 29, 2012 18:58
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 sathish316/1700142 to your computer and use it in GitHub Desktop.
Save sathish316/1700142 to your computer and use it in GitHub Desktop.
Alphametric solver for equations like SEND + MORE = MONEY (Golf version)
def s(e)
c=e.scan(/\w{1}/).uniq
d=('0'..'9').to_a
d.permutation(c.size).each{|p|o=c.zip(p).inject(e){|e,d|e.gsub(*d)};return o if o !~/\b0/ && eval(o)}
end
puts s("SEND + MORE == MONEY")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment