That being said, it's still fast enough for this example.
Also, Python solution along the same lines:
import itertoolsdef
def valueOf(*values, base=10):
v = 0
for v in itertools.accumulate(values, lambda a,b: a*base+b):
pass
return v
def solve():
for s,e,n,d,m,o,r,y in itertools.permutations(range(10), r=8):
if valueOf(s,e,n,d) + valueOf(m,o,r,e) == valueOf(m,o,n,e,y):
yield (s,e,n,d),(m,o,r,e),(m,o,n,e,y)
(If anyone knows of a better way to do valueOf, let me know)