Send More Money

This an example of a Crytparithmic puzzle solved with Numberjack

Description: 

SEND + MORE = MONEY

Every letter represents a digit from 0 to 9. S and M are in the range 1 to 9. The puzzle is to find a uniqie assignment for every letter so that the equation above holds.

Code: 

from Numberjack import *

def send_more_money(libs):
    #Variable definitions, we need a variable for every letter
    s,m = (Variable(1,9) for val in range(2)) # These can't be zero as
                                              # they are the start of a word
    e,n,d,o,r,y = (Variable(0,9) for val in range(6)) # These can
   
    model = Model(      
                  s*1000 + e*100 + n*10 + d +
                  m*1000 + o*100 + r*10 + e ==
        m*10000 + o*1000 + n*100 + e*10 + y,
                  # Post the all different constraint on all the variables
                  AllDiff((s,e,n,d,m,o,r,y))
                  )
   
    for library in libs:
        solver = model.load(library) # Load up model into solver
   
        print ''
        solver.solve() # Now Solve
        print "   ", s,e,n,d
        print " + ", m,o,r,e
        print  "=", m,o,n,e,y
        print 'Nodes:', solver.getNodes(), ' Time:', solver.getTime()


send_more_money(('Gecode','Mistral','SCIP'))