Although the alphametic
SEVEN+EIGHT=TWELVE conveys a false message, it has several (how many?) valid solutions.
Find the one with the largest W.
SEVEN EIGHT TWELVE
36465 69781 106246
38487 89561 128048
58287 80641 138928
63732 39841 103573
69298 90431 159729
85254 50671 135925
The largest W in the 6 solutions is 5, in
69298+90431=159729
DefDbl A-Z
Dim crlf$, used(9)
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
For s = 1 To 9
If used(s) = 0 Then
used(s) = 1
For e = 1 To 9
If used(e) = 0 Then
used(e) = 1
For t = 1 To 9
If used(t) = 0 Then
used(t) = 1
For v = 0 To 9
If used(v) = 0 Then
used(v) = 1
For n = 0 To 9
If used(n) = 0 Then
used(n) = 1
seven = 10000 * s + 1010 * e + 100 * v + n
For i = 0 To 9
If used(i) = 0 Then
used(i) = 1
For w = 0 To 9
If used(w) = 0 Then
used(w) = 1
For l = 0 To 9
If used(l) = 0 Then
used(l) = 1
twelve = 100000 * t + 10000 * w + 1001 * e + 100 * l + 10 * v
For g = 0 To 9
If used(g) = 0 Then
used(g) = 1
For h = 0 To 9
DoEvents
If used(h) = 0 Then
used(h) = 1
eight = 10000 * e + 1000 * i + 100 * g + 10 * h + t
If seven + eight = twelve Then
Text1.Text = Text1.Text & seven & Str(eight) & Str(twelve) & crlf
End If
used(h) = 0
End If
Next
used(g) = 0
End If
Next
used(l) = 0
End If
Next
used(w) = 0
End If
Next
used(i) = 0
End If
Next
used(n) = 0
End If
Next
used(v) = 0
End If
Next
used(t) = 0
End If
Next
used(e) = 0
End If
Next
used(s) = 0
End If
Next
Text1.Text = Text1.Text & crlf & " done"
End Sub
|
Posted by Charlie
on 2016-11-30 10:29:30 |