SEND + MORE = MONEY: Difference between revisions

Added Wren
(Made this into a draft task which presumably is what's intended.)
(Added Wren)
Line 74:
done...
Time: 31.9 s
</pre>
 
=={{header|Wren}}==
Clearly M = 1 and S must be 2 or more. Brute force can be used to solve for the other letters.
<syntaxhighlight lang="ecmascript">var start = System.clock
var sends = []
var ors = []
var m = 1
for (s in 2..9) {
for (e in 0..9) {
if (e == m || e == s) continue
for (n in 0..9) {
if (n == m || n == s || n == e) continue
for (d in 0..9) {
if (d == m || d == s || d == n || d == e) continue
sends.add([s, e, n, d])
}
}
}
}
for (o in 0..9) {
if (o == m) continue
for (r in 0..9) {
if (r == m || r == o) continue
ors.add([o, r])
}
}
System.print("Solution(s):")
for (send in sends) {
var SEND = 1000 * send[0] + 100 * send[1] + 10 * send[2] + send[3]
for (or in ors) {
if (send.contains(or[0]) || send.contains(or[1])) continue
var sendmore = send + [m] + or
var MORE = 1000 * m + 100 * or[0] + 10 * or[1] + send[1]
for (y in 0..9) {
if (sendmore.contains(y)) continue
var MONEY = 10000 * m + 1000 * or[0] + 100 * send[2] + 10 * send[1] + y
if (SEND + MORE == MONEY) {
System.print("%(SEND) + %(MORE) = %(MONEY)")
}
}
}
}
System.print("\nTook %(System.clock - start) seconds.")</syntaxhighlight>
 
{{out}}
<pre>
Solution(s):
9567 + 1085 = 10652
 
Took 0.263465 seconds.
</pre>
9,476

edits