asd+fgh=jkl
Believe me - there are numerous solutions of the above alphametic.
I. What is the minimal possible sum of participating digits?
ii. Same question for as+df=gh
DefDbl A-Z
Dim crlf$
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
minsum = 9999: minsum2 = 9999
n$ = "1234567890": h$ = n
Do
asd = Val(Left(n, 3))
fgh = Val(Mid(n, 4, 3))
jkl = Val(Mid(n, 7, 3))
tot = 45 - Val(Right(n, 1))
If asd + fgh = jkl Then
If tot < minsum Then minsum = tot: minsumdigs$ = Left(n, 9)
End If
asv = Val(Left(n, 2))
dfv = Val(Mid(n, 3, 2))
ghv = Val(Mid(n, 5, 2))
tot = 0
For i = 1 To 6
tot = tot + Val(Mid(n, i, 1))
Next
If asv + dfv = ghv Then
If tot < minsum2 Then minsum2 = tot: minsumdigs2$ = Left(n, 6)
End If
permute n
DoEvents
Loop Until n = h
Text1.Text = minsum & " " & minsumdigs & crlf
Text1.Text = Text1.Text & minsum2 & " " & minsumdigs2 & crlf
Text1.Text = Text1.Text & crlf & " done"
End Sub
finds
36 125478603
17 132740
meaning
36 is the minimum sum, for 125 + 478 = 603
17 is the minimum sum, for 13 + 27 = 40
|
Posted by Charlie
on 2017-09-02 12:54:29 |