Created
January 29, 2012 18:58
-
-
Save sathish316/1700142 to your computer and use it in GitHub Desktop.
Alphametric solver for equations like SEND + MORE = MONEY (Golf version)
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
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