This method is <i>really</i> inefficient. There are b! / (b - n)! ways to choose n of b unique numbers, whereas this solution is O(b^n).<p>That being said, it's still fast enough for this example.<p>Also, Python solution along the same lines:<p><pre><code> 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)
</code></pre>
(If anyone knows of a better way to do valueOf, let me know)