Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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